Atomic check exception (#440)
authorAda Joule <ada.fulmina@gmail.com>
Sun, 13 Feb 2022 14:46:27 +0000 (21:46 +0700)
committerGitHub <noreply@github.com>
Sun, 13 Feb 2022 14:46:27 +0000 (15:46 +0100)
src/position.cpp
test.py
tests/js/test.js

index d1a1c1f..81de344 100644 (file)
@@ -923,8 +923,13 @@ Bitboard Position::attackers_to(Square s, Bitboard occupied) const {
 Bitboard Position::attackers_to_pseudo_royals(Color c) const {
   Bitboard attackers = 0;
   Bitboard pseudoRoyals = st->pseudoRoyals & pieces(~c);
+  Bitboard pseudoRoyalsTheirs = st->pseudoRoyals & pieces(c);
   while (pseudoRoyals) {
       Square sr = pop_lsb(pseudoRoyals);
+      if (blast_on_capture()
+          && pseudoRoyalsTheirs & attacks_bb<KING>(sr))
+          // skip if capturing this piece would blast all of the attacker's pseudo-royal pieces
+          continue;
       attackers |= attackers_to(sr, c);
   }
   return attackers;
diff --git a/test.py b/test.py
index 837847c..2996862 100644 (file)
--- a/test.py
+++ b/test.py
@@ -725,6 +725,9 @@ class TestPyffish(unittest.TestCase):
         result = sf.gives_check("atomic", "rnbqkbnr/ppp2ppp/8/8/8/8/PPP2PPP/RNBQKBNR w KQkq - 0 4", ["d1d7"])
         self.assertTrue(result)
 
+        result = sf.gives_check("atomic", "8/8/kK6/8/8/8/Q7/8 b - - 0 1", [])
+        self.assertFalse(result)
+
     def test_game_result(self):
         result = sf.game_result("chess", CHESS, ["f2f3", "e7e5", "g2g4", "d8h4"])
         self.assertEqual(result, -sf.VALUE_MATE)
index 6b26297..d7598b6 100644 (file)
@@ -484,6 +484,8 @@ describe('board.isCheck()', function () {
     board.setFen("rnbqkbnr/ppp2ppp/8/8/8/8/PPP2PPP/RNBQKBNR w KQkq - 0 4");
     board.pushSan("Qd7");
     chai.expect(board.isCheck()).to.equal(true);
+    board.setFen("8/8/kK6/8/8/8/Q7/8 b - - 0 1")
+    chai.expect(board.isCheck()).to.equal(false);
     board.delete();
   });
 });