From d2c8485cf7f20ebe49aedec481f727bc4b267bfe Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Sat, 1 May 2021 21:24:58 +0200 Subject: [PATCH] Consider custom pieces in insufficient material Consider all custom pieces to have mating potential in order to avoid false positive insufficient material calls. Temporary solution for #294. --- src/apiutil.h | 3 +++ src/variant.cpp | 2 +- test.py | 5 +++++ 3 files changed, 9 insertions(+), 1 deletions(-) diff --git a/src/apiutil.h b/src/apiutil.h index 7ddcc17..d1e35b3 100644 --- a/src/apiutil.h +++ b/src/apiutil.h @@ -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 }) diff --git a/src/variant.cpp b/src/variant.cpp index 4442c33..1f2ef8a 100644 --- a/src/variant.cpp +++ b/src/variant.cpp @@ -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 --- 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 = { -- 1.7.0.4