I have been programming TicTacToe, using Numpy and Pandas dataframe, and my code works fine, however each time the second player inputs the coordinates of his move, the error message is being displayed in the terminal:
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: https://pandas.pydata.org/pands_docs/stabel/user_guide/indexing.html@returning-a-view-versus-a-copy
board[c1][r1] = "O"
This is the code responsible for changing the value in the Numpy Pandas dataframe:
def player_move(board, turn, p):
c1, r1 = (input("Enter the coordinates(Column,Row) of your first move(separate by \',') : ").split(","))
if valid_move(board, c1, r1, p):
if (p == 1):
board[c1][r1] = "X"
else:
board[c1][r1] = "O"
return board
else:
player_move(board, turn, p)
board = np.array([ [0, 0, 0],
[0, 0, 0],
[0, 0, 0], ])
column_names = ['a', 'b', 'c']
row_names = ['1', '2', '3']
#matrix = np.reshape((1, 2, 3, 4, 5, 6, 7, 8, 9), (3, 3)) creates a matrix with the given size.
board = pd.DataFrame(board, columns=column_names, index=row_names)
Does anyone know how to solve this issue?
Thank you in advance.