【发布时间】:2014-10-26 05:48:19
【问题描述】:
我为类似国际象棋的游戏制作了一个负最大算法,我想知道如何使用最终的棋盘值结果。我知道 negamax 算法的最终回报代表了玩家采取最佳行动后棋盘的价值,但这并不是完全有用的信息。我需要知道这个动作是什么,而不是它的价值。
代码如下:
public int negamax(Match match, int depth, int alpha, int beta, int color) {
if(depth == 0) {
return color*stateScore(match);
}
ArrayList<Match> matches = getChildren(match, color);
if(matches.size() == 0) {
return color*stateScore(match);
}
int bestValue = Integer.MIN_VALUE;
for(int i = 0; i != matches.size(); i++) {
int value = -negamax(matches.get(i), depth-1, -beta, -alpha, -color);
if(value > bestValue) {
bestValue = value;
}
if(value > alpha) {
alpha = value;
}
if(alpha >= beta) {
break;
}
}
return bestValue;
}
public void getBestMove(Match match, int color) {
int bestValue = negamax(match, 4, Integer.MIN_VALUE, Integer.MAX_VALUE, color);
// What to do with bestValue???
}
我想在确定 bestValue 后重新评估当前匹配状态的子项。然后我遍历它们并找出其中哪些孩子的 stateScore 等于 bestValue。但这行不通,因为他们中的很多人无论如何都会有相同的 stateScore,这是他们可以导致的结果......
【问题讨论】:
标签: java algorithm alpha-beta-pruning negamax