1
我目前正在写一个国际象棋引擎,并取得了很大的进展,但我遇到了一个问题,并希望就这种方式发表一些看法。好吧,我的问题是,我的国际象棋AI没有做出“最好”的举动,似乎没有看到简单的事情,例如它的作品可能被收回或其他事情。我的alpha测试版如下。Alpha beta修剪根移动
int Search (TREE *tree, int ply, int wtm, int alpha, int beta) {
if (0 == ply) {
return quiesce(tree, ply, wtm, alpha, beta);
}
movePointer = GenCaptures(tree, MAXPLY, wtm, moves);
movePointer = GenNonCaptures(tree, wtm, movePointer);
for (move = &moves[0]; move < movePointer; move++) {
MakeMove(tree, &tree->movePath[ply], wtm);
score = -Search(tree, ply - 1, Flip(wtm), -beta, -alpha);
UnmakeMove(tree, &tree->movePath[ply], wtm);
tree->movePath[ply].move = 0;
if (score >= beta) {
return beta;
}
if (score > alpha) {
alpha = score;
}
}
我觉得我的alpha beta剪枝的作品不够好,因为它不会返回合理的举动,我认为这个问题是,当我试图获得我的rootMove。我试着去获得通过(
int searchRoot(TREE *tree, int ply, int wtm) {
//int depth = 1;
int moves[220];
int *movePointer = 0;
int *move = 0;
int rootAlpha = -MATE - 1;
int rootValue = -MATE - 1;
int rootBeta = MATE + 1;
MOVE currentMove;
currentMove.move = 0;
currentMove.capture = 0;
movePointer = GenCaptures(tree, MAXPLY, wtm, moves);
movePointer = GenNonCaptures(tree, wtm, movePointer);
for (move = &moves[0]; move < movePointer; move++) {
currentMove.move = *move;
tree->movePath[MAXPLY] = currentMove;
MakeMove(tree, ¤tMove, wtm);
int lastValue = -Search(tree, MAXPLY -1, Flip(wtm), rootAlpha, rootBeta);
UnmakeMove(tree, ¤tMove, wtm);
if (lastValue > rootValue) {
tree->rootMove = *move; rootValue = lastValue;
}
}
}
根移动任何意见将是有益的,谢谢。
你有多深 - 什么是MAXPLY?浅搜索只是表现不佳。 – 2012-04-24 17:23:29
通常情况下,您希望像在其他节点中一样处理根节点中的'alpha'和'beta'。这里你没有更新根节点中的alpha,这会让你的搜索速度变慢(它不会改变结果)。 – interjay 2012-04-24 17:27:36
您应该在TalkChess这样的专家论坛上提出这个问题,它可能引起Bob Hyatt或同等学者的注意:http://www.talkchess.com/forum/index.php – trojanfoe 2012-05-01 06:32:27