Skip to content

Commit dca94e8

Browse files
committed
Fix Battlekings gating legality on captures
1 parent fdb1191 commit dca94e8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/position.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,15 @@ bool Position::legal(Move m) const {
12741274
Bitboard occ = occupied | gating_square(m);
12751275
if (type_of(m) == EN_PASSANT)
12761276
occ ^= capture_square(to);
1277-
if (attackers_to(gating_square(m), occ, ~us))
1277+
1278+
Bitboard attackers = attackers_to(gating_square(m), occ, ~us);
1279+
1280+
// Ignore attacks from squares that will be cleared as part of the move
1281+
attackers &= ~SquareBB[to];
1282+
if (type_of(m) == EN_PASSANT)
1283+
attackers &= ~SquareBB[capture_square(to)];
1284+
1285+
if (attackers)
12781286
return false;
12791287
}
12801288

test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,11 @@ def test_battlekings_first_commoner_capture_with_multiple(self):
466466
fen = "3qk3/pppp1ppp/2nkr3/4p1b1/P1N5/NPPP3P/NBNNPPPN/8 w - - 3 8"
467467
self._check_immediate_game_end("battlekings", fen, ["c4d6"], True, -sf.VALUE_MATE)
468468

469+
def test_battlekings_gating_capture_allows_commoner_spawn(self):
470+
fen = "1Q1QRQ2/BqqqQQQQ/R2Rqq1Q/QQQQ2qQ/qB1QRRq1/rq1q1BNQ/qQQQNRNP/1R6 b - - 0 57"
471+
moves = sf.legal_moves("battlekings", fen, [])
472+
self.assertIn("a2b2", moves)
473+
469474
def test_legal_moves(self):
470475
fen = "10/10/10/10/10/k9/10/K9 w - - 0 1"
471476
result = sf.legal_moves("capablanca", fen, [])

0 commit comments

Comments
 (0)