@@ -1585,6 +1585,15 @@ def probe_wdl_table(self, board: chess.Board) -> int:
15851585 return table .probe_wdl_table (board )
15861586
15871587 def probe_ab (self , board : chess .Board , alpha : int , beta : int , threats : bool = False ) -> Tuple [int , int ]:
1588+ # Check preconditions.
1589+ if board .uci_variant != self .variant .uci_variant :
1590+ raise KeyError (f"tablebase has been opened for { self .variant .uci_variant } , probed with: { board .uci_variant } " )
1591+ if board .castling_rights :
1592+ raise KeyError (f"syzygy tables do not contain positions with castling rights: { board .fen ()} " )
1593+ if chess .popcount (board .occupied ) > TBPIECES :
1594+ raise KeyError (f"syzygy tables support up to { TBPIECES } pieces, not { chess .popcount (board .occupied )} : { board .fen ()} " )
1595+
1596+ # Special case: Variant with compulsory captures.
15881597 if self .variant .captures_compulsory :
15891598 if board .is_variant_win ():
15901599 return 2 , 2
@@ -1701,14 +1710,6 @@ def probe_wdl(self, board: chess.Board) -> int:
17011710
17021711 Note that probing corrupted table files is undefined behavior.
17031712 """
1704- # Positions with castling rights are not in the tablebase.
1705- if board .castling_rights :
1706- raise KeyError (f"syzygy tables do not contain positions with castling rights: { board .fen ()} " )
1707-
1708- # Validate piece count.
1709- if chess .popcount (board .occupied ) > TBPIECES :
1710- raise KeyError (f"syzygy tables support up to { TBPIECES } pieces, not { chess .popcount (board .occupied )} : { board .fen ()} " )
1711-
17121713 # Probe.
17131714 v , _ = self .probe_ab (board , - 2 , 2 )
17141715
0 commit comments