From 9d5cfcbda128c36e9033a84ae84499fa4a00674a Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Sat, 3 May 2025 17:59:55 +0200 Subject: [PATCH] Fix custom ep captures Pick the frontmost piece to be captured. Closes #876. --- src/position.h | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-) 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 { -- 1.7.0.4