Conversion of minimax with alpha beta pruning to negamax

前端 未结 1 931
耶瑟儿~
耶瑟儿~ 2021-01-06 00:54

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

相关标签:
1条回答
  • 2021-01-06 01:00

    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
    
    0 讨论(0)
提交回复
热议问题