- int time = int(std::min(1.0, ratio) * std::max(0, myTime - moveOverhead));
-
- if (type == OptimumTime && ponder)
- time *= 1.25;
-
- if (type == MaxTime)
- time -= 10; // Keep always at least 10 millisecs on the clock
-
- return std::max(0, time);
- }
-
-} // namespace
-
-
-/// init() is called at the beginning of the search and calculates the allowed
-/// thinking time out of the time control and current game ply. We support four
-/// different kinds of time controls, passed in 'limits':
-///
-/// inc == 0 && movestogo == 0 means: x basetime [sudden death!]
-/// inc == 0 && movestogo != 0 means: x moves in y minutes
-/// 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)
-{
- int moveOverhead = Options["Move Overhead"];
- int npmsec = Options["nodestime"];
- bool ponder = Options["Ponder"];
-
- // 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
- // the 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;
- }
-
- int moveNum = (ply + 1) / 2;
-
- startTime = limits.startTime;
- optimumTime = remaining(limits.time[us], limits.inc[us], moveOverhead,
- limits.movestogo, moveNum, ponder, OptimumTime);
- maximumTime = remaining(limits.time[us], limits.inc[us], moveOverhead,
- limits.movestogo, moveNum, ponder, MaxTime);