Please, I'm a little new to Python, and it was nice, I could comment that python is very sexy, until I needed to translate the contents of the 4x4 matrix, which I want to use to create a 2048-game demo game here I have this function
def cover_left(matrix):
new=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
for i in range(4):
count=0
for j in range(4):
if mat[i][j]!=0:
new[i][count]=mat[i][j]
count+=1
return new
This is what this function does if you call it
cover_left([
[1,0,2,0],
[3,0,4,0],
[5,0,6,0],
[0,7,0,8]
])
It will cover the zeros on the left and produce
[ [1, 2, 0, 0],
[3, 4, 0, 0],
[5, 6, 0, 0],
[7, 8, 0, 0]]
Please, I need someone to help me with a numpyway to do this, which, in my opinion, will be faster and require less code (I use the depth search algorithm) and, more importantly, the implementation cover_up, cover_downand
`cover_left`.
`cover_up`
[ [1, 7, 2, 8],
[3, 0, 4, 0],
[5, 0, 6, 0],
[0, 0, 0, 0]]
`cover_down`
[ [0, 0, 0, 0],
[1, 0, 2, 0],
[3, 0, 4, 0],
[5, 7, 6, 8]]
`cover_right`
[ [0, 0, 1, 2],
[0, 0, 3, 4],
[0, 0, 5, 6],
[0, 0, 7, 8]]
Thanks in advance.