]> git.sesse.net Git - stockfish/blobdiff - src/timeman.cpp
Bonus for reachable outpost
[stockfish] / src / timeman.cpp
index 46ef75f4221335de0b7d2e0ebd9c66c651ec3f24..3a4e157f8b145f1ba43de49b58c7b6db4093f643 100644 (file)
@@ -25,6 +25,8 @@
 #include "timeman.h"
 #include "uci.h"
 
+TimeManagement Time; // Our global time management object
+
 namespace {
 
   enum TimeType { OptimumTime, MaxTime };
@@ -78,13 +80,29 @@ namespace {
 ///  inc >  0 && movestogo == 0 means: x basetime + z increment
 ///  inc >  0 && movestogo != 0 means: x moves in y minutes + z increment
 
-void TimeManager::init(const 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"];
   int slowMover       = Options["Slow Mover"];
+  int npmsec          = Options["nodestime"];
+
+  // If we have to play in 'nodes as time' mode, then convert from time
+  // to nodes, and use resulting values in time management formulas.
+  // WARNING: Given npms (nodes per millisecond) must be much lower then
+  // real engine speed to avoid time losses.
+  if (npmsec)
+  {
+      if (!availableNodes) // Only once at game start
+          availableNodes = npmsec * limits.time[us]; // Time is in msec
+
+      // Convert from millisecs to nodes
+      limits.time[us] = (int)availableNodes;
+      limits.inc[us] *= npmsec;
+      limits.npmsec = npmsec;
+  }
 
-  start = now;
+  startTime = limits.startTime;
   unstablePvFactor = 1;
   optimumTime = maximumTime = std::max(limits.time[us], minThinkingTime);