I\'ve written a minimax algorithm with alpha beta pruning for the game Checkers, and now I\'m trying to rewrite it using the negamax approach. I\'m expecting the two to be e
Your minimax() and negamax() functions are correct. I assume that state.getNextPlayer() returns the player who has to move next. That means that your evaluate() and negamax() functions return a score from the perspective of that player.
However, the minimax() returns a score from the perspective of max. So if you try uncommenting minimax() in your play() function, that would lead to a bug
//int v = negamax(move, 10, a, b);
int v = minimax(move, 10, a, b, false); // assumes perspective of min player
^^^^^
if (v > a) { // assumes perspective of max player
a = v;
bestMove = move;
}
Replacing the call to minimax() with a true parameter should solve it:
int v = minimax(move, 10, a, b, true); // assumes perspective of max player