File tree 2 files changed +20
-7
lines changed
2 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -1493,8 +1493,8 @@ def probe_dtm(self, board: chess.Board) -> int:
1493
1493
Probes for depth to mate information.
1494
1494
1495
1495
The absolute value is the number of half-moves until forced mate
1496
- (or ``0`` in drawn positions). The value is positive if the
1497
- side to move is winning, otherwise it is negative.
1496
+ (or ``0`` in drawn or checkmated positions). The value is positive if
1497
+ the side to move is winning, otherwise it is negative or 0 .
1498
1498
1499
1499
In the example position, white to move will get mated in 10 half-moves:
1500
1500
@@ -1532,11 +1532,14 @@ def probe_dtm(self, board: chess.Board) -> int:
1532
1532
try :
1533
1533
board .push (move )
1534
1534
1535
- child_dtm = - self ._probe_dtm_no_ep (board )
1536
- if child_dtm > 0 :
1537
- child_dtm += 1
1538
- elif child_dtm < 0 :
1539
- child_dtm -= 1
1535
+ if board .is_checkmate ():
1536
+ child_dtm = 1
1537
+ else :
1538
+ child_dtm = - self ._probe_dtm_no_ep (board )
1539
+ if child_dtm > 0 :
1540
+ child_dtm += 1
1541
+ elif child_dtm < 0 :
1542
+ child_dtm -= 1
1540
1543
1541
1544
dtm = min (dtm , child_dtm ) if dtm * child_dtm > 0 else max (dtm , child_dtm )
1542
1545
finally :
Original file line number Diff line number Diff line change @@ -4353,6 +4353,16 @@ def test_ep_is_best(self):
4353
4353
board = chess .Board ("8/8/7k/8/1pP5/7K/8/8 b - c3 0 1" )
4354
4354
self .assertEqual (self .tablebase .probe_dtm (board ), 19 )
4355
4355
4356
+ @catchAndSkip (chess .gaviota .MissingTableError , "need KQPvKP.gtb.cp4" )
4357
+ def test_ep_is_mate (self ):
4358
+ # The resulting mate.
4359
+ board = chess .Board ("5Q2/7k/6P1/5K2/8/8/8/8 b - - 0 1" )
4360
+ self .assertEqual (self .tablebase .probe_dtm (board ), 0 )
4361
+
4362
+ # Ep leads to the previously tested mate position.
4363
+ board = chess .Board ("5Q2/7k/8/5KpP/8/8/8/8 w - g6 0 1" )
4364
+ self .assertEqual (self .tablebase .probe_dtm (board ), 1 )
4365
+
4356
4366
4357
4367
class SvgTestCase (unittest .TestCase ):
4358
4368
You can’t perform that action at this time.
0 commit comments