From 95803fc64a89307bfe51910f9e9349d120b81705 Mon Sep 17 00:00:00 2001 From: Niklas Fiekas Date: Thu, 4 Jul 2024 20:58:32 +0200 Subject: [PATCH] Artificially limit syzygy ab search after relaxing bound --- chess/syzygy.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/chess/syzygy.py b/chess/syzygy.py index 807b0922..8ba1cbca 100644 --- a/chess/syzygy.py +++ b/chess/syzygy.py @@ -1561,6 +1561,13 @@ def probe_ab(self, board: chess.Board, alpha: int, beta: int, threats: bool = Fa if board.castling_rights: raise KeyError(f"syzygy tables do not contain positions with castling rights: {board.fen()}") + # Probing resolves captures, so sometimes we can obtain results for + # positions that have more pieces than the maximum number of supported + # pieces. We artificially limit this to one additional level, to + # make sure search remains somewhat bounded. + if chess.popcount(board.occupied) > TBPIECES + 1: + raise KeyError(f"syzygy tables support up to {TBPIECES} pieces, not {chess.popcount(board.occupied)}: {board.fen()}") + # Special case: Variant with compulsory captures. if self.variant.captures_compulsory: if board.is_variant_win():