From 07f6edf93426fab8edb274232f9a40e46ea3d961 Mon Sep 17 00:00:00 2001 From: FauziAkram Date: Fri, 2 May 2025 18:32:55 +0300 Subject: [PATCH] Refactor Position::pseudo_legal Pawn Move Check use intermediate variables to make the statement easier to read closes https://github.com/official-stockfish/Stockfish/pull/6045 No functional change --- src/position.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index 9f023b5fe..5e2c27822 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -597,10 +597,14 @@ bool Position::pseudo_legal(const Move m) const { if ((Rank8BB | Rank1BB) & to) return false; - if (!(attacks_bb(from, us) & pieces(~us) & to) // Not a capture - && !((from + pawn_push(us) == to) && empty(to)) // Not a single push - && !((from + 2 * pawn_push(us) == to) // Not a double push - && (relative_rank(us, from) == RANK_2) && empty(to) && empty(to - pawn_push(us)))) + // Check if it's a valid capture, single push, or double push + const bool isCapture = bool(attacks_bb(from, us) & pieces(~us) & to); + const bool isSinglePush = (from + pawn_push(us) == to) && empty(to); + const bool isDoublePush = (from + 2 * pawn_push(us) == to) + && (relative_rank(us, from) == RANK_2) && empty(to) + && empty(to - pawn_push(us)); + + if (!(isCapture || isSinglePush || isDoublePush)) return false; } else if (!(attacks_bb(type_of(pc), from, pieces()) & to))