mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-22 10:06:26 +08:00
Fix nodestime
1. The current time management system utilizes limits.inc and limits.time, which can represent either milliseconds or node count, depending on whether the nodestime option is active. There have been several modifications which brought Elo gain for typical uses (i.e. real-time matches), however some of these changes overlooked such distinction. This patch adjusts constants and multiplication/division to more accurately simulate real TC conditions when nodestime is used. 2. The advance_nodes_time function has a bug that can extend the time limit when availableNodes reaches exact zero. This patch fixes the bug by initializing the variable to -1 and make sure it does not go below zero. 3. elapsed_time function is newly introduced to print PV in the UCI output based on real time. This makes PV output more consistent with the behavior of trivial use cases. closes https://github.com/official-stockfish/Stockfish/pull/5186 No functional changes
This commit is contained in:
committed by
Joost VandeVondele
parent
db147fe258
commit
2dbb44e28d
@@ -190,8 +190,8 @@ void Search::Worker::start_searching() {
|
||||
// When playing in 'nodes as time' mode, subtract the searched nodes from
|
||||
// the available ones before exiting.
|
||||
if (limits.npmsec)
|
||||
main_manager()->tm.advance_nodes_time(limits.inc[rootPos.side_to_move()]
|
||||
- threads.nodes_searched());
|
||||
main_manager()->tm.advance_nodes_time(threads.nodes_searched()
|
||||
- limits.inc[rootPos.side_to_move()]);
|
||||
|
||||
Worker* bestThread = this;
|
||||
Skill skill =
|
||||
@@ -347,7 +347,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 && (bestValue <= alpha || bestValue >= beta)
|
||||
&& elapsed() > 3000)
|
||||
&& elapsed_time() > 3000)
|
||||
main_manager()->pv(*this, threads, tt, rootDepth);
|
||||
|
||||
// In case of failing low/high increase aspiration window and
|
||||
@@ -378,7 +378,7 @@ void Search::Worker::iterative_deepening() {
|
||||
std::stable_sort(rootMoves.begin() + pvFirst, rootMoves.begin() + pvIdx + 1);
|
||||
|
||||
if (mainThread
|
||||
&& (threads.stop || pvIdx + 1 == multiPV || elapsed() > 3000)
|
||||
&& (threads.stop || pvIdx + 1 == multiPV || elapsed_time() > 3000)
|
||||
// A thread that aborted search can have mated-in/TB-loss PV and score
|
||||
// that cannot be trusted, i.e. it can be delayed or refuted if we would have
|
||||
// had time to fully search other root-moves. Thus we suppress this output and
|
||||
@@ -935,7 +935,7 @@ moves_loop: // When in check, search starts here
|
||||
|
||||
ss->moveCount = ++moveCount;
|
||||
|
||||
if (rootNode && is_mainthread() && elapsed() > 3000)
|
||||
if (rootNode && is_mainthread() && elapsed_time() > 3000)
|
||||
{
|
||||
main_manager()->updates.onIter(
|
||||
{depth, UCIEngine::move(move, pos.is_chess960()), moveCount + thisThread->pvIdx});
|
||||
@@ -1647,10 +1647,20 @@ Depth Search::Worker::reduction(bool i, Depth d, int mn, int delta) {
|
||||
return (reductionScale + 1318 - delta * 760 / rootDelta) / 1024 + (!i && reductionScale > 1066);
|
||||
}
|
||||
|
||||
// elapsed() returns the time elapsed since the search started. If the
|
||||
// 'nodestime' option is enabled, it will return the count of nodes searched
|
||||
// instead. This function is called to check whether the search should be
|
||||
// stopped based on predefined thresholds like time limits or nodes searched.
|
||||
//
|
||||
// elapsed_time() returns the actual time elapsed since the start of the search.
|
||||
// This function is intended for use only when printing PV outputs, and not used
|
||||
// for making decisions within the search algorithm itself.
|
||||
TimePoint Search::Worker::elapsed() const {
|
||||
return main_manager()->tm.elapsed([this]() { return threads.nodes_searched(); });
|
||||
}
|
||||
|
||||
TimePoint Search::Worker::elapsed_time() const { return main_manager()->tm.elapsed_time(); }
|
||||
|
||||
|
||||
namespace {
|
||||
// Adjusts a mate or TB score from "plies to mate from the root"
|
||||
@@ -1900,7 +1910,7 @@ void SearchManager::pv(const Search::Worker& worker,
|
||||
const auto& rootMoves = worker.rootMoves;
|
||||
const auto& pos = worker.rootPos;
|
||||
size_t pvIdx = worker.pvIdx;
|
||||
TimePoint time = tm.elapsed([nodes]() { return nodes; }) + 1;
|
||||
TimePoint time = tm.elapsed_time() + 1;
|
||||
size_t multiPV = std::min(size_t(worker.options["MultiPV"]), rootMoves.size());
|
||||
uint64_t tbHits = threads.tb_hits() + (worker.tbConfig.rootInTB ? rootMoves.size() : 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user