mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-23 02:27:00 +08:00
Remove the dependency on a Worker from evaluate
Also remove dead code, `rootSimpleEval` is no longer used since the introduction of dual net. `iterBestValue` is also no longer used in evaluate and can be reduced to a local variable. closes https://github.com/official-stockfish/Stockfish/pull/4979 No functional change
This commit is contained in:
@@ -280,7 +280,7 @@ void Search::Worker::iterative_deepening() {
|
||||
|
||||
ss->pv = pv;
|
||||
|
||||
iterBestValue = -VALUE_INFINITE;
|
||||
Value bestValue = -VALUE_INFINITE;
|
||||
|
||||
if (mainThread)
|
||||
{
|
||||
@@ -357,7 +357,7 @@ void Search::Worker::iterative_deepening() {
|
||||
// for every four searchAgain steps (see issue #2717).
|
||||
Depth adjustedDepth =
|
||||
std::max(1, rootDepth - failedHighCnt - 3 * (searchAgainCounter + 1) / 4);
|
||||
iterBestValue = search<Root>(rootPos, ss, alpha, beta, adjustedDepth, false);
|
||||
bestValue = search<Root>(rootPos, ss, alpha, beta, adjustedDepth, false);
|
||||
|
||||
// Bring the best move to the front. It is critical that sorting
|
||||
// is done with a stable algorithm because all the values but the
|
||||
@@ -375,7 +375,7 @@ void Search::Worker::iterative_deepening() {
|
||||
|
||||
// When failing high/low give some update (without cluttering
|
||||
// the UI) before a re-search.
|
||||
if (mainThread && multiPV == 1 && (iterBestValue <= alpha || iterBestValue >= beta)
|
||||
if (mainThread && multiPV == 1 && (bestValue <= alpha || bestValue >= beta)
|
||||
&& mainThread->tm.elapsed(threads.nodes_searched()) > 3000)
|
||||
sync_cout << UCI::pv(*this, mainThread->tm.elapsed(threads.nodes_searched()),
|
||||
threads.nodes_searched(), threads.tb_hits(), tt.hashfull(),
|
||||
@@ -384,18 +384,18 @@ void Search::Worker::iterative_deepening() {
|
||||
|
||||
// In case of failing low/high increase aspiration window and
|
||||
// re-search, otherwise exit the loop.
|
||||
if (iterBestValue <= alpha)
|
||||
if (bestValue <= alpha)
|
||||
{
|
||||
beta = (alpha + beta) / 2;
|
||||
alpha = std::max(iterBestValue - delta, -VALUE_INFINITE);
|
||||
alpha = std::max(bestValue - delta, -VALUE_INFINITE);
|
||||
|
||||
failedHighCnt = 0;
|
||||
if (mainThread)
|
||||
mainThread->stopOnPonderhit = false;
|
||||
}
|
||||
else if (iterBestValue >= beta)
|
||||
else if (bestValue >= beta)
|
||||
{
|
||||
beta = std::min(iterBestValue + delta, int(VALUE_INFINITE));
|
||||
beta = std::min(bestValue + delta, int(VALUE_INFINITE));
|
||||
++failedHighCnt;
|
||||
}
|
||||
else
|
||||
@@ -428,8 +428,8 @@ void Search::Worker::iterative_deepening() {
|
||||
}
|
||||
|
||||
// Have we found a "mate in x"?
|
||||
if (limits.mate && iterBestValue >= VALUE_MATE_IN_MAX_PLY
|
||||
&& VALUE_MATE - iterBestValue <= 2 * limits.mate)
|
||||
if (limits.mate && bestValue >= VALUE_MATE_IN_MAX_PLY
|
||||
&& VALUE_MATE - bestValue <= 2 * limits.mate)
|
||||
threads.stop = true;
|
||||
|
||||
if (!mainThread)
|
||||
@@ -449,8 +449,8 @@ void Search::Worker::iterative_deepening() {
|
||||
// Do we have time for the next iteration? Can we stop searching now?
|
||||
if (limits.use_time_management() && !threads.stop && !mainThread->stopOnPonderhit)
|
||||
{
|
||||
double fallingEval = (66 + 14 * (mainThread->bestPreviousAverageScore - iterBestValue)
|
||||
+ 6 * (mainThread->iterValue[iterIdx] - iterBestValue))
|
||||
double fallingEval = (66 + 14 * (mainThread->bestPreviousAverageScore - bestValue)
|
||||
+ 6 * (mainThread->iterValue[iterIdx] - bestValue))
|
||||
/ 616.6;
|
||||
fallingEval = std::clamp(fallingEval, 0.51, 1.51);
|
||||
|
||||
@@ -483,7 +483,7 @@ void Search::Worker::iterative_deepening() {
|
||||
threads.increaseDepth = true;
|
||||
}
|
||||
|
||||
mainThread->iterValue[iterIdx] = iterBestValue;
|
||||
mainThread->iterValue[iterIdx] = bestValue;
|
||||
iterIdx = (iterIdx + 1) & 3;
|
||||
}
|
||||
|
||||
@@ -580,7 +580,7 @@ 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(pos, *thisThread)
|
||||
return (ss->ply >= MAX_PLY && !ss->inCheck) ? evaluate(pos, thisThread->optimism[us])
|
||||
: value_draw(thisThread->nodes);
|
||||
|
||||
// Step 3. Mate distance pruning. Even if we mate at the next move our score
|
||||
@@ -734,7 +734,7 @@ Value Search::Worker::search(
|
||||
// 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);
|
||||
unadjustedStaticEval = ss->staticEval = eval = evaluate(pos, thisThread->optimism[us]);
|
||||
else if (PvNode)
|
||||
Eval::NNUE::hint_common_parent_position(pos);
|
||||
|
||||
@@ -752,7 +752,7 @@ Value Search::Worker::search(
|
||||
}
|
||||
else
|
||||
{
|
||||
unadjustedStaticEval = ss->staticEval = eval = evaluate(pos, *thisThread);
|
||||
unadjustedStaticEval = ss->staticEval = eval = evaluate(pos, thisThread->optimism[us]);
|
||||
|
||||
Value newEval =
|
||||
ss->staticEval
|
||||
@@ -1470,7 +1470,8 @@ 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(pos, *thisThread) : VALUE_DRAW;
|
||||
return (ss->ply >= MAX_PLY && !ss->inCheck) ? evaluate(pos, thisThread->optimism[us])
|
||||
: VALUE_DRAW;
|
||||
|
||||
assert(0 <= ss->ply && ss->ply < MAX_PLY);
|
||||
|
||||
@@ -1501,7 +1502,8 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta,
|
||||
{
|
||||
// Never assume anything about values stored in TT
|
||||
if ((unadjustedStaticEval = ss->staticEval = bestValue = tte->eval()) == VALUE_NONE)
|
||||
unadjustedStaticEval = ss->staticEval = bestValue = evaluate(pos, *thisThread);
|
||||
unadjustedStaticEval = ss->staticEval = bestValue =
|
||||
evaluate(pos, thisThread->optimism[us]);
|
||||
|
||||
Value newEval =
|
||||
ss->staticEval
|
||||
@@ -1521,7 +1523,7 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta,
|
||||
{
|
||||
// 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)
|
||||
(ss - 1)->currentMove != Move::null() ? evaluate(pos, thisThread->optimism[us])
|
||||
: -(ss - 1)->staticEval;
|
||||
|
||||
Value newEval =
|
||||
|
||||
Reference in New Issue
Block a user