niklasf/python-chess

Endgame tables

st4ck3 opened this issue · 2 comments

Hi,

Congratulations for the great library!

I'am having a problem with the endgame tablebases and a specific FEN, corresponding to an endgame with 6 men. Here is my code and the FEN:

import chess
import chess.engine
import chess.svg
import chess.pgn
import chess.syzygy

fen = "8/8/5p2/1k3K1B/6P1/4r3/8/8 w - - 0 54"
board = chess.Board(fen)

tablebase_dir = "c:/Users/.../.../.../Syzygy/6"
tb = chess.syzygy.open_tablebase(tablebase_dir)

print(tb.probe_wdl(board))

I get the following error:

File C:\Python...\python-3.12.3.amd64\Lib\site-packages\chess\syzygy.py:1570 in probe_wdl_table
table = typing.cast(WdlTable, self.wdl[key])

KeyError: 'KBPvKR'

Nevertheless, if I call the function calc_key(board) I get the correct key: 'KBPvKRP'

Any help would be greatly appreciated.

Best regards,

tb.add_directory("c:/Users/.../Syzygy/3-4-5")

Adding this line solves the issue.

If I understand correctly, the algorithm check all legal moves. And the error message was due to the unavailability of 5 men table, because the capture of a black pawn was a legal move checked by the algorithm.

Hi. It's a bit more efficient/complicated than all legal moves, but yes, if tables are missing the method is documented to raise KeyError.

So doing something like

try:
    wdl = tb.probe_wdl(board)
    # ...
except KeyError:
    # ...

is normal.