ネガマックスでコネクトフォーをプレイしています。私が気付いたのは、アルファベータを追加すると、「間違った」結果が得られることがあるということです。アルファベータを削除すると、想定どおりに再生されます。アルファ-ベータは、実際に実行可能なブランチをいくつか切り取ることができますか (特に深さが制限されている場合)? 念のためのコードは次のとおりです。
int negamax(const GameState& state, int depth, int alpha, int beta, int color)
{
//depth end reached? or we actually hit a win/lose condition?
if (depth == 0 || state.points != 0)
{
return color*state.points;
}
//get successors and optimize the ordering/trim maybe too
std::vector<GameState> childStates;
state.generate_successors(childStates);
state.order_successors(childStates);
//no possible moves - then it's a terminal state
if (childStates.empty())
{
return color*state.points;
}
int bestValue = -extremePoints;
int v;
for (GameState& child : childStates)
{
v = -negamax(child, depth - 1, -beta, -alpha, -color);
bestValue = std::max(bestValue, v);
alpha = std::max(alpha, v);
if (alpha >= beta)
break;
}
return bestValue;
}