I have a 8x8 array that contains objects in some positions, ' '
in others. (It's a chessboard)
My code was running slowly partially due to the use of copy.deepcopy(x)
so I did some testing and found that iterating through the array was something like 32x faster. When I ran the code it threw errors so I compared the result from the iteration and the copy.deepcopy(x)
and they aren't the same. I can't see where I'm going wrong or find anything similar (I have looked)
the function is below:
def makeCopy(array):
new = [[],[],[],[],[],[],[],[]]
for x in range(0,8):
for y in range(0,8):
new[x].append(array[x][y])
a = copy.deepcopy(array)
if new != a:
print('failed')
else:
print('good')
return new
When it gets called it prints failed
so they aren't the same, which breaks the rest of my code.
I'm passing it something like this (some piece positions may differ):
currentGameState = [[Rook('black', [0,0]),Knight('black',[1,0]),Bishop('black', [2,0]),Queen('black',[3,0]),King('black',[4,0]),Bishop('black', [5,0]),Knight('black',[6,0]),Rook('black', [7,0])],
[Pawn('black', [0,1]),Pawn('black', [1,1]),Pawn('black', [2,1]),Pawn('black', [3,1]),Pawn('black', [4,1]),Pawn('black', [5,1]),Pawn('black', [6,1]),Pawn('black', [7,1])],
[' ',' ',' ',' ',' ',' ',' ',' '],
[' ',' ',' ',' ',' ',' ',' ',' '],
[' ',' ',' ',' ',' ',' ',' ',' '],
[' ',' ',' ',' ',' ',' ',' ',' '],
[Pawn('white', [0,6]),Pawn('white', [1,6]),Pawn('white', [2,6]),Pawn('white', [3,6]),Pawn('white', [4,6]),Pawn('white', [5,6]),Pawn('white', [6,6]),Pawn('white', [7,6])],
[Rook('white', [0,7]),Knight('white', [1,7]),Bishop('white', [2,7]),Queen('white',[3,7]),King('white',[4,7]),Bishop('white', [5,7]),Knight('white',[6,7]),Rook('white', [7,7])]]