我的静止搜索有问题吗?

Is there something wrong with my quiescence search?

当我尝试实施 QuiesenceSearch 时,我的基于 negamax 的 AI 总是出现奇怪的行为。我基于 here:

的伪代码
int Quiesce( int alpha, int beta ) {
    int stand_pat = Evaluate();
    if( stand_pat >= beta )
        return beta;
    if( alpha < stand_pat )
        alpha = stand_pat;

    until( every_capture_has_been_examined )  {
        MakeCapture();
        score = -Quiesce( -beta, -alpha );
        TakeBackMove();

        if( score >= beta )
            return beta;
        if( score > alpha )
           alpha = score;
    }
    return alpha;
}

这是我的代码:

    private double QuiescenceSearch(GameBoard gameBoard, double alpha, double beta, int color)
    {
        double standPat = color * CalculateBoardScore(gameBoard);

        if (standPat >= beta)
        {
            return beta;
        }
        else if (alpha < standPat)
        {
            alpha = standPat;
        }

        foreach (Move move in GetNoisyMoves(gameBoard))
        {
            gameBoard.TrustedPlay(move);
            double score = -1.0 * QuiescenceSearch(gameBoard, -beta, -alpha, -color);
            gameBoard.UndoLastMove();

            if (score >= beta)
            {
                return beta;
            }
            else if (score > alpha)
            {
                alpha = score;
            }
        }

        return alpha;
    }

也就是说,AI 似乎表现得好像做出最糟糕的举动(自杀)是必经之路。

CalculateBoardScore 总是从颜色 == 1 侧 returns,因此乘以颜色。

我重构了我的代码,现在可以正常工作了:

private double QuiescenceSearch(GameBoard gameBoard, double alpha, double beta, int color)
{
    double bestValue = color * CalculateBoardScore(gameBoard);

    alpha = Math.Max(alpha, bestValue);

    if (alpha >= beta)
    {
        return bestValue;
    }

    foreach (Move move in GetNoisyMoves(gameBoard))
    {
        gameBoard.TrustedPlay(move);
        double value = -1 * QuiescenceSearch(gameBoard, -beta, -alpha, -color);
        gameBoard.UndoLastMove();

        bestValue = Math.Max(bestValue, value);

        alpha = Math.Max(alpha, bestValue);

        if (alpha >= beta)
        {
            break;
        }
    }

    return bestValue;
}

伪代码的问题是如果它大于 beta,它应该 return stand_pat/score,而不是 beta:

int Quiesce( int alpha, int beta ) {
    int stand_pat = Evaluate();
    if( stand_pat >= beta )
        return stand_pat;
    if( alpha < stand_pat )
        alpha = stand_pat;

    until( every_capture_has_been_examined )  {
        MakeCapture();
        score = -Quiesce( -beta, -alpha );
        TakeBackMove();

        if( score >= beta )
            return score;
        if( score > alpha )
           alpha = score;
    }
    return alpha;
}