我正在用alpha-beta修剪编程一个negamax。但是,只有删除“坏”线但我不知道为什么它才有效。我的代码基于pseudo-code。这是对的吗?大多数实现在循环内调用negamax(在根节点的单独函数上),我应该这样做吗?为什么呢?
private static double AlphaBetaWithMemory(Board board, int player,
int depth,
int max_depth, double alpha, double beta) {
double eval = Double.NEGATIVE_INFINITY;
List<Integer> moves;
if (depth == max_depth
|| board.gameOver()) {
double h = board.heuristic(player);
return h;
} else {
movs=board.getMoves();
for (Integer m : moves) {
if (depth == 1) {
double val = -AlphaBetaWithMemory(
board.move(m), (player + 1) % 2,
depth + 1,
max_depth, -beta, -alpha);
if (val > eval) {
best_mov = m;
eval = val;
} else if (val == eval) {
if (Math.random() > 0.5) {
best_mov = m;
}
}
alpha = Math.max(alpha, val); //"BAD" LINE
} else {
double val = -AlphaBetaWithMemory(
board.mover(m), (player + 1) % 2,
depth + 1,
max_depth, -beta, -alpha);
eval = Math.max(eval, val);
alpha = Math.max(alpha, val);
if (alpha >= beta) {
return beta;
}
}
}
}
return eval;
答案 0 :(得分:0)
问题是:
else if (val == eval) {
if (Math.random() > 0.5) {
best_mov = m;
}
}
要解决这个问题(并保持随机性),我只需要随意播放&#34; movs&#34;。我知道排序&#34; movs&#34;会更有效率。