Ignore countStarted when either side has only one piece
authorAda Joule <ada.fulmina@gmail.com>
Sun, 12 Sep 2021 12:15:15 +0000 (19:15 +0700)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sun, 12 Sep 2021 14:49:08 +0000 (16:49 +0200)
src/position.h
test.py

index b09171d..6e7c1dc 100644 (file)
@@ -1171,7 +1171,7 @@ inline int Position::game_ply() const {
 }
 
 inline int Position::counting_ply(int countStarted) const {
-  return countStarted == 0 ? st->countingPly : std::min(st->countingPly, std::max(1 + gamePly - countStarted, 0));
+  return countStarted == 0 || (count<ALL_PIECES>(WHITE) <= 1 || count<ALL_PIECES>(BLACK) <= 1) ? st->countingPly : std::min(st->countingPly, std::max(1 + gamePly - countStarted, 0));
 }
 
 inline int Position::rule50_count() const {
diff --git a/test.py b/test.py
index 019a19a..2dc7f5b 100644 (file)
--- a/test.py
+++ b/test.py
@@ -359,6 +359,17 @@ class TestPyffish(unittest.TestCase):
         result = sf.get_fen("makruk", fen, moves, False, False, True)
         self.assertEqual(result, "8/2K3k1/5S2/6S1/8/8/8/8 b - 44 8 1")
 
+        # ignore count_started for piece honor counting
+        fen = "8/3k4/8/2K1S1P1/8/8/8/8 w - - 0 1"
+        moves = ["g5g6m"]
+        result = sf.get_fen("makruk", fen, moves, False, False, True, -1)
+        self.assertEqual(result, "8/3k4/6M~1/2K1S3/8/8/8/8 b - 88 8 1")
+
+        fen = "8/2K3k1/5m2/4S1S1/8/8/8/8 w - 128 1 30"
+        moves = ["e5f6"]
+        result = sf.get_fen("makruk", fen, moves, False, False, True, 58)
+        self.assertEqual(result, "8/2K3k1/5S2/6S1/8/8/8/8 b - 44 8 30")
+
         # makruk board honor counting
         fen = "3k4/2m5/8/4MP2/3KS3/8/8/8 w - - 0 1"
         moves = ["f5f6m"]