mirror of
https://github.com/official-stockfish/Stockfish.git
synced 2026-07-23 05:07:14 +00:00
[refactor] Add helper functions and simplify thread selection
I found these changes useful and natural when working on a patch to improve mate reporting. I can revert some of the changes if maintainers would prefer that. E.g. I am not sure whether `unset_bound_flags()` is worth defining. closes https://github.com/official-stockfish/Stockfish/pull/6785 No functional change
This commit is contained in:
committed by
Joost VandeVondele
parent
6127bf711e
commit
fcbd160d26
+10
-12
@@ -441,8 +441,8 @@ bool Search::Worker::iterative_deepening() {
|
||||
&& rootMoves[pvIdx].previousScore < rootMoves[pvIdx - 1].score)
|
||||
? rootMoves[pvIdx].previousScore
|
||||
: rootMoves[pvIdx - 1].score;
|
||||
rootMoves[pvIdx].previousScore = -VALUE_INFINITE;
|
||||
rootMoves[pvIdx].scoreLowerbound = rootMoves[pvIdx].scoreUpperbound = false;
|
||||
rootMoves[pvIdx].previousScore = -VALUE_INFINITE;
|
||||
rootMoves[pvIdx].unset_bound_flags();
|
||||
rootMoves[pvIdx].pv.resize(1);
|
||||
}
|
||||
|
||||
@@ -471,7 +471,7 @@ bool Search::Worker::iterative_deepening() {
|
||||
// loss could be delayed or refuted upon exploring the remaining root-moves.
|
||||
// Thus here we roll back to the score from the previous iteration.
|
||||
else if (!pvIdx && rootMoves[0].score != -VALUE_INFINITE && is_loss(rootMoves[0].score)
|
||||
&& !rootMoves[0].scoreLowerbound && !rootMoves[0].scoreUpperbound)
|
||||
&& !rootMoves[0].score_is_bound())
|
||||
{
|
||||
// Bring the last best move to the front for best thread selection.
|
||||
if (!lastIterationPV.empty())
|
||||
@@ -491,9 +491,8 @@ bool Search::Worker::iterative_deepening() {
|
||||
|
||||
// Have we found a "mate in x" after a completed iteration?
|
||||
if (limits.mate && !threads.stop
|
||||
&& ((rootMoves[0].score >= VALUE_MATE_IN_MAX_PLY
|
||||
&& VALUE_MATE - rootMoves[0].score <= 2 * limits.mate)
|
||||
|| (rootMoves[0].score <= VALUE_MATED_IN_MAX_PLY
|
||||
&& ((is_mate(rootMoves[0].score) && VALUE_MATE - rootMoves[0].score <= 2 * limits.mate)
|
||||
|| (is_mated(rootMoves[0].score)
|
||||
&& VALUE_MATE + rootMoves[0].score <= 2 * limits.mate)))
|
||||
threads.stop = true;
|
||||
|
||||
@@ -1357,7 +1356,7 @@ moves_loop: // When in check, search starts here
|
||||
{
|
||||
rm.score = rm.uciScore = value;
|
||||
rm.selDepth = selDepth;
|
||||
rm.scoreLowerbound = rm.scoreUpperbound = false;
|
||||
rm.unset_bound_flags();
|
||||
|
||||
if (value >= beta)
|
||||
{
|
||||
@@ -1810,7 +1809,7 @@ Value value_from_tt(Value v, int ply, int r50c) {
|
||||
if (is_win(v))
|
||||
{
|
||||
// Downgrade a potentially false mate score
|
||||
if (v >= VALUE_MATE_IN_MAX_PLY && VALUE_MATE - v > 100 - r50c)
|
||||
if (is_mate(v) && VALUE_MATE - v > 100 - r50c)
|
||||
return VALUE_TB_WIN_IN_MAX_PLY - 1;
|
||||
|
||||
// Downgrade a potentially false TB score.
|
||||
@@ -1824,7 +1823,7 @@ Value value_from_tt(Value v, int ply, int r50c) {
|
||||
if (is_loss(v))
|
||||
{
|
||||
// Downgrade a potentially false mate score.
|
||||
if (v <= VALUE_MATED_IN_MAX_PLY && VALUE_MATE + v > 100 - r50c)
|
||||
if (is_mated(v) && VALUE_MATE + v > 100 - r50c)
|
||||
return VALUE_TB_LOSS_IN_MAX_PLY + 1;
|
||||
|
||||
// Downgrade a potentially false TB score.
|
||||
@@ -2158,13 +2157,12 @@ void SearchManager::pv(Search::Worker& worker,
|
||||
if (v == -VALUE_INFINITE)
|
||||
v = VALUE_ZERO;
|
||||
|
||||
bool isTBScore = worker.tbConfig.rootInTB && std::abs(v) <= VALUE_TB;
|
||||
bool isTBScore = worker.tbConfig.rootInTB && !is_mate_or_mated(v);
|
||||
v = isTBScore ? rootMoves[i].tbScore : v;
|
||||
|
||||
// Potentially correct and extend the PV, and in exceptional cases v.
|
||||
// Bound flags indicate an unreliable PV, also when we usePreviousScore.
|
||||
if (is_decisive(v) && std::abs(v) < VALUE_MATE_IN_MAX_PLY
|
||||
&& ((!rootMoves[i].scoreLowerbound && !rootMoves[i].scoreUpperbound) || isTBScore))
|
||||
if (is_decisive(v) && !is_mate_or_mated(v) && (!rootMoves[i].score_is_bound() || isTBScore))
|
||||
syzygy_extend_pv(worker.options, worker.limits, pos, rootMoves[i], v);
|
||||
|
||||
std::string pv;
|
||||
|
||||
Reference in New Issue
Block a user