mirror of
https://github.com/official-stockfish/Stockfish.git
synced 2026-07-22 20:57:10 +00:00
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:
+12
-18
@@ -60,7 +60,6 @@ void syzygy_extend_pv(const OptionsMap& options,
|
|||||||
Stockfish::Search::RootMove& rootMove,
|
Stockfish::Search::RootMove& rootMove,
|
||||||
Value& v);
|
Value& v);
|
||||||
|
|
||||||
using Eval::evaluate;
|
|
||||||
using namespace Search;
|
using namespace Search;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -592,10 +591,8 @@ Value Search::Worker::search(
|
|||||||
// Step 2. Check for aborted search and immediate draw
|
// Step 2. Check for aborted search and immediate draw
|
||||||
if (threads.stop.load(std::memory_order_relaxed) || pos.is_draw(ss->ply)
|
if (threads.stop.load(std::memory_order_relaxed) || pos.is_draw(ss->ply)
|
||||||
|| ss->ply >= MAX_PLY)
|
|| ss->ply >= MAX_PLY)
|
||||||
return (ss->ply >= MAX_PLY && !ss->inCheck)
|
return (ss->ply >= MAX_PLY && !ss->inCheck) ? evaluate(pos)
|
||||||
? evaluate(networks[numaAccessToken], pos, refreshTable,
|
: value_draw(thisThread->nodes);
|
||||||
thisThread->optimism[us])
|
|
||||||
: value_draw(thisThread->nodes);
|
|
||||||
|
|
||||||
// Step 3. Mate distance pruning. Even if we mate at the next move our score
|
// 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
|
// 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
|
// Never assume anything about values stored in TT
|
||||||
unadjustedStaticEval = ttData.eval;
|
unadjustedStaticEval = ttData.eval;
|
||||||
if (!is_valid(unadjustedStaticEval))
|
if (!is_valid(unadjustedStaticEval))
|
||||||
unadjustedStaticEval =
|
unadjustedStaticEval = evaluate(pos);
|
||||||
evaluate(networks[numaAccessToken], pos, refreshTable, thisThread->optimism[us]);
|
|
||||||
else if (PvNode)
|
else if (PvNode)
|
||||||
Eval::NNUE::hint_common_parent_position(pos, networks[numaAccessToken], refreshTable);
|
Eval::NNUE::hint_common_parent_position(pos, networks[numaAccessToken], refreshTable);
|
||||||
|
|
||||||
@@ -747,9 +743,8 @@ Value Search::Worker::search(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unadjustedStaticEval =
|
unadjustedStaticEval = evaluate(pos);
|
||||||
evaluate(networks[numaAccessToken], pos, refreshTable, thisThread->optimism[us]);
|
ss->staticEval = eval =
|
||||||
ss->staticEval = eval =
|
|
||||||
to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos, ss);
|
to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos, ss);
|
||||||
|
|
||||||
// Static evaluation is saved as it was before adjustment by correction history
|
// 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
|
// Step 2. Check for an immediate draw or maximum ply reached
|
||||||
if (pos.is_draw(ss->ply) || ss->ply >= MAX_PLY)
|
if (pos.is_draw(ss->ply) || ss->ply >= MAX_PLY)
|
||||||
return (ss->ply >= MAX_PLY && !ss->inCheck)
|
return (ss->ply >= MAX_PLY && !ss->inCheck) ? evaluate(pos) : VALUE_DRAW;
|
||||||
? evaluate(networks[numaAccessToken], pos, refreshTable, thisThread->optimism[us])
|
|
||||||
: VALUE_DRAW;
|
|
||||||
|
|
||||||
assert(0 <= ss->ply && ss->ply < MAX_PLY);
|
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
|
// Never assume anything about values stored in TT
|
||||||
unadjustedStaticEval = ttData.eval;
|
unadjustedStaticEval = ttData.eval;
|
||||||
if (!is_valid(unadjustedStaticEval))
|
if (!is_valid(unadjustedStaticEval))
|
||||||
unadjustedStaticEval =
|
unadjustedStaticEval = evaluate(pos);
|
||||||
evaluate(networks[numaAccessToken], pos, refreshTable, thisThread->optimism[us]);
|
|
||||||
ss->staticEval = bestValue =
|
ss->staticEval = bestValue =
|
||||||
to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos, ss);
|
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
|
// In case of null move search, use previous static eval with opposite sign
|
||||||
unadjustedStaticEval =
|
unadjustedStaticEval =
|
||||||
(ss - 1)->currentMove != Move::null()
|
(ss - 1)->currentMove != Move::null() ? evaluate(pos) : -(ss - 1)->staticEval;
|
||||||
? evaluate(networks[numaAccessToken], pos, refreshTable, thisThread->optimism[us])
|
|
||||||
: -(ss - 1)->staticEval;
|
|
||||||
ss->staticEval = bestValue =
|
ss->staticEval = bestValue =
|
||||||
to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos, ss);
|
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(); }
|
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 {
|
namespace {
|
||||||
// Adjusts a mate or TB score from "plies to mate from the root" to
|
// Adjusts a mate or TB score from "plies to mate from the root" to
|
||||||
|
|||||||
@@ -313,6 +313,8 @@ class Worker {
|
|||||||
TimePoint elapsed() const;
|
TimePoint elapsed() const;
|
||||||
TimePoint elapsed_time() const;
|
TimePoint elapsed_time() const;
|
||||||
|
|
||||||
|
Value evaluate(const Position&);
|
||||||
|
|
||||||
LimitsType limits;
|
LimitsType limits;
|
||||||
|
|
||||||
size_t pvIdx, pvLast;
|
size_t pvIdx, pvLast;
|
||||||
|
|||||||
Reference in New Issue
Block a user