I'm trying to debug an issue within this c++ code that plays tic-tac-toe on a given game state using minimax to find best moves between the min (o) and maxer (x). I'm able to get the position of the move from the minimax function but when I try to run make_move to set the position on the board, i run into this issue: "The object has type qualifiers that are not compatible with the member function State::make_move object type is: const State"
void solve(const State &st)
{
while (!st.full() && !st.gameEnded())
{
auto value = minimax(st); // Find the optimal move for the current player
st.make_move(get<1>(value), get<2>(value));
if (st.max_value() == 1 || st.max_value() == -1) // Either x or o won
{
st.set_game_ended(true);
}
}
st.print(); // Prints the completed board state
if (st.max_value() == 0) // Not +=1 and the board is full, game ends in a draw
{
cout << "draw" << endl;
}
}
public:
void make_move(int x, int y)
{
sq[x][y] = to_move; // Represents the position on the board
// Switch turns depending on the current player
to_move = (to_move == MAX ? MIN : MAX);
// Increment the number of filled tiles on the board
filled += 1;
}
This issue also happens similarly with the set_game_ended method. If there are any ideas on how to access these methods through a const reference to the state, it would be greatly appreciated.