Repository navigation
Track move legality in the type system - #63
Merged
Merged
Conversation
Moves now carry their legality in their type. PseudoLegalMove and LegalMove wrap Move with no size or speed cost; MaybeLegalMove is the two-byte "legal move or none" the move picker returns. Only the move generator, the picker's checked return paths and the checked conversions Position::TryPseudoLegal and Position::TryLegal can create them, and Position::DoMove/UndoMove accept only LegalMove, so search, quiescence, perft, PV and ponder code cannot play an unchecked move. UCI "position ... moves" now validates every move and stops at the first illegal one with "info string illegal move <move>"; before, an illegal move was played into a corrupted position. Syzygy root moves are validated the same way. Search is node-for-node identical on 30 positions at depth 11, and instructions per node are unchanged (11977-11985 vs 11976-11982). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 8, 2026
Merge deploy-elo at 83917b9 while preserving checked move execution. Return MaybeLegalMove from the ProbCut picker and adapt search, NNUE, SEE, static-eval history and PV tests to the typed interfaces.
Preserve legal move boundaries in aspiration search, PV reporting and pin-cache tests. Bench: 696698
Preserve NodeExit and constexpr settings while carrying legal moves through scoped search helpers. Reject removed castling notation before move parsing. Bench: 696698
Adapt the single-network NNUE tests to legal move histories and checked special moves. Retain UCI castling-notation rejection cases. Bench: 696698
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Moves now carry their legality in their type, so a reader can tell from the signature which moves are guaranteed legal, and the compiler rejects playing an unchecked move.
PseudoLegalMoveandLegalMovewrapMove(same size, trivially copyable);MaybeLegalMoveis the two-byte "legal move or none" returned by the move picker.Position::TryPseudoLegal/Position::TryLegalcan create them.Position::DoMove/UndoMoveaccept onlyLegalMove, so search, quiescence, perft, PV and ponder code cannot play an unchecked move. There is no unchecked bypass left in search.position ... movesnow validates each move and stops at the first illegal one (info string illegal move e2e5); before, the illegal move was played into a corrupted position and the engine then answered from it. Syzygy root moves are validated the same way.Zero-cost check against 2fff081: search is node-for-node identical (main and quiescence nodes, bestmove) on 30 positions at depth 11; instructions per node 11977–11985 vs 11976–11982, cycles not slower. Machine-code differences in search are register allocation, scheduling and alignment only; the extra instructions are in the UCI and Syzygy validation paths. Perft and all 204 tests pass.
🤖 Generated with Claude Code