@@ -702,6 +702,56 @@ Value Search::Worker::search(
702702 // At this point, if excluded, skip straight to step 6, static eval. However,
703703 // to save indentation, we list the condition in all code between here and there.
704704
705+ // Step 6. Static evaluation of the position
706+ Value unadjustedStaticEval = VALUE_NONE;
707+ const auto correctionValue = correction_value (*this , pos, ss);
708+ if (ss->inCheck )
709+ {
710+ // Skip early pruning when in check
711+ ss->staticEval = eval = (ss - 2 )->staticEval ;
712+ improving = false ;
713+ }
714+ else if (excludedMove)
715+ unadjustedStaticEval = eval = ss->staticEval ;
716+ else if (ss->ttHit )
717+ {
718+ // Never assume anything about values stored in TT
719+ unadjustedStaticEval = ttData.eval ;
720+ if (!is_valid (unadjustedStaticEval))
721+ unadjustedStaticEval = evaluate (pos);
722+
723+ ss->staticEval = eval = to_corrected_static_eval (unadjustedStaticEval, correctionValue);
724+
725+ // ttValue can be used as a better position evaluation
726+ if (is_valid (ttData.value )
727+ && (ttData.bound & (ttData.value > eval ? BOUND_LOWER : BOUND_UPPER)))
728+ eval = ttData.value ;
729+ }
730+ else
731+ {
732+ unadjustedStaticEval = evaluate (pos);
733+ ss->staticEval = eval = to_corrected_static_eval (unadjustedStaticEval, correctionValue);
734+
735+ // Static evaluation is saved as it was before adjustment by correction history
736+ ttWriter.write (posKey, VALUE_NONE, ss->ttPv , BOUND_NONE, DEPTH_UNSEARCHED, Move::none (),
737+ unadjustedStaticEval, tt.generation ());
738+ }
739+
740+ // Set up the improving flag, which is true if current static evaluation is
741+ // bigger than the previous static evaluation at our turn (if we were in
742+ // check at our previous move we go back until we weren't in check) and is
743+ // false otherwise. The improving flag is used in various pruning heuristics.
744+ // Similarly, opponentWorsening is true if our static evaluation is better
745+ // for us than at the last ply.
746+ improving = ss->staticEval > (ss - 2 )->staticEval ;
747+ opponentWorsening = ss->staticEval > -(ss - 1 )->staticEval ;
748+
749+ // Hindsight adjustment of reductions based on static evaluation difference.
750+ if (priorReduction >= 3 && !opponentWorsening)
751+ depth++;
752+ if (priorReduction >= 2 && depth >= 2 && ss->staticEval + (ss - 1 )->staticEval > 173 )
753+ depth--;
754+
705755 // At non-PV nodes we check for an early TT cutoff
706756 if (!PvNode && !excludedMove && ttData.depth > depth - (ttData.value <= beta)
707757 && is_valid (ttData.value ) // Can happen when !ttHit or when access race in probe()
@@ -799,41 +849,8 @@ Value Search::Worker::search(
799849 }
800850 }
801851
802- // Step 6. Static evaluation of the position
803- Value unadjustedStaticEval = VALUE_NONE;
804- const auto correctionValue = correction_value (*this , pos, ss);
805852 if (ss->inCheck )
806- {
807- // Skip early pruning when in check
808- ss->staticEval = eval = (ss - 2 )->staticEval ;
809- improving = false ;
810853 goto moves_loop;
811- }
812- else if (excludedMove)
813- unadjustedStaticEval = eval = ss->staticEval ;
814- else if (ss->ttHit )
815- {
816- // Never assume anything about values stored in TT
817- unadjustedStaticEval = ttData.eval ;
818- if (!is_valid (unadjustedStaticEval))
819- unadjustedStaticEval = evaluate (pos);
820-
821- ss->staticEval = eval = to_corrected_static_eval (unadjustedStaticEval, correctionValue);
822-
823- // ttValue can be used as a better position evaluation
824- if (is_valid (ttData.value )
825- && (ttData.bound & (ttData.value > eval ? BOUND_LOWER : BOUND_UPPER)))
826- eval = ttData.value ;
827- }
828- else
829- {
830- unadjustedStaticEval = evaluate (pos);
831- ss->staticEval = eval = to_corrected_static_eval (unadjustedStaticEval, correctionValue);
832-
833- // Static evaluation is saved as it was before adjustment by correction history
834- ttWriter.write (posKey, VALUE_NONE, ss->ttPv , BOUND_NONE, DEPTH_UNSEARCHED, Move::none (),
835- unadjustedStaticEval, tt.generation ());
836- }
837854
838855 // Use static evaluation difference to improve quiet move ordering
839856 if (((ss - 1 )->currentMove ).is_ok () && !(ss - 1 )->inCheck && !priorCapture)
@@ -845,21 +862,6 @@ Value Search::Worker::search(
845862 pawnHistory[pawn_history_index (pos)][pos.piece_on (prevSq)][prevSq] << evalDiff * 13 ;
846863 }
847864
848- // Set up the improving flag, which is true if current static evaluation is
849- // bigger than the previous static evaluation at our turn (if we were in
850- // check at our previous move we go back until we weren't in check) and is
851- // false otherwise. The improving flag is used in various pruning heuristics.
852- // Similarly, opponentWorsening is true if our static evaluation is better
853- // for us than at the last ply.
854- improving = ss->staticEval > (ss - 2 )->staticEval ;
855- opponentWorsening = ss->staticEval > -(ss - 1 )->staticEval ;
856-
857- // Hindsight adjustment of reductions based on static evaluation difference.
858- if (priorReduction >= 3 && !opponentWorsening)
859- depth++;
860-
861- if (priorReduction >= 2 && depth >= 2 && ss->staticEval + (ss - 1 )->staticEval > 169 )
862- depth--;
863865
864866 // Step 7. Razoring
865867 // If eval is really low, skip search entirely and return the qsearch value.
0 commit comments