From 5f77c88c85af9d5d8731ae4fd261563592d135db Mon Sep 17 00:00:00 2001 From: rektdie Date: Mon, 15 Apr 2024 10:48:05 +0200 Subject: [PATCH] bugfix: en passant was always possible in check evasions --- source/movegen.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/source/movegen.cpp b/source/movegen.cpp index 74b7f84..f152475 100644 --- a/source/movegen.cpp +++ b/source/movegen.cpp @@ -879,9 +879,20 @@ static void GenCheckEvasions(Board &board, bool color) { if (type == Pawn) { pushes |= getPawnPushes(square, color, board.occupied) & pushMask; // Checking for en passant capture - if ((pawnAttacks[color][square] - & Bitboard::GetSquare(board.enPassantTarget)).GetBoard()) { - board.AddMove(Move(square, board.enPassantTarget, epCapture)); + Bitboard attackedSquare = pawnAttacks[color][square] + & Bitboard::GetSquare(board.enPassantTarget); + if (attackedSquare.GetBoard()) { + // Checking if it's legal + if (IsLegalEnPassant(board, square)) { + int direction = color ? south : north; + int targetSquare = captureMask.getLS1BIndex() + direction; + captureMask.SetBit(targetSquare); + if ((attackedSquare & pushMask).GetBoard() + || (attackedSquare & captureMask).GetBoard()) { + board.AddMove(Move(square, board.enPassantTarget, epCapture)); + } + captureMask.PopBit(targetSquare); + } } } else { pushes |= getPieceAttacks(square, type, color, board.occupied.GetBoard()) & pushMask;