我使用alpha beta修剪和quiscence搜索实现了negamax,它看起来很有效......除非有时计算机允许我在1中交配,即使有可能已经采取措施来阻止它(这发生在深度4,它绝对应该被发现。如果有经验的人可以查看我的代码并且可能看到我没有的东西,我真的很感激:
static double alphaBetaMax(double alpha, double beta, int depthleft, game_t game, bool player)
{
move_t *cur;
move_t *tmp;
double score = 0;
bool did_move = false;
cur = getAllMoves(game, player); //getAllMoves initilizes a global list of moves, firstMove
if(cur == NULL) /* check mate*/
return -9999999*(player*2-1);
tmp = firstMove;
firstMove = 0;
while (cur != NULL)
{
game_t copy;
if(depthleft<=0 && !isCapture(game, cur)) { /* Quiescence search */
cur = cur->next;
continue;
}
did_move = true;
copyGame(game, ©);
makeMove(©, *cur);
firstMove = NULL;
score = -alphaBetaMax(-beta, -alpha, depthleft - 1, copy, !player);
if(board_count > MAX_BOARDS)
break;
freeGame(copy);
if(score > alpha)
alpha = score;
if (beta <= alpha)
break;
cur = cur->next;
}
firstMove=tmp;
freeMoves();
if(!did_move)
alpha = evaluate(game)*(player*2-1);
return alpha;
}
move_t* getBestMove(game_t game, int player, unsigned int depth) // initial call
{
move_t *cur = NULL, *best = NULL;
move_t *tmp;
double alpha = -DBL_MAX, score = 0;
freeMoves();
firstMove = NULL;
cur = getAllMoves(game, player);
tmp = firstMove;
firstMove = 0;
while (cur != NULL)
{
game_t copy;
copyGame(game, ©);
makeMove(©, *cur);
firstMove = NULL;
score = -alphaBetaMax(-DBL_MAX, -alpha, depth-1, copy, !player);
#ifdef PRINT_SCORES
printf(" <%c,%d> to ", cur->x1 + 'a', cur->y1 + 1);
printf("<%c,%d>", cur->x2 + 'a', cur->y2 + 1);
printf(" - score %f\n", score);
#endif
freeGame(copy);
if(board_count > MAX_BOARDS)
break;
if (score > alpha) {
alpha = score;
if (best != NULL) {
best->next = NULL;
free(best);
}
best = copyMove(*cur);
}
cur = cur->next;
}
firstMove = tmp;
freeMoves();
if(board_count > MAX_BOARDS) {
free(best);
return 0;
}
return best;
}
答案 0 :(得分:0)
您的代码在许多方面实现不正确,例如q-search,评估和搜索算法本身。例如,您的qsearch不正确。您应该获得一个standpat分数,然后生成所有捕获和非完全移动。将这些移动递归地用于qsearch。
但是大多数重要,你为将军返回的分数是错误的。在nega-max中,必须且必须相对于转牌的玩家返回将死分数。也就是说,您必须为配偶返回负值。
您的代码
如果玩家为假,则返回-9999999 *(播放器* 2-1);
将返回正值(false == 0)。在http://en.wikipedia.org/wiki/Negamax中读取nega-max。你看到
了吗?算法中的bestValue:= - ∞
?你不在乎转弯是谁,你必须为配偶返回一个负值。