Conversion of minimax with alpha beta pruning to negamax

﹥>﹥吖頭↗ 提交于 2019-11-30 15:15:23

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!