2012-04-24 102 views
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, &currentMove, wtm); 
     int lastValue = -Search(tree, MAXPLY -1, Flip(wtm), rootAlpha, rootBeta); 
     UnmakeMove(tree, &currentMove, wtm); 
     if (lastValue > rootValue) { 
      tree->rootMove = *move; rootValue = lastValue; 
     } 
    } 
} 

根移動任何意見將是有益的,謝謝。

+0

你有多深 - 什麼是MAXPLY?淺搜索只是表現不佳。 – 2012-04-24 17:23:29

+0

通常情況下,您希望像在其他節點中一樣處理根節點中的'alpha'和'beta'。這裏你沒有更新根節點中的alpha,這會讓你的搜索速度變慢(它不會改變結果)。 – interjay 2012-04-24 17:27:36

+2

您應該在TalkChess這樣的專家論壇上提出這個問題,它可能引起Bob Hyatt或同等學者的注意:http://www.talkchess.com/forum/index.php – trojanfoe 2012-05-01 06:32:27

回答

0

您searchRoot不正確執行negamax想法。你行

int lastValue = -Search(tree, MAXPLY -1, Flip(wtm), rootAlpha, rootBeta); 

應該讀

int lastValue = -Search(tree, MAXPLY -1, Flip(wtm), -rootBeta, -rootAlpha);