Add chess.chesstb: pure-Python prober for chesstb endgame tablebases - #1194
Open
noobpwnftw wants to merge 1 commit into
Open
Add chess.chesstb: pure-Python prober for chesstb endgame tablebases#1194noobpwnftw wants to merge 1 commit into
noobpwnftw wants to merge 1 commit into
Conversation
noobpwnftw
force-pushed
the
add-chesstb-tablebases
branch
7 times, most recently
from
July 1, 2026 01:08
a252d4c to
228bac6
Compare
noobpwnftw
force-pushed
the
add-chesstb-tablebases
branch
10 times, most recently
from
August 11, 2026 10:10
3edd50e to
b0e8430
Compare
chesstb tables store WDL, DTC, DTM and DTM50 for endgame material
configurations. This adds a pure-Python reader for the format, shaped like
chess.syzygy and chess.gaviota: open_tablebase() on a directory tree, then
probe() a board for all four values at once, or probe_wdl / probe_dtz /
probe_dtm / probe_dtm50 for one at a time.
The format, as read here: one table per material configuration, split by
side to move and compressed in blocks (LZMA, or LZ4 with an optional
dictionary prefix). Positions are addressed by a combinatorial index over
king symmetry classes and groups of identical pieces. Configurations of
equal strength share a single table, read through a rank-mirrored,
colour-swapped view of the position; one holding an opposing pawn pair may
also ship a smaller frozen-pair ('p') table, which is preferred when
present, and whose index counts only the free pieces. A table may omit one
side to move altogether, in which case its values are recovered by
minimaxing over legal children. En passant is not indexed and is applied as
a virtual-capture overlay at probe time. DTM50 carries a prefix index every
256 positions within a block and layers its values by halfmove clock.
Tables are memory-mapped and decoded a block at a time, with a shared LRU
holding decoded blocks across every open table against one budget.
_TableFile._open_source is the single seam where the transport is decided,
and the three table classes are named as class attributes, so serving
tables from something other than a mapping is three subclasses and a _find.
A Tablebase is safe to share between threads: probes register as readers so
close() can wait for them before unmapping, and table opens are
double-checked under a per-kind lock.
Positions with castling rights are rejected with MissingTableError, as
chess.syzygy and chess.gaviota do for the same input; the tables are built
without them. Positions are assumed legal, as they are on the C++ side.
Includes docs, tests, and seven small table sets (KBK..KRKR) as test data.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
noobpwnftw
force-pushed
the
add-chesstb-tablebases
branch
from
August 11, 2026 10:28
b0e8430 to
5898772
Compare
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.
Add
chess.chesstb: pure-Python prober for chesstb endgame tablebasesWhat this adds
A new module,
chess.chesstb, that probes the chesstb endgametablebase format directly from
chess.Boardpositions — in the same spirit asthe existing
chess.syzygyandchess.gaviotamodules.chesstb ships three table types per material:
.lzw.lzdtc.lzdtm50API
get_wdl/get_dtz/get_dtmare non-raising variants returning a default(
None) when no table is available.probe(board, rule50=0)returns the fullstructured result (all fields at once).
Why pure Python
chess.syzygyis pure Python; this follows suit. The module depends only onpython-chessand the standard library:lzmawithFORMAT_RAW(the C++side uses the LZMA SDK with props appended at each block tail).
(~30 lines) supporting the optional LZ4 dictionary. No new dependency.
The position index (symmetry canonicalization, king/pawn slice managers, the
binomial piece-group ranking, the radix-composed board index and the
index-permutation layout) and the probe orchestration (dropped-frame one-ply
minimax reconstruction for shrunk files, the en-passant overlay, and the DTM50
halfmove-clock layer selection) are faithful re-implementations of the C++
src/probelibrary. Square numbering already matches python-chess exactly(a1=0 … h8=63), so boards are consumed directly.
Validation
Every value is validated bit-for-bit against the reference C++ prober
(
tests/probe_fen) by enumerating positions and comparing WDL, DTC/dtz, DTMand DTM50 in lockstep:
0 mismatches.
materials (exercising the CONST/SINGLE/DOUBLE/MULTI changepoint state machine,
the draw-end hint, and
recover_mate_at_hmc) — 0 mismatches.and the asymmetric one-ply-minimax derive (109 of 145 materials ship a dropped
frame) — 0 mismatches.
Black) — verified against the oracle.
reference
lz4C library on every shipped WDL table..lzdtmtable is intentionally not read: DTM is served fromthe
.lzdtm50pack (layer 0), which supersedes it.A self-contained
test_chesstb.pypins representative expected values (no C++build required) and skips when no tables are present.