Skip to content

Commit 5297ba0

Browse files
daniel-monroevondele
authored andcommitted
Move hindsight reductions above cutoffs
Passed STC LLR: 2.93 (-2.94,2.94) <0.00,2.00> Total: 52640 W: 13701 L: 13361 D: 25578 Ptnml(0-2): 168, 6143, 13356, 6487, 166 https://tests.stockfishchess.org/tests/view/6918dc407ca8781852332339 Passed LTC LLR: 2.95 (-2.94,2.94) <0.50,2.50> Total: 207690 W: 53187 L: 52520 D: 101983 Ptnml(0-2): 93, 22515, 57994, 23118, 125 https://tests.stockfishchess.org/tests/view/6919dd307ca87818523324c7 closes #6448 Bench: 2912398
1 parent abd835d commit 5297ba0

File tree

1 file changed

+50
-48
lines changed

1 file changed

+50
-48
lines changed

src/search.cpp

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)