【问题标题】:Alpha beta pruning search countAlpha beta 修剪搜索计数
【发布时间】:2017-04-28 03:30:42
【问题描述】:

我正在尝试使用 alpha beta 修剪算法;我得到了程序的工作。我需要弄清楚在选择 alpha 或 beta 值之前完成的搜索次数。我正在计算值,但我不确定计数值是否正确。

int alpha_beta(const int level, const bool player, const Board &board, int alpha, int beta, Move &move) {
**static int count = 0;**

if (board.isGameOver() || level == 0) {
    if (!board.isGameOver()) move = (board.legalMoves())[0];
    return (getScore(board));
}

vector<Move> children = board.legalMoves();

tempBoard = board;
permutator(children.begin(), children.end());
//cout << count;
//getchar();
if (player == MAX) {
    for (vector<Move>::iterator it = children.begin(); it != children.end(); it++) {
        Board child = board.doMove(*it);
        Move temp;
        int score = alpha_beta(level - 1, !player, child, alpha, beta, temp);
        if (score > alpha) {
            alpha = score; // We have found a better best move
            move = *it;
        }
        if (alpha >= beta) {
            move = *it;
            cout << alpha;
            return alpha; // Beta Cut Off
            cout << alpha;
        }
        count++;
    }

    **cout << "alpha count ="<<count;**
    std::getchar();
    return alpha; // This is our best move

}
else {
    for (vector<Move>::iterator it = children.begin(); it != children.end(); it++) {
        Board child = board.doMove(*it);
        Move temp;
        int score = alpha_beta(level - 1, !player, child, alpha, beta, temp);
        if (score < beta) {
            beta = score; // Opponent has found a better worse move
            move = *it;
        }
        if (alpha >= beta) {
            move = *it;
            cout << beta;
            return beta; // Alpha Cut Off
        }


        count++;
    }
    **cout <<" beta count ="<<count;**
    std::getchar();
    return beta; // This is the opponent's best move
}}

任何建议都会对搜索次数有所帮助。

【问题讨论】:

    标签: search count artificial-intelligence minimax alpha-beta-pruning


    【解决方案1】:

    只是一个简单的想法,可能你应该首先实现 Minimax 算法,因为基本上,alpha beta pruning 是 Minimax 的优化,所以如果你想在选择 alpha 或 beta 之前获得搜索的叶子总数,Minimax 是也许是个不错的选择。

    在这种情况下,您应该在树到达离开节点时添加一个计数器

    if (board.isGameOver() || level == 0) {
        count ++;
        if (!board.isGameOver()) move = (board.legalMoves())[0];
        return (getScore(board)); 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-15
      • 1970-01-01
      • 1970-01-01
      • 2015-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多