Consider custom pieces in insufficient material
authorFabian Fichter <ianfab@users.noreply.github.com>
Sat, 1 May 2021 19:24:58 +0000 (21:24 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sat, 1 May 2021 19:24:58 +0000 (21:24 +0200)
Consider all custom pieces to have mating potential
in order to avoid false positive insufficient material calls.

Temporary solution for #294.

src/apiutil.h
src/variant.cpp
test.py

index 7ddcc17..d1e35b3 100644 (file)
@@ -306,6 +306,9 @@ inline bool has_insufficient_material(Color c, const Position& pos) {
     for (PieceType pt : pos.piece_types())
         if (pt == KING || !(pos.board_bb(c, pt) & pos.board_bb(~c, KING)))
             restricted |= pos.pieces(c, pt);
+        else if (pt >= CUSTOM_PIECES && pt <= CUSTOM_PIECES_END && pos.count(c, pt) > 0)
+            // to be conservative, assume any custom piece has mating potential
+            return false;
 
     // Mating pieces
     for (PieceType pt : { ROOK, QUEEN, ARCHBISHOP, CHANCELLOR, SILVER, GOLD, COMMONER, CENTAUR })
index 4442c33..1f2ef8a 100644 (file)
@@ -717,7 +717,7 @@ namespace {
         v->pieceToCharTable = "PNBR.....G.++++Kpnbr.....g.++++k";
         v->maxRank = RANK_8;
         v->maxFile = FILE_H;
-        v->add_piece(CUSTOM_PIECES, 'n', std::string("fNsW"));
+        v->add_piece(CUSTOM_PIECES, 'n', "fNsW");
         v->startFen = "1nbgkgn1/1r4b1/pppppppp/8/8/PPPPPPPP/1B4R1/1NGKGBN1[-] w 0 1";
         v->promotionRank = RANK_6;
         v->promotedPieceType[CUSTOM_PIECES] = GOLD;
diff --git a/test.py b/test.py
index ce86be9..f174a0c 100644 (file)
--- a/test.py
+++ b/test.py
@@ -160,6 +160,11 @@ variant_positions = {
     "orda": {
         "k7/8/8/8/8/8/8/K7 w - - 0 1": (False, False),  # K vs K
     },
+    "tencubed": {
+        "2cwamwc2/1rnbqkbnr1/pppppppppp/10/10/10/10/PPPPPPPPPP/1RNBQKBNR1/2CWAMWC2 w - - 0 1":  (False, False),  # startpos
+        "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
+    },
 }
 
 invalid_variant_positions = {