def move(board, dir):
tempt = []
tempt = board[:]
#print(tempt)
if dir == 'down':
for a in range(Grids):
for b in range(Grids-1, -1, -1):
if board[a][b] != 0:
check = CheckBlock(a, b, dir)
board[a][b].moving(board, dir, check[1], check[0])
#print(tempt)
if dir == 'up':
for a in range(Grids):
for b in range(Grids):
if board[a][b] != 0:
check = CheckBlock(a, b, dir)
board[a][b].moving(board, dir, check[1], check[0])
if dir == 'left':
for a in range(Grids):
for b in range(Grids):
if board[b][a] != 0:
check = CheckBlock(b, a, dir)
board[b][a].moving(board, dir, check[1], check[0])
if dir == 'right':
for a in range(Grids):
for b in range(Grids-1, -1, -1):
if board[b][a] != 0:
check = CheckBlock(b, a, dir)
board[b][a].moving(board, dir, check[1], check[0])
I was recreating some games when I stumbled upon this mess. So this is a function to move everything inside a list while changing the list itself (which is board). And at the end, I want to make sure that something changed in the list. So I made a temporary list (which is tempt) and copied the base list to compare later. But when the base list is modified, the temporary list is modified as well. So the two #print(tempt) code will print out the different list.
I have tried my best to indicate the problem, by calling the function only once, but somehow the temporary list keeps changing whenever I make any modifications to the base lists.
Thank you very much for reading through here, any bits of help or thoughts are appreciated.