[CHAPTER 05 // crates/search & crates/core · engine, SPEC 003, engine, SPEC 001/R14] Implemented in engine code

Move Ordering: TT Move, SEE, Killers & Damped History

Staged candidate ordering prioritizing the transposition move, Static Exchange Evaluation captures, killer moves, and damped quiet history.

Why does BalouChess do this?

Alpha-beta pruning only saves work when strong refutation moves are searched first: examining the best reply right away lets BalouChess snip away the rest of the opponent's options, whereas searching weak moves first forces the engine to explore vastly larger trees.

BalouChess orders moves in crisp stages: first the proven transposition-table move, then winning and equal captures scored by Static Exchange Evaluation (SEE), then quiet 'killer' moves that caused beta cutoffs at the same ply, and finally quiet moves ranked by a bounded, damped history table.

Data Layout, Invariants & Common Pitfalls

Memory & State Layout

Staged picker (OrderingState) operating over disjoint tactical and quiet move generators (engine, SPEC 001 §4): (1) root previous-iteration winner and validated TT move (engine, SPEC 003/R20), (2) tactical moves ordered by Static Exchange Evaluation see_ge using fixed core piece constants (100, 300, 300, 500, 900 cp), (3) one ply-indexed quiet killer slot per ply ([Option<Move>; MAX_PLY], MAX_PLY = 128), and (4) a side-indexed 2×64×64 from/to-square quiet history table (side_to_move × from × to) with proportional decay and clamping.

Formal Invariants

  • Partition completeness without duplicates (engine, SPEC 001 §4): legal_tactical_moves (captures plus non-capture queen promotions) and legal_quiet_moves (remaining quiet moves including castling and quiet underpromotions) partition legal_moves 1-to-1.
  • Individually switchable SPRT discipline (engine, SPEC 003/R8, R13, R14): every ordering heuristic has a dedicated disable value in the central parameter table so its standalone strength contribution and node impact (such as the Split-Run A/B duels planned for the Web-Lab) can be measured cleanly.

Typical Pitfalls & Edge Cases

  • X-ray attackers in Static Exchange Evaluation (engine, SPEC 001 §5): when a pawn or minor piece captures on a square, a rook, bishop, or queen standing behind it along the cleared ray immediately joins the exchange sequence and must be uncovered dynamically.
  • Unbounded history overflow: naive additive bonuses cause long searches to overflow or freeze move rankings; proportional history gravity and explicit score clamping keep rankings bounded while adapting to new tactical themes.