From 4921dbf5f03db400382313d27dadcb80530c91e5 Mon Sep 17 00:00:00 2001 From: GoldenRare Date: Tue, 6 Feb 2024 05:45:52 -0500 Subject: [PATCH 1/5] Minor simplification to static evaluation handling in search --- src/search.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index b23740d831b..40dc4293104 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -732,14 +732,14 @@ Value Search::Worker::search( else if (ss->ttHit) { // Never assume anything about values stored in TT - unadjustedStaticEval = ss->staticEval = eval = tte->eval(); - if (eval == VALUE_NONE) - unadjustedStaticEval = ss->staticEval = eval = evaluate(pos, thisThread->optimism[us]); + unadjustedStaticEval = tte->eval(); + if (unadjustedStaticEval == VALUE_NONE) + unadjustedStaticEval = evaluate(pos, thisThread->optimism[us]); else if (PvNode) Eval::NNUE::hint_common_parent_position(pos); Value newEval = - ss->staticEval + unadjustedStaticEval + thisThread->correctionHistory[us][pawn_structure_index(pos)] * std::abs(thisThread->correctionHistory[us][pawn_structure_index(pos)]) / 16384; From 98088d070131c786c608144dda9a797690315931 Mon Sep 17 00:00:00 2001 From: GoldenRare Date: Tue, 6 Feb 2024 06:40:00 -0500 Subject: [PATCH 2/5] Simplify static evaluation logic in qsearch --- src/search.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index 57a86ef297b..527c1cf0f7b 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -1442,9 +1442,8 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta, if (ss->ttHit) { // Never assume anything about values stored in TT - if ((unadjustedStaticEval = ss->staticEval = bestValue = tte->eval()) == VALUE_NONE) - unadjustedStaticEval = ss->staticEval = bestValue = - evaluate(pos, thisThread->optimism[us]); + if ((unadjustedStaticEval = tte->eval()) == VALUE_NONE) + unadjustedStaticEval = evaluate(pos, thisThread->optimism[us]); ss->staticEval = bestValue = to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos); From 8b246a6a627b6fd220f1bf38e4f54c724f39db78 Mon Sep 17 00:00:00 2001 From: GoldenRare Date: Sat, 10 Feb 2024 06:47:20 -0500 Subject: [PATCH 3/5] Remove unnecessary assignments --- src/search.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index 527c1cf0f7b..807a1f9abb3 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -715,7 +715,7 @@ Value Search::Worker::search( } else { - unadjustedStaticEval = ss->staticEval = eval = evaluate(pos, thisThread->optimism[us]); + unadjustedStaticEval = evaluate(pos, thisThread->optimism[us]); ss->staticEval = eval = to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos); // Static evaluation is saved as it was before adjustment by correction history @@ -1455,9 +1455,8 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta, else { // In case of null move search, use previous static eval with a different sign - unadjustedStaticEval = ss->staticEval = bestValue = - (ss - 1)->currentMove != Move::null() ? evaluate(pos, thisThread->optimism[us]) - : -(ss - 1)->staticEval; + unadjustedStaticEval = (ss - 1)->currentMove != Move::null() ? evaluate(pos, thisThread->optimism[us]) + : -(ss - 1)->staticEval; ss->staticEval = bestValue = to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos); } From 0792200fd13891241af4627a34de171bf1474b17 Mon Sep 17 00:00:00 2001 From: GoldenRare Date: Sat, 10 Feb 2024 07:30:50 -0500 Subject: [PATCH 4/5] Compliant with 'make format' style --- src/search.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index f12979919ef..538c76da6cb 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -1447,9 +1447,10 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta, else { // In case of null move search, use previous static eval with a different sign - unadjustedStaticEval = (ss - 1)->currentMove != Move::null() ? evaluate(pos, thisThread->optimism[us]) - : -(ss - 1)->staticEval; - ss->staticEval = bestValue = + unadjustedStaticEval = (ss - 1)->currentMove != Move::null() + ? evaluate(pos, thisThread->optimism[us]) + : -(ss - 1)->staticEval; + ss->staticEval = bestValue = to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos); } From 344db6a48e3cc59782342a897ccda6e0a7425666 Mon Sep 17 00:00:00 2001 From: GoldenRare Date: Sat, 10 Feb 2024 08:09:43 -0500 Subject: [PATCH 5/5] Minor refactor --- src/search.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/search.cpp b/src/search.cpp index 538c76da6cb..b186d8a9ec7 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -1434,7 +1434,8 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta, if (ss->ttHit) { // Never assume anything about values stored in TT - if ((unadjustedStaticEval = tte->eval()) == VALUE_NONE) + unadjustedStaticEval = tte->eval(); + if (unadjustedStaticEval == VALUE_NONE) unadjustedStaticEval = evaluate(pos, thisThread->optimism[us]); ss->staticEval = bestValue = to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos);