Skip to content

Unify engine state on Game and adjudicate endgames with Syzygy - #325

Merged
kirillbobyrev merged 1 commit into
mainfrom
claude/codebase-review-0hfehw
Jul 21, 2026
Merged

Unify engine state on Game and adjudicate endgames with Syzygy#325
kirillbobyrev merged 1 commit into
mainfrom
claude/codebase-review-0hfehw

Conversation

@kirillbobyrev

Copy link
Copy Markdown
Owner

Summary

First of a planned sequence connecting the game/RL layer and making stored UCI options real. Removes dead code and duplication, and makes SyzygyTablebase actually affect play.

Previously the UCI engine tracked its own position + Vec<Key> history, while game.rs held a completely dead parallel Game/Environment/RepetitionTable implementation, and the SyzygyTablebase option was parsed and stored but never used.

Changes

  • Game is now the single game-state substrate. It owns the position, the repetition history, and an optional shared tablebase, and is what the engine holds (and what datagen will drive through the Environment trait next). The duplicate RepetitionTable is gone — repetition detection is a single history scan.
  • Syzygy adjudication in the live search. The optional tablebase is threaded into mcts::search; leaves with few enough pieces are probed for their exact WDL value instead of using the static eval. The probe now covers all positions up to the tablebase size (the old Game::result only adjudicated at exactly max_pieces). Confirmed Tablebase<Chess> is Send + Sync, so it's shared with the background search thread via Arc.
  • Search refactor to reduce boilerplate. MCTS is now a Searcher struct carrying the immutable inputs (root, history, tablebase), so simulate/expand/backup/info no longer thread them as parameters; PV construction and best-move selection share one most_visited_child helper.
  • Engine wiring. Loading SyzygyTablebase now actually loads the tables (reporting the piece count), shares them with the game and each search, and state reports the loaded size. <empty> clears them.

Testing

  • 131 tests pass (68 lib incl. new search-with-tablebase test; 47 chess; 9 integration incl. new tablebase-load test; 7 doctests).
  • Manual: loading the test tablebases over UCI and searching a KQvK position reports a winning score and a legal move; a full self-play game runs cleanly.
  • cargo clippy --all-targets --all-features reports zero warnings (the unification removed all previously-dead-code warnings); cargo +nightly fmt --check clean.

Move generation and make_move are untouched, so perft correctness is unaffected.

Next in the sequence

Transposition table + tree reuse (makes Hash real), then datagen self-play (built on this Game), a UCI-completeness pass, and the transmute safety cleanup.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GVrKvkMe4xDmkRAksacBzk


Generated by Claude Code

Previously the UCI engine tracked its own position + Vec<Key> history while
game.rs held a parallel, entirely dead Game/Environment/RepetitionTable
implementation, and the SyzygyTablebase option was stored but never used.

- Make Game the single game-state substrate: it owns the position, the
  repetition history and an optional shared tablebase, and is used by the
  engine (and, next, by datagen via the Environment trait). Remove the
  duplicate RepetitionTable (repetition is now a history scan in one place).
- Thread the optional tablebase into the search and probe WDL for positions
  with few enough pieces, making SyzygyTablebase actually affect play. The
  probe covers all positions up to the tablebase size (the old Game code only
  adjudicated at exactly max_pieces).
- Refactor the MCTS search into a Searcher struct that carries the immutable
  inputs (root, history, tablebase) so the per-iteration steps stop threading
  them as parameters; principal-variation and best-move selection share one
  most_visited_child helper.
- Engine loads the tablebase when SyzygyTablebase is set and shares it with
  the game and each search; state reports the loaded size.

Tests: new search-with-tablebase unit test and a UCI integration test that
loads the test tablebases; existing game tests adapted to the new API.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GVrKvkMe4xDmkRAksacBzk
@kirillbobyrev
kirillbobyrev marked this pull request as ready for review July 21, 2026 00:24
@kirillbobyrev
kirillbobyrev merged commit 60a01ba into main Jul 21, 2026
13 checks passed
@kirillbobyrev
kirillbobyrev deleted the claude/codebase-review-0hfehw branch July 21, 2026 00:24
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.

2 participants