Skip to content

Commit ecb83d0

Browse files
authored
Merge pull request #69 from Belzedar94/codex/fix-illegal-move-in-battlekings-engine
Fix battlekings gating when capturing commoners
2 parents 98229cc + 6803f5d commit ecb83d0

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Release
22

33
on:
44
push:
5-
branches: [ master, implement-battle-of-the-kings-variant-7bhqbn ]
5+
branches: [ master, implement-battle-of-the-kings-variant-7bhqbn, codex/fix-illegal-move-in-battlekings-engine ]
66
pull_request:
7-
branches: [ master, implement-battle-of-the-kings-variant-7bhqbn ]
7+
branches: [ master, implement-battle-of-the-kings-variant-7bhqbn, codex/fix-illegal-move-in-battlekings-engine ]
88

99
jobs:
1010
windows:

src/position.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,9 +599,9 @@ void Position::set_check_info(StateInfo* si) const {
599599
{
600600
PieceType pt = pop_lsb(ps);
601601
si->pseudoRoyalCandidates |= pieces(pt);
602-
if (count(sideToMove, pt) <= var->extinctionPieceCount + 1)
602+
if (extinction_first_capture() || count(sideToMove, pt) <= var->extinctionPieceCount + 1)
603603
si->pseudoRoyals |= pieces(sideToMove, pt);
604-
if (count(~sideToMove, pt) <= var->extinctionPieceCount + 1)
604+
if (extinction_first_capture() || count(~sideToMove, pt) <= var->extinctionPieceCount + 1)
605605
si->pseudoRoyals |= pieces(~sideToMove, pt);
606606
}
607607
}
@@ -1284,7 +1284,24 @@ bool Position::legal(Move m) const {
12841284
attackers &= ~SquareBB[capture_square(to)];
12851285

12861286
if (attackers)
1287-
return false;
1287+
{
1288+
bool captureEndsGame = false;
1289+
1290+
if ( extinction_first_capture()
1291+
&& capture(m))
1292+
{
1293+
Square captureSq = type_of(m) == EN_PASSANT ? capture_square(to) : to;
1294+
Piece captured = piece_on(captureSq);
1295+
1296+
if ( captured != NO_PIECE
1297+
&& color_of(captured) == ~us
1298+
&& (extinction_piece_types() & piece_set(type_of(captured))))
1299+
captureEndsGame = true;
1300+
}
1301+
1302+
if (!captureEndsGame)
1303+
return false;
1304+
}
12881305
}
12891306

12901307
// Flying general rule and bikjang

src/variant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ namespace {
792792
v->extinctionValue = -VALUE_MATE;
793793
v->extinctionPieceTypes = piece_set(COMMONER);
794794
v->extinctionMustAppear = piece_set(COMMONER);
795-
// v->extinctionPseudoRoyal = true;
795+
v->extinctionPseudoRoyal = true;
796796
v->extinctionFirstCaptureWins = true;
797797
return v;
798798
}

test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,24 @@ def test_battlekings_gating_capture_allows_commoner_spawn(self):
471471
moves = sf.legal_moves("battlekings", fen, [])
472472
self.assertIn("a2b2", moves)
473473

474+
def test_battlekings_commoner_capture_ends_game_even_if_gate_attacked(self):
475+
fen = "B1B1BB1q/qqBBRQqq/RB1qRBqQ/qRBqqB1R/QqqQqB1R/Rqqqqq1q/qkkqqqqq/kqqrq1br b - - 0 64"
476+
477+
moves = sf.legal_moves("battlekings", fen, [])
478+
self.assertNotIn("b2a3", moves)
479+
480+
white_to_move = "B1B1BB1q/qqBBRQqq/RB1qRBqQ/qRBqqB1R/QqqQqB1R/kqqqqq1q/q1kqqqqq/kqqrq1br w - - 0 65"
481+
white_moves = sf.legal_moves("battlekings", white_to_move, [])
482+
self.assertIn("a4a3", white_moves)
483+
484+
self._check_immediate_game_end(
485+
"battlekings",
486+
white_to_move,
487+
["a4a3"],
488+
True,
489+
-sf.VALUE_MATE,
490+
)
491+
474492
def test_legal_moves(self):
475493
fen = "10/10/10/10/10/k9/10/K9 w - - 0 1"
476494
result = sf.legal_moves("capablanca", fen, [])

0 commit comments

Comments
 (0)