From: Fabian Fichter Date: Sat, 3 May 2025 15:59:55 +0000 (+0200) Subject: Fix custom ep captures X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=9d5cfcbda128c36e9033a84ae84499fa4a00674a;p=fairystockfish.git Fix custom ep captures Pick the frontmost piece to be captured. Closes #876. --- diff --git a/src/position.h b/src/position.h index 9818ede..242a4c9 100644 --- a/src/position.h +++ b/src/position.h @@ -1395,8 +1395,18 @@ inline bool Position::capture(Move m) const { inline Square Position::capture_square(Square to) const { assert(is_ok(to)); // The capture square of en passant is either the marked ep piece or the closest piece behind the target square - Bitboard b = ep_squares() & pieces() ? ep_squares() & pieces() : pieces(~sideToMove) & forward_file_bb(~sideToMove, to); - return sideToMove == WHITE ? msb(b) : lsb(b); + Bitboard customEp = ep_squares() & pieces(); + if (customEp) + { + // For longer custom en passant paths, we take the frontmost piece + return sideToMove == WHITE ? lsb(customEp) : msb(customEp); + } + else + { + // The capture square of normal en passant is the closest piece behind the target square + Bitboard epCandidates = pieces(~sideToMove) & forward_file_bb(~sideToMove, to); + return sideToMove == WHITE ? msb(epCandidates) : lsb(epCandidates); + } } inline bool Position::virtual_drop(Move m) const {