diff --git a/source/main.cpp b/source/main.cpp index 9ee0efa..aec8419 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -10,7 +10,7 @@ int main() { Board board; board.SetByFen("r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P2PP/R2Q1RK1 w kq - 0 1"); - Perft(board, 4); + Perft(board, 5); return 0; } \ No newline at end of file diff --git a/source/movegen.cpp b/source/movegen.cpp index 8de2249..15cf756 100644 --- a/source/movegen.cpp +++ b/source/movegen.cpp @@ -436,39 +436,27 @@ static bool IsLegalEnPassant(Board &board, int square) { newOccupancy.PopBit(board.enPassantTarget - pushDirection); // Looking for horizontal checks - if (!(kingSquare.GetBoard() & files[A])) { - int currentSq = kingSquare.getLS1BIndex() + west; + int directionToKing = GetDirection(square, kingSquare.getLS1BIndex()); - while (!Bitboard(files[H]).IsSet(currentSq)) { + // Either east or west + if (abs(directionToKing) == 1) { + int currentSq = square - directionToKing; + + Bitboard endingFile = directionToKing > 0 ? files[H] : files[A]; + + while (!endingFile.IsSet(currentSq)) { if (newOccupancy.IsSet(currentSq)) { - int attackerColor = board.GetPieceColor(currentSq); - int attackerType = board.GetPieceType(currentSq); + int squareColor = board.GetPieceColor(currentSq); + int squarePiece = board.GetPieceType(currentSq); - if (attackerColor != board.sideToMove && (attackerType == Rook - || attackerType == Bishop || attackerType == Queen)) { - return false; + if (squareColor != board.sideToMove) { + if (squarePiece == Rook || squarePiece == Queen) { + return false; + } } - return true; + break; } - currentSq += west; - } - } - - if (!(kingSquare.GetBoard() & files[H])) { - int currentSq = kingSquare.getLS1BIndex() + east; - - while (!Bitboard(files[A]).IsSet(currentSq)) { - if (newOccupancy.IsSet(currentSq)) { - int attackerColor = board.GetPieceColor(currentSq); - int attackerType = board.GetPieceType(currentSq); - - if (attackerColor != board.sideToMove && (attackerType == Rook - || attackerType == Bishop || attackerType == Queen)) { - return false; - } - return true; - } - currentSq += east; + currentSq -= directionToKing; } }