1
建立一个极小位置树对于Connect4比赛,我需要这个的Alpha-Beta算法转换成由Aske Plaat在他的MTD(F)算法解释AlphaBetaWithMemory算法:https://people.csail.mit.edu/plaat/mtdf.html#abmem如何在JavaScript
所以,我需要一些提示关于如何构建可能移动的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;
}
}