From cc974fa7a4ffc5511ca6c4bc9ae1ef40c2827772 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Wed, 6 Jan 2010 09:58:41 +0100 Subject: [PATCH] Fix en-passant parsing from fen string According to standard en-passant is recorded in fen string regardless of whether there is a pawn in position to make an en passant capture. Instead internally we set ep square only if the pawn can be captured. So teach from_fen() to correctly handle this difference. Bug reported and fixed by Justin Blanchard. No functional change. Signed-off-by: Marco Costalba --- src/position.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index b4ccff5d..fb17f209 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -204,11 +204,16 @@ void Position::from_fen(const string& fen) { while (fen[i] == ' ') i++; - // En passant square + // En passant square -- ignore if no capture is possible if ( i <= fen.length() - 2 && (fen[i] >= 'a' && fen[i] <= 'h') && (fen[i+1] == '3' || fen[i+1] == '6')) - st->epSquare = square_from_string(fen.substr(i, 2)); + { + Square fenEpSquare = square_from_string(fen.substr(i, 2)); + Color them = opposite_color(sideToMove); + if (attacks_from(fenEpSquare, them) & this->pieces(PAWN, sideToMove)) + st->epSquare = square_from_string(fen.substr(i, 2)); + } // Various initialisation for (Square sq = SQ_A1; sq <= SQ_H8; sq++) -- 2.39.2