I am new to python and my first project is to hand-code a tictactoe game.
So as I'm trying to write a "toString" method, I came across a problem with 2 Dimensional arrays, as follows
board = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
binit = board[:]
for x in range(3):
for y in range(3):
if int(binit[x][y]) == 0:
binit[x][y] = "_"
elif int(binit[x][y]) == 1:
binit[x][y] = "X"
else:
binit[x][y] = "O"
print(binit)
print(board)
the Output I get when playing is:
ID: board 140662640260544
ID: binit 140662640580864
board: [['X', '_', '_'], ['_', '_', '_'], ['_', '_', '_']]
binit: [['X', '_', '_'], ['_', '_', '_'], ['_', '_', '_']]
though the board itself should have been unchanged.
bint = board.copy()
didn't work either.