深海圆疑电影百度云:了解机器博弈的请进,关于负极大值算法的问题

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/11 03:30:47
代码来自<<PC游戏编程--人机博弈>>一书,如下:

int CNegamaxEngine::NegaMax(int depth)
{
int current = -20000 ;
int score;
int Count,i;
BYTE type;

i = IsGameOver(CurPosition, depth);
if (i != 0)
return i;

if (depth <= 0) //叶子节点取估值
return m_pEval->Evaluate(CurPosition, (m_nMaxDepth-depth)%2);//Evaluate()的原型为 int Evaluate( position pos, int IsRedTurn ); 为评估函数,评估传入的棋局pos的分数,为负极大值搜索引擎所调用,搜索最佳着法.

Count = m_pMG->CreatePossibleMove(CurPosition, depth, (m_nMaxDepth-depth)%2);

for (i=0;i<Count;i++)
{

type = MakeMove(&m_pMG->m_MoveList[depth][i]);
score = -NegaMax(depth - 1);
UnMakeMove(&m_pMG->m_MoveList[depth][i],type);

if (score > current)
{
current = score;
if(depth == m_nMaxDepth)
{
m_cmBestMove = m_pMG->m_MoveList[depth][i];
}
}

}

return current;
}

我的疑惑在于,return m_pEval->Evaluate(CurPosition, (m_nMaxDepth-depth)%2);这条语句调用了估值函数Evaluate();给它传入的参数为什么始终等于m_nMaxDepth%2 呢? (depth始终为0)

这样一来,当前局面轮到哪方走棋在搜索深度一定的情况下不就不变了吗?这样的话搜索算法如何运作以找到最优着法呢?

我知道要大家仔细看完这样的代码不太可能,但还是抱着希望来了,希望大家能帮帮我.