@@ -1580,6 +1580,14 @@ def probe_dtm(self, board: chess.Board) -> int:
15801580 if board .castling_rights :
15811581 raise KeyError ("gaviota tables do not contain positions with castling rights: {}" .format (board .fen ()))
15821582
1583+ # Supports only up to 5 pieces.
1584+ if chess .popcount (board .occupied ) > 5 :
1585+ raise KeyError ("gaviota tables support up to 5 pieces, not {}: {}" .format (chess .popcount (board .occupied ), board .fen ()))
1586+
1587+ # KvK is a draw.
1588+ if board .occupied == board .kings :
1589+ return 0
1590+
15831591 # Prepare the tablebase request.
15841592 white_squares = list (chess .SquareSet (board .occupied_co [chess .WHITE ]))
15851593 white_types = [typing .cast (chess .PieceType , board .piece_type_at (sq )) for sq in white_squares ]
@@ -1589,22 +1597,11 @@ def probe_dtm(self, board: chess.Board) -> int:
15891597 epsq = board .ep_square if board .ep_square else NOSQUARE
15901598 req = Request (white_squares , white_types , black_squares , black_types , side , epsq )
15911599
1592- # KvK is a draw.
1593- if len (white_squares ) == 1 and len (black_squares ) == 1 :
1594- return 0
1595-
1596- # Supports only up to 5 pieces.
1597- if len (white_squares ) + len (black_squares ) > 5 :
1598- raise KeyError ("gaviota tables support up to 5 pieces, not {}: {}" .format (chess .popcount (board .occupied ), board .fen ()))
1599-
16001600 # Probe.
16011601 dtm = self .egtb_get_dtm (req )
16021602 ply , res = unpackdist (dtm )
16031603
1604- if res == iDRAW :
1605- # Draw.
1606- return 0
1607- elif res == iWMATE :
1604+ if res == iWMATE :
16081605 # White mates in the stored position.
16091606 if req .realside == 1 :
16101607 if req .is_reversed :
@@ -1628,6 +1625,9 @@ def probe_dtm(self, board: chess.Board) -> int:
16281625 return - ply
16291626 else :
16301627 return ply
1628+ else :
1629+ # Draw.
1630+ return 0
16311631
16321632 def get_dtm (self , board : chess .Board , default : Optional [int ] = None ) -> Optional [int ]:
16331633 try :
0 commit comments