Repository navigation
[search-position] Add the "Position" page of ChessBase's search dialog - #11
tuliovianna-lab wants to merge 6 commits into
Conversation
- query::PositionQuery on GameDataQuery::position: "Look for", "Or" and "Exclude" boards of men (a piece of a colour, or a joker for any man of a colour), horizontal and vertical mirrors (colours swapped), and First, Length, Last with the dialog's defaults. "Sacrifice" is refused as unsupported. - The fragment compiles to bitboards per orientation; the replay stage tests it on each main-line position in the same single replay as the endings, and stops once the answer is known. Ending-only queries keep their own sink. - parse_fragment and the cbvault search options --look-for, --or, --exclude, --mirror, --first-move, --length, --last-move, --sacrifice. - Tests on classic and 2CBH fixtures, CLI tests, fixture and whole-database benchmarks, docs/search.md and the OpenSpec change search-position. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ovenance and measurements Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thank you for this PR — the bitboard compilation, single-replay design, and keeping Before we merge, there are a few items to address: 1. ChessBase parity checks (OpenSpec task
|
…eview tests - Tracker::passed: after a main-line move, a next move past Last settles the answer, so the move after Last is never decoded (a corrupt one no longer fails a valid 1..=Last search). - MainLine::resume ends the main line, so no variation move is decoded. - Tests: a 2CBH variation, both mirrors together, a set-up start (Black to move on move 10), Length up to Last, the same man in Look for and Exclude, a corrupt move right after Last, and an exhaustive square-by-square gigachess reference over every man on every square plus 2,000 pseudo-random combinations of boards, mirrors and windows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"Vertical" reflects across the vertical axis (files a<->h); "Horizontal" across the horizontal axis (ranks 1<->8) with the colours swapped. Checked against ChessBase on Mega Database 2026 (white bishop on h7): Horizontal 344,642 (cbvault 342,106), Vertical 395,103 (cbvault 389,913); the dialog draws the axis as a red line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mirror axes, "Or" and the start position agree with ChessBase on Mega Database 2026; ChessBase reads past move Last by a rule not yet established, recorded with the counts in docs/search.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Measured on Mega Database 2026: ChessBase looks at every position from the start through move max(Last, First + 1), plus the position after White's following move; First does not cut the positions before it. Eleven searches agree within 0.03% (docs/search.md). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the careful review. Everything is addressed in 99b4257, 1761dd0, 0f1986b and 0c6e426. 2. Early stops
3. Tests
1. ChessBase spot checks (Mega Database 2026, 11 searches)
All eleven counts agree within 0.03%:
The small remaining gap is not explained yet. It is recorded in |
Summary
Thank you for integrating the "Game data" search into v0.3.0. This PR adds the next page of ChessBase's search dialog, Position, on top of your v0.3 query architecture. It touches roadmap item 5 (
advanced-position-search-and-index-feeds, task 1.2): an explicitly defined partial-board predicate, with gigachess replay as the oracle.GameDataQuery::positiontakes aPositionQuery, combined with every "Game data" field:PositionQuerycbvault searchlook_for--look-for "Kg1 Rf1 Pf2g2h2"or--or BOARDexclude--exclude BOARDMan::Any(colour)X/xmirror_horizontal,mirror_vertical--mirror h|v|hvfirst,length,last--first-move,--length,--last-movesacrifice: refused,QueryError::Unsupported--sacrificeDesign
[colour][role]plus a mask per colour for jokers). The existing replay stage tests them on each main-line position withpiece_bb/occ_color, a dozen integer operations and no allocation.SelectedReplay::walkdrives a sink that stops as soon as the answer is known: at the first match (unless an ending is also asked for), after "Last", or when the main line ends. With--last-move 1, the whole Mega takes 0.45 s.FinalBoardsink.matches_endingbecamematches_replay, which dispatches on whether a pattern is present.Invalid.Semantics, and what is still open
ChessBase's help ("Search mask – Position") establishes three things:
It leaves four points open. I implemented the reading below for each, but have not compared them with ChessBase's counts yet; they are listed in
docs/search.mdand in task 2.5 of the change:Only the main line is searched; whether ChessBase also searches variations is open as well.
I computed the Mega 2026 counts for each competing reading, so a single ChessBase search settles each point. For example, a white bishop on h7 with the horizontal mirror gives 389,913 games if the mirror is a↔h, 401,207 if it is 1↔8 with the same colour, and 342,106 if it is 1↔8 with the colours swapped. I'm happy to share the list.
Measurements
Mega Database 2026 (2CBH, 11,740,862 records), warm,
CBVAULT_QUERY_REPORT=1 cargo bench -p cbvault --bench query:Shared replay stage, before (v0.3.0) and after this PR. Mega times are the mean of three alternating runs.
query_mate_1_thread, fixtureOn the fixture, the new
query_position_1_threadtakes 4.01 ms.Verification
cargo fmt --checkpasses.cargo clippy --workspace --all-targets --all-features -- -D warningspasses.cargo test --workspace --all-featurespasses, including:tests/query_position.rs: every board, the jokers, the mirrors, First / Length / Last, and combinations with names and endings, on classic and 2CBH fixtures. It also checks invariance across thread counts, that a fragment only in a variation does not match, the refusals and cancellation.cli_search.rs::position_options_reach_the_query.search-position(proposal, spec delta, tasks).Provenance
The code is original. The controls and their meanings come from ChessBase's dialog and public help page. No third-party position-search code was read.
gigachessstays the only chess core, and no dependency was added.🤖 Generated with Claude Code