From 9da30159201a1207a850ccbcba4c1c1a272f9d2b Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 13 Oct 2026 07:03:16 -0500 Subject: [PATCH] Restructure code --- src/search.cpp | 67 +++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index b9766ff..a320ea1 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -513,9 +513,16 @@ namespace ironphoenix { return ttProbe.score; } + const int staticEval = evaluate(pos); + const bool inCheckNode = pos.inCheck(); const auto& tuning = Tuning::search(); + const Color us = pos.sideToMove(); + const Color partner = static_cast(static_cast(us) ^ 2u); + + const bool partnerChecked = pos.inCheck(partner); + const bool mateWindow = !(alpha > -MATE_THRESHOLD && beta < MATE_THRESHOLD); // Null Move Pruning (NMP): keep expensive partner-check detection and @@ -524,42 +531,36 @@ namespace ironphoenix { && !pvNode && ply > 0 && depth >= NULL_MOVE_MIN_DEPTH + && staticEval >= beta + && !partnerChecked && !inCheckNode && !mateWindow && hasNonPawnMaterial(pos, us)) { - - const Color partner = static_cast(static_cast(us) ^ 2u); - if (!pos.inCheck(partner)) { - const int staticEval = evaluate(pos); - - if (staticEval >= beta) { - StateInfo nullState; - pos.makeNullMove(nullState); - searchStack_[ply + 1] = HistoryContext{}; - - // Dynamic null-move reduction: reduce the depth more aggressively - // at deeper nodes and for higher static evaluations. - const int reduction = 4 + depth / 5 + std::min(3, (staticEval - beta) / NULL_MOVE_DIVISOR); - const int nullScore = -negamax( - pos, - depth - reduction, - -beta, - -beta + 1, - ply + 1, - false, - false - ); - - pos.undoNullMove(nullState); - - if (shouldStop()) - return 0; - - // Never manufacture a mate score from a synthetic pass. - if (nullScore >= beta && nullScore < MATE_THRESHOLD) - return nullScore; - } - } + StateInfo nullState; + pos.makeNullMove(nullState); + searchStack_[ply + 1] = HistoryContext{}; + + // Dynamic null-move reduction: reduce the depth more aggressively + // at deeper nodes and for higher static evaluations. + const int reduction = 4 + depth / 5 + std::min(3, (staticEval - beta) / NULL_MOVE_DIVISOR); + const int nullScore = -negamax( + pos, + depth - reduction, + -beta, + -beta + 1, + ply + 1, + false, + false + ); + + pos.undoNullMove(nullState); + + if (shouldStop()) + return 0; + + // Never manufacture a mate score from a synthetic pass. + if (nullScore >= beta && nullScore < MATE_THRESHOLD) + return nullScore; } MoveList moves;