Skip to content

Track move legality in the type system - #63

Merged
nook0110 merged 5 commits into
deploy-elofrom
move-legality-types
Nov 12, 2026
Merged

nook0110 merged 5 commits into
deploy-elofrom
move-legality-types

Conversation

@nook0110

@nook0110 nook0110 commented Nov 8, 2026

Copy link
Copy Markdown
Owner

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.

  • PseudoLegalMove and LegalMove wrap Move (same size, trivially copyable); MaybeLegalMove is the two-byte "legal move or none" returned by the move picker.
  • Only the move generator, the picker's checked return paths and Position::TryPseudoLegal / Position::TryLegal can create them. Position::DoMove / UndoMove accept only LegalMove, so search, quiescence, perft, PV and ponder code cannot play an unchecked move. There is no unchecked bypass left in search.
  • UCI position ... moves now 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

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]>
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
@nook0110
nook0110 merged commit 1eaf139 into deploy-elo Nov 12, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant