I've created a virtual chessboard with 64 spaces formed as a nested array. I'm trying to go through each spot and check if the value of the spot is zero. I'm using np.where to get the indexes of the spot, however eventually np.where starts to return multiple values which throws an error. How can I get it to return ONLY the indexes of the spot that I am currently on?
while chessboard[result[0], result[1]] != 0:
for row in chessboard:
for spot in row:
if spot == 0:
location = np.where(chessboard == spot)
print(location)
for move in possible_moves:
if (location[0] + move[0]) < 0 or (location[1] + move[1]) < 0 or (location[0] + move[0]) > 7 or (location[1] + move[1]) > 7:
continue
else:
chessboard_updated[location[0] + move[0], location[1] + move[1]] = 0
chessboard = chessboard_updated
counter += 1
Eventually I get the error
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
because
location
returns
(array([5, 6, 7], dtype=int32), array([1, 2, 0], dtype=int32))
it returns 5,6,7 instead of just 1 value
Thank you.