【发布时间】: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