Alpha-beta stuck after certain moves
Posted: 03 Mar 2016, 10:55
I'm in the process of writing a chess program. So far, I've implemented correct move-generation and an alpha-beta pruning algorithm. The problem is, after certain moves the alpha-beta algorithm seems to take forever.
For example, the moves
My alpha-beta is organized as follows:
For example, the moves
- e2e4 a7a5
Qd1h5 a5a4
Bf1c4
My alpha-beta is organized as follows:
- Code: Select all
int alphabeta(int alpha, int beta, int depth, Position& position) {
if (depth == 0) return evaluate(position);
MoveList moves;
AddLegalMoves(moves);
if (moves.Length == 0) {
if (position.Checkmate()) return -INFINITY;
return 0;
}
for (Move move : moves) {
Position new_position = position;
new_position.MakeMove(move);
int score = alphabeta(-beta, -alpha, depth - 1, new_position);
if (score >= beta) return beta;
if (score > alpha) alpha = score;
}
return alpha;
}