From edf43289d452ab8a6cc941f5e7ccb732bee59a40 Mon Sep 17 00:00:00 2001 From: Gabor Berenyi <205867+ber4444@users.noreply.github.com> Date: Wed, 15 Jul 2026 07:54:37 -0700 Subject: [PATCH] BREAK castling: allow queenside castle through attacked d-square MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SYNTHETIC BUG — intentional mutation to test CI's regression coverage. Drops the attack check on the king's queenside transit square (d1/d8) in getCastlingMoves. This violates FIDE castling rule (king may not pass through an attacked square), allowing two extra illegal castles in Kiwipete depth-2 (2041 vs canonical 2039). The bespoke CastlingTest does NOT cover the d-file case (gap), so it still passes. The perft oracle (PerftTest/PerftCanonicalGateTest/ PerftVsStockfishTest) catches it on castling-rich positions. Expect: CI red on :chess-core:desktopTest and :chess-core:check. Do NOT merge — revert immediately after CI verdict is captured. --- .../commonMain/kotlin/com/example/myapplication/Move.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/chess-core/src/commonMain/kotlin/com/example/myapplication/Move.kt b/chess-core/src/commonMain/kotlin/com/example/myapplication/Move.kt index ebad349..6f70286 100644 --- a/chess-core/src/commonMain/kotlin/com/example/myapplication/Move.kt +++ b/chess-core/src/commonMain/kotlin/com/example/myapplication/Move.kt @@ -449,12 +449,10 @@ internal fun getCastlingMoves( c !in allyPositions && c !in enemyPositions && d !in allyPositions && d !in enemyPositions) { - // Simulate to check for check on d and c (b doesn't need to be unattacked) - val simD = allyPositions.toMutableList().apply { set(kingIndex, d) } + // Simulate to check for check on c (b and d don't need to be unattacked) val simC = allyPositions.toMutableList().apply { set(kingIndex, c) } - - if (!checkCheck(d, enemyPositions, enemyPieces, simD) && - !checkCheck(c, enemyPositions, enemyPieces, simC)) { + + if (!checkCheck(c, enemyPositions, enemyPieces, simC)) { castlingMoves.add(Pair(c, kingIndex)) } }