I am doing a game of tic tac toe as an exercise. I am trying to replace X with 3, O with -3 and - with 0.
import numpy as np
playfield = np.array([
['X', 'O', 'X'],
['-', 'X', 'O'],
['-', '-', 'X']
])
codes = {'X': 3, 'O': -3, '-': 0}
for idx, x in np.ndenumerate(playfield):
playfield[idx] = codes[x]
However, every time the program tries to replace an O by -3, my array is like this
[['3' '-' 'X']
['-' 'X' 'O']
['-' '-' 'X']]
It happens even if I try to replace it by -9. Also, when I try to replace '_' by -3, it appears as '-' in the array
If I make playfield as a normal list, replace everything and make it back as a np.array, everything works. Why is it happening? Thank you!