Cleanup Evaluate Calls

Makes code a bit easier to read as well.

closes https://github.com/official-stockfish/Stockfish/pull/5722

No functional change
This commit is contained in:
Disservin
2024-12-15 13:52:20 +01:00
parent 77ec878ffa
commit 2dc47e4345
2 changed files with 14 additions and 18 deletions
+12 -18
View File
@@ -60,7 +60,6 @@ void syzygy_extend_pv(const OptionsMap& options,
Stockfish::Search::RootMove& rootMove,
Value& v);
using Eval::evaluate;
using namespace Search;
namespace {
@@ -592,10 +591,8 @@ Value Search::Worker::search(
// Step 2. Check for aborted search and immediate draw
if (threads.stop.load(std::memory_order_relaxed) || pos.is_draw(ss->ply)
|| ss->ply >= MAX_PLY)
return (ss->ply >= MAX_PLY && !ss->inCheck)
? evaluate(networks[numaAccessToken], pos, refreshTable,
thisThread->optimism[us])
: value_draw(thisThread->nodes);
return (ss->ply >= MAX_PLY && !ss->inCheck) ? evaluate(pos)
: value_draw(thisThread->nodes);
// Step 3. Mate distance pruning. Even if we mate at the next move our score
// would be at best mate_in(ss->ply + 1), but if alpha is already bigger because
@@ -732,8 +729,7 @@ Value Search::Worker::search(
// Never assume anything about values stored in TT
unadjustedStaticEval = ttData.eval;
if (!is_valid(unadjustedStaticEval))
unadjustedStaticEval =
evaluate(networks[numaAccessToken], pos, refreshTable, thisThread->optimism[us]);
unadjustedStaticEval = evaluate(pos);
else if (PvNode)
Eval::NNUE::hint_common_parent_position(pos, networks[numaAccessToken], refreshTable);
@@ -747,9 +743,8 @@ Value Search::Worker::search(
}
else
{
unadjustedStaticEval =
evaluate(networks[numaAccessToken], pos, refreshTable, thisThread->optimism[us]);
ss->staticEval = eval =
unadjustedStaticEval = evaluate(pos);
ss->staticEval = eval =
to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos, ss);
// Static evaluation is saved as it was before adjustment by correction history
@@ -1510,9 +1505,7 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta)
// Step 2. Check for an immediate draw or maximum ply reached
if (pos.is_draw(ss->ply) || ss->ply >= MAX_PLY)
return (ss->ply >= MAX_PLY && !ss->inCheck)
? evaluate(networks[numaAccessToken], pos, refreshTable, thisThread->optimism[us])
: VALUE_DRAW;
return (ss->ply >= MAX_PLY && !ss->inCheck) ? evaluate(pos) : VALUE_DRAW;
assert(0 <= ss->ply && ss->ply < MAX_PLY);
@@ -1542,8 +1535,7 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta)
// Never assume anything about values stored in TT
unadjustedStaticEval = ttData.eval;
if (!is_valid(unadjustedStaticEval))
unadjustedStaticEval =
evaluate(networks[numaAccessToken], pos, refreshTable, thisThread->optimism[us]);
unadjustedStaticEval = evaluate(pos);
ss->staticEval = bestValue =
to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos, ss);
@@ -1556,9 +1548,7 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta)
{
// In case of null move search, use previous static eval with opposite sign
unadjustedStaticEval =
(ss - 1)->currentMove != Move::null()
? evaluate(networks[numaAccessToken], pos, refreshTable, thisThread->optimism[us])
: -(ss - 1)->staticEval;
(ss - 1)->currentMove != Move::null() ? evaluate(pos) : -(ss - 1)->staticEval;
ss->staticEval = bestValue =
to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos, ss);
}
@@ -1730,6 +1720,10 @@ TimePoint Search::Worker::elapsed() const {
TimePoint Search::Worker::elapsed_time() const { return main_manager()->tm.elapsed_time(); }
Value Search::Worker::evaluate(const Position& pos) {
return Eval::evaluate(networks[numaAccessToken], pos, refreshTable,
optimism[pos.side_to_move()]);
}
namespace {
// Adjusts a mate or TB score from "plies to mate from the root" to