Alpha beta修剪根移动

时间:2012-04-24 12:40:55

标签: c artificial-intelligence chess alpha-beta-pruning

我目前正在写一个国际象棋引擎并且已经取得了相当大的进展,但是我遇到了一个问题,并希望对这种方式有一些看法。好吧,我的问题是我的国际象棋AI没有做出“最佳”的举动,似乎没有看到简单的事情,比如它的作品可能被收回或其他东西。我的alpha beta prunning如下。

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; 
        } 
    } 
} 

任何想法都会有所帮助,谢谢。

1 个答案:

答案 0 :(得分:0)

您的searchRoot无法正确实现negamax的想法。你的行

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

应该阅读

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