]> git.sesse.net Git - stockfish/commitdiff
Do no initialize TM in all cases
authorMaxim Masiutin <maxim@masiutin.com>
Sat, 1 Apr 2023 20:49:03 +0000 (23:49 +0300)
committerJoost VandeVondele <Joost.VandeVondele@gmail.com>
Mon, 10 Apr 2023 08:56:42 +0000 (10:56 +0200)
Avoid doing full TM initialization if it won't be used, avoids division by zero.

closes https://github.com/official-stockfish/Stockfish/pull/4484

No functional change

src/timeman.cpp

index 5c826b4f0c5547a61e1b936b1c57ed1e5fde8990..061de0182f7d75e698d73664b9bf3a25dd603e4b 100644 (file)
@@ -36,6 +36,12 @@ TimeManagement Time; // Our global time management object
 
 void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) {
 
+  // if we have no time, no need to initialize TM, except for the start time,
+  // which is used by movetime.
+  startTime = limits.startTime;
+  if (limits.time[us] == 0)
+      return;
+
   TimePoint moveOverhead    = TimePoint(Options["Move Overhead"]);
   TimePoint slowMover       = TimePoint(Options["Slow Mover"]);
   TimePoint npmsec          = TimePoint(Options["nodestime"]);
@@ -59,8 +65,6 @@ void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) {
       limits.npmsec = npmsec;
   }
 
-  startTime = limits.startTime;
-
   // Maximum move horizon of 50 moves
   int mtg = limits.movestogo ? std::min(limits.movestogo, 50) : 50;