diff --git a/src/benchmark.cpp b/src/benchmark.cpp index c683a381..8f3e6ae1 100644 --- a/src/benchmark.cpp +++ b/src/benchmark.cpp @@ -156,6 +156,7 @@ void benchmark(const Position& current, istream& is) { else { Search::StateStackPtr st; + limits.startTime = now(); Threads.start_thinking(pos, limits, st); Threads.main()->join(); nodes += Threads.nodes_searched(); diff --git a/src/search.cpp b/src/search.cpp index 344a0093..207616ef 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -226,7 +226,7 @@ template uint64_t Search::perft(Position& pos, Depth depth); void MainThread::think() { Color us = pos.side_to_move(); - Time.init(Limits, us, pos.game_ply(), now()); + Time.init(Limits, us, pos.game_ply()); int contempt = Options["Contempt"] * PawnValueEg / 100; // From centipawns DrawValue[ us] = VALUE_DRAW - Value(contempt); diff --git a/src/search.h b/src/search.h index 81f7179c..c7abb9dc 100644 --- a/src/search.h +++ b/src/search.h @@ -88,6 +88,7 @@ struct LimitsType { std::vector searchmoves; int time[COLOR_NB], inc[COLOR_NB], npmsec, movestogo, depth, movetime, mate, infinite, ponder; int64_t nodes; + TimePoint startTime; }; /// The SignalsType struct stores volatile flags updated during the search diff --git a/src/timeman.cpp b/src/timeman.cpp index 7a5db255..3a4e157f 100644 --- a/src/timeman.cpp +++ b/src/timeman.cpp @@ -80,7 +80,7 @@ namespace { /// inc > 0 && movestogo == 0 means: x basetime + z increment /// inc > 0 && movestogo != 0 means: x moves in y minutes + z increment -void TimeManagement::init(Search::LimitsType& limits, Color us, int ply, TimePoint now) +void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) { int minThinkingTime = Options["Minimum Thinking Time"]; int moveOverhead = Options["Move Overhead"]; @@ -102,7 +102,7 @@ void TimeManagement::init(Search::LimitsType& limits, Color us, int ply, TimePoi limits.npmsec = npmsec; } - start = now; + startTime = limits.startTime; unstablePvFactor = 1; optimumTime = maximumTime = std::max(limits.time[us], minThinkingTime); diff --git a/src/timeman.h b/src/timeman.h index 24632d79..b6eb3485 100644 --- a/src/timeman.h +++ b/src/timeman.h @@ -29,16 +29,16 @@ class TimeManagement { public: - void init(Search::LimitsType& limits, Color us, int ply, TimePoint now); + void init(Search::LimitsType& limits, Color us, int ply); void pv_instability(double bestMoveChanges) { unstablePvFactor = 1 + bestMoveChanges; } int available() const { return int(optimumTime * unstablePvFactor * 0.76); } int maximum() const { return maximumTime; } - int elapsed() const { return int(Search::Limits.npmsec ? Threads.nodes_searched() : now() - start); } + int elapsed() const { return int(Search::Limits.npmsec ? Threads.nodes_searched() : now() - startTime); } int64_t availableNodes; // When in 'nodes as time' mode private: - TimePoint start; + TimePoint startTime; int optimumTime; int maximumTime; double unstablePvFactor; diff --git a/src/uci.cpp b/src/uci.cpp index 4e56542a..c5dbafae 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -112,6 +112,8 @@ namespace { Search::LimitsType limits; string token; + limits.startTime = now(); // As early as possible! + while (is >> token) if (token == "searchmoves") while (is >> token)