minimax - 我的静态搜索有问题吗?

标签 minimax alpha-beta-pruning negamax

当我尝试实现 QuiesenceSearch 时,我的基于 negamax 的人工智能不断出现奇怪的行为。我基于 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;
    }

也就是说,人工智能的表现似乎就好像做出绝对最糟糕的举动(自杀)就是要走的路。

CalculateBoardScore 始终从 color == 1 一侧返回,因此乘以颜色。

最佳答案

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

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,而不是 beta,它应该返回stand_pat/score:

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

关于minimax - 我的静态搜索有问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48846642/

相关文章:

java - Negamax国际象棋算法: How to use final return?

python - 将 Minimax 转换为 Negamax (python)

lisp - 用 lisp 实现的井字游戏是完成游戏而不是一步一步

javascript - 协助在 Javascript 中连接四极小极大算法

java - minimax 代码始终返回 0

algorithm - 黑白棋评价函数

python - 2048 年 Alpha Beta 的问题

c minimax 使用 posix 线程

python - 从 Alphabeta 框架中收集和检索主要变化

c++ - 将 Alpha Beta 实现为 Minimax