Artificial Intelligence/Intelligent Chess bot
56 / 67

10/2021Artificial Intelligence

Intelligent Chess bot

A chess engine built on adversarial search — minimax with alpha-beta pruning, sharpened by iterative deepening, transposition tables, move ordering, and quiescence search.

╌╌╌╌

A chess engine built on classical adversarial search: minimax with alpha-beta pruning at its base, then a stack of refinements — iterative deepening, transposition tables, move ordering, null-move pruning, aspiration windows, and quiescence search — that make the textbook algorithm play well under a real clock.

Chess is a zero-sum game, so one number scores every position: the engine (MAX) picks the child of highest value, assuming the opponent (MIN) always answers with the lowest. Minimax computes that value by recursing to the leaves,

but the full tree is — and chess branches at . Searching it outright is hopeless; every refinement below reduces how much of it is searched.

Alpha-beta pruning keeps minimax's answer while skipping subtrees that cannot matter. The search carries a window — the best score each side can already force — and cuts off the moment a node's value falls outside it:

Algorithm:Alpha-Beta(n,α,β,d)\textsc{Alpha-Beta}(n, \alpha, \beta, d) — minimax with a cutoff window
  1. 1
    input: position nn, window [α,β][\alpha, \beta], remaining depth dd
  2. 2
    if d=0d = 0 or nn is terminal then return Quiescence(n,α,β)\textsc{Quiescence}(n, \alpha, \beta)
  3. 3
    if MAX to move then
  4. 4
    vv \gets -\infty
  5. 5
    for each move aa of nn, best first, do
  6. 6
    vmax(v,Alpha-Beta(Result(n,a),α,β,d1))v \gets \max(v, \textsc{Alpha-Beta}(\textsc{Result}(n, a), \alpha, \beta, d - 1))
  7. 7
    αmax(α,v)\alpha \gets \max(\alpha, v)
  8. 8
    if αβ\alpha \ge \beta then return vv
  9. 9
    return vv
  10. 10
    else
  11. 11
    v+v \gets +\infty
  12. 12
    for each move aa of nn, best first, do
  13. 13
    vmin(v,Alpha-Beta(Result(n,a),α,β,d1))v \gets \min(v, \textsc{Alpha-Beta}(\textsc{Result}(n, a), \alpha, \beta, d - 1))
  14. 14
    βmin(β,v)\beta \gets \min(\beta, v)
  15. 15
    if βα\beta \le \alpha then return vv
  16. 16
    return vv
A MAX root chooses among three MIN nodes. After the middle child resolves to , its remaining leaf (dashed) can never be played — the root already has a better line — so the search skips it.

With perfect move ordering, alpha-beta examines only nodes — the same horizon for half the exponent, which in practice doubles the reachable search depth.

Each refinement past alpha-beta strengthens either the pruning or the evaluation:

  • Iterative deepening searches depth until time runs out — and each pass's best line seeds the next pass's move ordering.
  • Transposition tables memoize positions reached by different move orders, so a position is searched once, not once per path.
  • Move ordering tries captures and killer moves first, pushing real play toward that best case.
  • Null-move pruning gives the opponent a free move; if the position is still winning, the subtree is cut without a full search.
  • Aspiration windows start each iteration with a narrow guessed from the last one, re-searching only when the score lands outside it.
  • Quiescence search extends the search at the horizon until the position is quiet, so the evaluation never scores a board mid-capture.
The horizon effect, and why leaves are only scored when quiet. A fixed-depth search ends one ply after the queen takes a pawn and scores the position a pawn up. Quiescence search keeps following captures past the horizon, finds the recapture that loses the queen, and returns the true score instead.

References

  1. Project repository
  2. Reference notes: Adversarial Search and Games
  3. Reference notes: Games of Chance and Imperfect Information
  4. Reference notes: Informed Search and A*

╌╌ END ╌╌