我正在尝试为两人 8x8 棋盘游戏创建一个 AI 对手。经过研究,我发现 Minimax 算法足够方便完成这项工作。我正在创建的 AI 对手将与其他 AI 对手或人类对战。
我对理解 minimax 算法有疑问。
我正在尝试只创建一个 AI 对手,但在网上找到的解释说我需要为两个玩家(最小玩家和最大玩家)编写代码,正如我从下面的伪代码中所理解的那样。
MinMax (GamePosition game) {
return MaxMove (game);
}
MaxMove (GamePosition game) {
if (GameEnded(game)) {
return EvalGameState(game);
}
else {
best_move < - {};
moves <- GenerateMoves(game);
ForEach moves {
move <- MinMove(ApplyMove(game));
if (Value(move) > Value(best_move)) {
best_move < - move;
}
}
return best_move;
}
}
MinMove (GamePosition game) {
best_move <- {};
moves <- GenerateMoves(game);
ForEach moves {
move <- MaxMove(ApplyMove(game));
if (Value(move) > Value(best_move)) {
best_move < - move;
}
}
return best_move;
}
我可以进一步理解,最大玩家将是我要开发的 AI,而最小玩家是对手。
我的问题是为什么我必须为最小和最大玩家编写代码才能返回最佳移动?
下面给出的伪代码基于 C#。
提前致谢。