Fix custom king insufficient material
authorFabian Fichter <ianfab@users.noreply.github.com>
Sun, 20 Aug 2023 10:51:17 +0000 (12:51 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sun, 20 Aug 2023 10:51:17 +0000 (12:51 +0200)
Closes #686.

src/apiutil.h
test.py

index d753579..ca5858e 100644 (file)
@@ -404,6 +404,11 @@ inline bool has_insufficient_material(Color c, const Position& pos) {
     if ((pos.pieces(c) & unbound) && (popcount(pos.pieces() ^ restricted) >= 2 || pos.stalemate_value() != VALUE_DRAW || pos.check_counting() || pos.makpong()))
         return false;
 
+    // Non-draw stalemate with lone custom king
+    if (   pos.stalemate_value() != VALUE_DRAW && pos.king_type() != KING
+        && pos.pieces(c, KING) && (pos.board_bb(c, KING) & pos.board_bb(~c, KING)))
+        return false;
+
     return true;
 }
 
diff --git a/test.py b/test.py
index 3a40a54..1155817 100644 (file)
--- a/test.py
+++ b/test.py
@@ -84,6 +84,13 @@ capturesToHand = true
 firstRankPawnDrops = true
 promotionZonePawnDrops = true
 immobilityIllegal = true
+
+[wazirking:chess]
+fers = q
+king = k:W
+startFen = 7k/5Kq1/8/8/8/8/8/8 w - - 0 1
+stalemateValue = loss
+nFoldValue = loss
 """
 
 sf.load_variant_config(ini_text)
@@ -193,6 +200,9 @@ variant_positions = {
         "10/5k4/10/10/10/10/10/10/5KC3/10 w - - 0 1":  (False, True),  # KC vs K
         "10/5k4/10/10/10/10/10/10/5K4/10 w - - 0 1":  (True, True),  # K vs K
     },
+    "wazirking": {
+        "7k/6K1/8/8/8/8/8/8 b - - 0 1": (False, False),  # K vs K
+    },
 }
 
 invalid_variant_positions = {