Fix insufficient material for atomic
authorFabian Fichter <ianfab@users.noreply.github.com>
Tue, 7 Sep 2021 17:09:18 +0000 (19:09 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Tue, 7 Sep 2021 17:09:18 +0000 (19:09 +0200)
Closes #352.

src/apiutil.h
src/position.h
test.py

index f51d899..6d7b883 100644 (file)
@@ -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);
index b80de7a..b09171d 100644 (file)
@@ -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 (file)
--- 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