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;
}