Quiescence Search with First-Ply Quiet Checks
Horizon-effect defense resolving captures, queen promotions, full check evasions, and quiet checking moves on the first quiescence ply.
Why does BalouChess do this?
Stopping a fixed-depth search in the middle of a piece trade makes an engine blind to the recapture waiting one half-move later (the classic horizon effect): it might think it just won a queen when its own queen is about to be taken back.
At depth zero, BalouChess transitions into quiescence search: it continues playing out tactical sequences (captures and queen promotions), tests quiet checking moves on the very first horizon ply to spot forcing forks and mates, and generates all legal evasions whenever a king is in check.
Data Layout, Invariants & Common Pitfalls
Memory & State Layout
Recursive Negamax tactical extension sharing MAX_PLY = 128 hard stack ceiling (engine, SPEC 003/R21). When not in check, computes stand-pat static evaluation as lower bound [alpha, beta] and searches legal_tactical_moves plus — at quiescence ply 0 when q_checks is enabled — quiet moves satisfying Position::gives_check(mv) (engine, SPEC 003/R22). When in check, stand-pat is suppressed and all legal evasions are searched.
Formal Invariants
- True checkmate and stalemate detection in check (engine, SPEC 003/R22): if the side to move is in check inside quiescence search, stand-pat is forbidden and every legal evasion is generated, so checkmate returns MateIn(-ply) rather than a false static score.
- Bounded stack depth without heap growth (engine, SPEC 003/R21): at ply == MAX_PLY (128), recursion terminates deterministically with mate/draw check or static evaluation, guaranteeing zero stack or evaluator overflow.
Typical Pitfalls & Edge Cases
- Unrestricted quiet checks across all quiescence plies: allowing quiet checks at every quiescence depth causes exponential checking chases; restricting quiet checks strictly to the first quiescence ply captures horizon tactics while keeping tree size bounded.
- Stand-pat while in check: assuming the side to move can always decline to move ('stand pat') produces illegal evaluations when the king is under attack and every legal reply loses material.