【问题标题】:How to build a minimax position tree in JavaScript如何在 JavaScript 中构建极小极大位置树
【发布时间】:2017-01-11 19:14:57
【问题描述】:

对于 Connect4 游戏,我需要将此 AlphaBeta 算法转换为 Aske Plaat 在他的 MTD(f) 算法中解释的 AlphaBetaWithMemory 算法:https://people.csail.mit.edu/plaat/mtdf.html#abmem

因此,我需要一些关于如何构建可能移动的极小极大树板位置的提示,以便能够以与 AlphaBetaWithMemory 相同的方式遍历其子节点。

真的希望大家给我一些建议。

谢谢。

Game.prototype.alphabeta = function( board, depth, alpha, beta, maximizingPlayer ) {

    // Call score of our board
    var score = board.score();

    // Break
    if (board.isFinished(depth, score)) return [null, score];

    if( maximizingPlayer )
    {
        // Column, Score
        var max = [null, -99999];

        // POSSIBLE MOVES
        for (var column = 0; column < that.columns; column++) 
        {
            var new_board = board.copy(); // Create new board

            if (new_board.place(column)) {

                that.iterations++; // Debug

                var next_move = that.alphabeta( new_board, depth-1, alpha, beta, false ); // Recursive calling

                // Evaluate new move
                if (max[0] == null || next_move[1] > max[1]) {
                    max[0] = column;
                    max[1] = next_move[1];
                    alpha = next_move[1];
                }

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

        return max; 
    }
    else
    {
        // Column, score
        var min = [null, 99999];

        // POSSIBLE MOVES
        for (var column = 0; column < that.columns; column++) {
            var new_board = board.copy();

            if (new_board.place(column)) {

                that.iterations++;

                var next_move = that.alphabeta(new_board, depth-1, alpha, beta, true );

                if (min[0] == null || next_move[1] < min[1]) {
                    min[0] = column;
                    min[1] = next_move[1];
                    beta = next_move[1];
                }

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

【问题讨论】:

    标签: javascript tree artificial-intelligence minimax alpha-beta-pruning


    【解决方案1】:

    AlphaBetaWithMemory 算法是一种标准的 alpha beta 算法,它使用 Transposition Table

    因此,如果您的 alpha beta 算法有效,您只需添加一个转置表来存储来自先前搜索的信息。如果没有转置表,MTD(f) 仍然是正确的,但效率不是很高。

    【讨论】:

      猜你喜欢
      • 2017-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-19
      • 1970-01-01
      • 1970-01-01
      • 2015-01-30
      相关资源
      最近更新 更多