From b1fb50ae697265369d51c002603a621ffe8f9bfa Mon Sep 17 00:00:00 2001 From: rn5f107s2 Date: Wed, 15 Apr 2026 20:35:24 +0200 Subject: [PATCH] Simplify away the special case for en passant in the legality check Since as of 94175524b1c06f1a4ce80a5640272a15120dcbbd the en passant square is only set if there is a legal en passant capture, the special handling is redundant Passed Non-Regression STC: https://tests.stockfishchess.org/tests/view/696ffb6512ee1f6231b96fe8 LLR: 2.95 (-2.94,2.94) <-1.75,0.25> Total: 79072 W: 20380 L: 20210 D: 38482. closes https://github.com/official-stockfish/Stockfish/pull/6560 No functional change --- src/position.cpp | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index fa732836c..1f3eba7f6 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -673,24 +673,6 @@ bool Position::legal(Move m) const { assert(color_of(moved_piece(m)) == us); assert(piece_on(square(us)) == make_piece(us, KING)); - // En passant captures are a tricky special case. Because they are rather - // uncommon, we do it simply by testing whether the king is attacked after - // the move is made. - if (m.type_of() == EN_PASSANT) - { - Square ksq = square(us); - Square capsq = to - pawn_push(us); - Bitboard occupied = (pieces() ^ from ^ capsq) | to; - - assert(to == ep_square()); - assert(moved_piece(m) == make_piece(us, PAWN)); - assert(piece_on(capsq) == make_piece(~us, PAWN)); - assert(piece_on(to) == NO_PIECE); - - return !(attacks_bb(ksq, occupied) & pieces(~us, QUEEN, ROOK)) - && !(attacks_bb(ksq, occupied) & pieces(~us, QUEEN, BISHOP)); - } - // Castling moves generation does not check if the castling path is clear of // enemy attacks, it is delayed at a later time: now! if (m.type_of() == CASTLING)