From 732a687a796e21c5cf97228dc3ed77bb2d8a67a1 Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Tue, 7 Sep 2021 19:09:18 +0200 Subject: [PATCH] Fix insufficient material for atomic Closes #352. --- src/apiutil.h | 5 ++++- src/position.h | 6 ++++++ test.py | 3 +++ 3 files changed, 13 insertions(+), 1 deletions(-) diff --git a/src/apiutil.h b/src/apiutil.h index f51d899..6d7b883 100644 --- a/src/apiutil.h +++ b/src/apiutil.h @@ -299,12 +299,15 @@ inline bool has_insufficient_material(Color c, const Position& pos) { // Other win rules if ( pos.captures_to_hand() || pos.count_in_hand(c, ALL_PIECES) - || pos.extinction_value() != VALUE_NONE + || (pos.extinction_value() != VALUE_NONE && !pos.extinction_pseudo_royal()) || (pos.capture_the_flag_piece() && pos.count(c, pos.capture_the_flag_piece()))) return false; // Restricted pieces Bitboard restricted = pos.pieces(~c, KING); + // Atomic kings can not help checkmating + if (pos.extinction_pseudo_royal() && pos.blast_on_capture() && pos.extinction_piece_types().find(COMMONER) != pos.extinction_piece_types().end()) + restricted |= pos.pieces(c, COMMONER); for (PieceType pt : pos.piece_types()) if (pt == KING || !(pos.board_bb(c, pt) & pos.board_bb(~c, KING))) restricted |= pos.pieces(c, pt); diff --git a/src/position.h b/src/position.h index b80de7a..b09171d 100644 --- a/src/position.h +++ b/src/position.h @@ -188,6 +188,7 @@ public: bool extinction_single_piece() const; int extinction_piece_count() const; int extinction_opponent_piece_count() const; + bool extinction_pseudo_royal() const; PieceType capture_the_flag_piece() const; Bitboard capture_the_flag(Color c) const; bool flag_move() const; @@ -867,6 +868,11 @@ inline int Position::extinction_opponent_piece_count() const { return var->extinctionOpponentPieceCount; } +inline bool Position::extinction_pseudo_royal() const { + assert(var != nullptr); + return var->extinctionPseudoRoyal; +} + inline PieceType Position::capture_the_flag_piece() const { assert(var != nullptr); return var->flagPiece; diff --git a/test.py b/test.py index a0e0ccb..019a19a 100644 --- a/test.py +++ b/test.py @@ -94,6 +94,9 @@ variant_positions = { }, "atomic": { "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1": (False, False), # startpos + "8/8/8/8/3K4/3k4/8/8 b - - 0 1": (True, True), # K vs K + "k7/p7/8/8/8/8/8/K7 w - - 0 1": (True, False), # K vs KP + "k7/q7/8/8/8/8/8/K7 w - - 0 1": (True, False), # K vs KQ }, "3check": { "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 3+3 0 1": (False, False), # startpos -- 1.7.0.4