diff --git a/source/board.cpp b/source/board.cpp index b3c60ac..835f50d 100644 --- a/source/board.cpp +++ b/source/board.cpp @@ -346,7 +346,7 @@ void Board::MakeMove(Move move) { int targetPiece = GetPieceType(move.MoveTo()); int direction = attackerColor ? south : north; - int newEpTarget = -1; + int newEpTarget = noEPTarget; // Removing attacker piece from old position RemovePiece(attackerPiece, move.MoveFrom(), attackerColor); diff --git a/source/board.h b/source/board.h index 1116902..2d02777 100644 --- a/source/board.h +++ b/source/board.h @@ -5,7 +5,7 @@ #include "move.h" constexpr int nullPieceType = 100; -constexpr int noEPTarget = 100; +constexpr int noEPTarget = -1; class Board { public: diff --git a/source/movegen.cpp b/source/movegen.cpp index 0df13a2..d212172 100644 --- a/source/movegen.cpp +++ b/source/movegen.cpp @@ -481,9 +481,11 @@ static void GenPawnMoves(Board &board, bool color) { captures &= pinningRay; // Checking for en passant - if (captures.IsSet(board.enPassantTarget)) { - if (IsLegalEnPassant(board, square)) { - board.AddMove(Move(square, board.enPassantTarget, epCapture)); + if (board.enPassantTarget != noEPTarget) { + if (captures.IsSet(board.enPassantTarget)) { + if (IsLegalEnPassant(board, square)) { + board.AddMove(Move(square, board.enPassantTarget, epCapture)); + } } } @@ -515,10 +517,12 @@ static void GenPawnMoves(Board &board, bool color) { } // Checking for en passant - if (captures.IsSet(board.enPassantTarget)) { - // Checking if the move gives discovered check to own king - if (IsLegalEnPassant(board, square)) { - board.AddMove(Move(square, board.enPassantTarget, epCapture)); + if (board.enPassantTarget != noEPTarget) { + if (captures.IsSet(board.enPassantTarget)) { + // Checking if the move gives discovered check to own king + if (IsLegalEnPassant(board, square)) { + board.AddMove(Move(square, board.enPassantTarget, epCapture)); + } } } @@ -868,19 +872,21 @@ static void GenCheckEvasions(Board &board, bool color) { if (type == Pawn) { pushes |= getPawnPushes(square, color, board.occupied) & pushMask; // Checking for en passant capture - Bitboard attackedSquare = pawnAttacks[color][square] - & Bitboard::GetSquare(board.enPassantTarget); - if (attackedSquare) { - // 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) - || (attackedSquare & captureMask)) { - board.AddMove(Move(square, board.enPassantTarget, epCapture)); + if (board.enPassantTarget != noEPTarget) { + Bitboard attackedSquare = pawnAttacks[color][square] + & Bitboard::GetSquare(board.enPassantTarget); + if (attackedSquare) { + // 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) + || (attackedSquare & captureMask)) { + board.AddMove(Move(square, board.enPassantTarget, epCapture)); + } + captureMask.PopBit(targetSquare); } - captureMask.PopBit(targetSquare); } } } else {