Fix insufficient material handling for makpong
authorFabian Fichter <ianfab@users.noreply.github.com>
Thu, 29 Jul 2021 21:19:46 +0000 (23:19 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Thu, 29 Jul 2021 21:19:46 +0000 (23:19 +0200)
Closes #335.

src/apiutil.h
test.py

index 7d7bde0..f51d899 100644 (file)
@@ -322,11 +322,11 @@ inline bool has_insufficient_material(Color c, const Position& pos) {
     for (PieceType pt : { BISHOP, FERS, FERS_ALFIL, ALFIL, ELEPHANT })
         colorbound |= pos.pieces(pt) & ~restricted;
     unbound = pos.pieces() ^ restricted ^ colorbound;
-    if ((colorbound & pos.pieces(c)) && (((DarkSquares & colorbound) && (~DarkSquares & colorbound)) || unbound || pos.stalemate_value() != VALUE_DRAW || pos.check_counting()))
+    if ((colorbound & pos.pieces(c)) && (((DarkSquares & colorbound) && (~DarkSquares & colorbound)) || unbound || pos.stalemate_value() != VALUE_DRAW || pos.check_counting() || pos.makpong()))
         return false;
 
     // Unbound pieces require one helper piece of either color
-    if ((pos.pieces(c) & unbound) && (popcount(pos.pieces() ^ restricted) >= 2 || pos.stalemate_value() != VALUE_DRAW || pos.check_counting()))
+    if ((pos.pieces(c) & unbound) && (popcount(pos.pieces() ^ restricted) >= 2 || pos.stalemate_value() != VALUE_DRAW || pos.check_counting() || pos.makpong()))
         return false;
 
     return true;
diff --git a/test.py b/test.py
index bc17df2..a0e0ccb 100644 (file)
--- a/test.py
+++ b/test.py
@@ -133,6 +133,11 @@ variant_positions = {
         "k7/8/8/8/8/8/8/KFF5[] w - - 0 1": (False, True),  # KFF vs K
         "k7/8/8/8/8/8/8/KS6[] w - - 0 1": (False, True),  # KS vs K
     },
+    "makpong": {
+        "8/8/8/4k2K/5m~2/4m~3/8/8 w - 128 8 58": (True, False),  # KFF vs K
+        "k7/n7/8/8/8/8/8/K7 w - - 0 1": (True, False),  # K vs KN
+        "k7/8/8/8/8/8/8/K7 w - - 0 1": (True, True),  # K vs K
+    },
     "xiangqi": {
         "rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR w - - 0 1": (False, False),  # startpos
         "5k3/4a4/3CN4/9/1PP5p/9/8P/4C4/4A4/2B1K4 w - - 0 46": (False, False),  # issue #53