繁体   English   中英

如何在JavaScript中构建minimax位置树

[英]How to build a minimax position tree in JavaScript

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

因此,我需要一些关于如何构建可能移动的minimax树板位置的提示,以便能够以与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;
    }
}

AlphaBetaWithMemory算法是使用转置表的标准alpha beta算法。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM