
214
■
7
章
AI
における経路探索
//
打てる手がないなら、プレイヤーの観点から盤面の評価を返す。
Iterator<IGameMove> it = player.validMoves(state).iterator();
if (ply == 0 || !it.hasNext()) {
return new MoveEvaluation (player.eval(state));
}
// alpha
を改善する「子節点の点数符号を反転させたものの最大値」を選択する
MoveEvaluation best = new MoveEvaluation (alpha);
while (it.hasNext()) {
IGameMove move = it.next();
move.execute(state);
MoveEvaluation me
= alphabeta (ply-1, opponent, player, -beta, -alpha);
move.undo(state);
// alpha
が改善されたら、この手を覚えておく
if (-me.score > alpha) {
alpha = -me.score;
best = new MoveEvaluation (move, alpha);
}
if (alpha >= beta) { return best; } //
探索はもはや意味がない
}
return best;
}
}
見つかった手は、
ミニマックス ...