我正在研究带有井字游戏(3x3)的 alpha-beta 修剪算法。目前对于 3x3 网格的任何给定实例,我都能够找出最佳情况:
public Best chooseAlphaBetaMove(int whosMov, int alpha, int beta) {
Best reply = new Best();
Best myBest = new Best();
if ((scoreGrid()==COMPUTER_WIN) || (scoreGrid()==OPPONENT_WIN) ||
(scoreGrid()==GAME_DRAW)) {
int score = scoreGrid();
return new Best(score,-3,-3,count);
}
if (whosMov==COMPUTER_MOVE) {
myBest.score = alpha;
} else {
myBest.score = beta;
}
for (int i=0; i<3; i++) {
for (int j=0; j<3; j++) {
if (layOut[i][j]==0) {
moveGrid(whosMov,i,j);
reply = chooseAlphaBetaMove(-whosMov,alpha,beta);
unmoveGrid(i,j);
if ((whosMov==COMPUTER_MOVE)&&(reply.score>myBest.score)) {
myBest.score = reply.score;
alpha = reply.score;
myBest.row = i;
myBest.column = j;
}
if ((whosMov==OPPONENT_MOVE)&&(reply.score<myBest.score)) {
myBest.score = reply.score;
beta = reply.score;
myBest.row = i;
myBest.column = j;
}
if (beta <= alpha) return myBest;
}
}
}
return myBest;
}
最佳结构在哪里:
public class Best {
public int score;
public int row;
public int column;
public int count
}
给定一个初始网格以及接下来谁将移动,我可以知道下一个玩家的最佳得分和最佳位置。但是,我不知道如何为这个最佳动作打印整个路径。(注意 - 我不想要整个搜索路径。我只想打印出从这个最佳移动到叶子的单个搜索路径)。有什么想法吗?谢谢!