maxconnect4游戏的终端案例是什么



我理解使用极小极大算法的井字游戏,其中终端情况是赢、输和平局-10,0,-10。

当有人获胜、获胜或打平时,程序终止。由于连接四个游戏没有三个终端状态,而不是游戏结束后的记分牌,我如何从评估函数中确定其终端情况?如何实现评估功能?

int minimax(char board[3][3], int depth, bool isMax)
{
int score = evaluate(board);
// If Maximizer has won the game return his/her
// evaluated score
if (score == 10)
return score;
// If Minimizer has won the game return his/her
// evaluated score
if (score == -10)
return score;
// If there are no more moves and no winner then
// it is a tie
if (isMovesLeft(board)==false)
return 0;
// If this maximizer's move
if (isMax)
{
int best = -1000;
// Traverse all cells
for (int i = 0; i<3; i++)
{
for (int j = 0; j<3; j++)
{
// Check if cell is empty
if (board[i][j]=='_')
{
// Make the move
board[i][j] = player;
// Call minimax recursively and choose
// the maximum value
best = max( best,
minimax(board, depth+1, !isMax) );
// Undo the move
board[i][j] = '_';
}
}
}
return best;
}
// If this minimizer's move
else
{
int best = 1000;
// Traverse all cells
for (int i = 0; i<3; i++)
{
for (int j = 0; j<3; j++)
{
// Check if cell is empty
if (board[i][j]=='_')
{
// Make the move
board[i][j] = opponent;
// Call minimax recursively and choose
// the minimum value
best = min(best,
minimax(board, depth+1, !isMax));
// Undo the move
board[i][j] = '_';
}
}
}
return best;
}
}

但对于connect4,我如何计算评估函数,以及它将如何定义终端情况(除非板已满)?

由于connect四款游戏没有三种终端状态,而不是游戏结束后的记分牌,

首先,你说连接四没有三个终端阶段是错误的。它也只能以胜利、失败或平局告终。

问题是,连接四非常复杂,在到达这些终端阶段之前,不可能评估树。这就是为什么在比最基本的游戏(如井字游戏)更复杂的游戏中,会为搜索提供预定的搜索深度,并且该深度末尾的所有节点都被视为终端。这种深度通常由迭代深化框架中的时间约束决定。

由于实际上这些节点不是终端节点,我们不能再使用0、1和-1来评估它们。相反,我们扩大了我们的范围,将胜利视为任意高的数字,将失败视为任意低的数字,并使用启发式评估函数来确定中间值。一种可能的启发式方法是玩家一排有三个。要了解更复杂的连接四种启发式方法,请阅读Victor Aliss关于该主题的论文。

最新更新