Gaviota endgame tablebase probing

Gaviota tablebases provide WDL (win/draw/loss) and DTM (depth to mate) information for all endgame positions with up to 5 pieces. Positions with castling rights are not included.

chess.gaviota.open_tablebases(directory=None, libgtb=None, LibraryLoader=<ctypes.LibraryLoader object>)

Opens a collection of tablebases for probing.

First native access via the shared library libgtb is tried. You can optionally provide a specific library name or a library loader. The shared library has global state and caches, so only one instance can be open at a time.

Second pure Python probing code is tried.

class chess.gaviota.PythonTablebases(directory, lzma)

Provides access to Gaviota tablebases using pure Python code.

open_directory(directory)

Loads .gtb.cp4 tables from a directory.

probe_dtm(board)

Probes for depth to mate information.

Returns None if the position was not found in any of the tables.

Otherwise the absolute value is the number of half moves until forced mate. The value is positive if the side to move is winning, otherwise it is negative.

In the example position white to move will get mated in 10 half moves:

>>> with chess.gaviota.open_tablebases("data/gaviota") as tablebases:
...     tablebases.probe_dtm(chess.Board("8/8/8/8/8/8/8/K2kr3 w - - 0 1"))
...
-10
probe_wdl(board)

Probes for win/draw/loss-information.

Returns None if the position was not found in any of the tables.

Returns 1 if the side to move is winning, 0 if it is a draw, and -1 if the side to move is losing.

>>> with chess.gaviota.open_tablebases("data/gaviota") as tablebases:
...     tablebases.probe_wdl(chess.Board("8/4k3/8/B7/8/8/8/4K3 w - - 0 1"))
...
0
close()

Closes all loaded tables.

backports.lzma

For Python versions before 3.3 you have to install backports.lzma in order to use the pure Python probing code.

sudo apt-get install liblzma-dev libpython2.7-dev
pip install backports.lzma

libgtb

For faster access you can build and install a shared library. Otherwise the pure Python probing code is used.

git clone https://github.com/michiguel/Gaviota-Tablebases.git
cd Gaviota-Tablebases
make
sudo make install
class chess.gaviota.NativeTablebases(directory, libgtb)

Provides access to Gaviota tablebases via the shared library libgtb.