- int moveNumber = (ply + 1) / 2;
- double ratio; // Which ratio of myTime we are going to use. It is <= 1
- double sd = 8.5;
-
- // Usage of increment follows quadratic distribution with the maximum at move 25
- double inc = myInc * std::max(55.0, 120.0 - 0.12 * (moveNumber - 25) * (moveNumber - 25));
-
- // In moves-to-go we distribute time according to a quadratic function with
- // the maximum around move 20 for 40 moves in y time case.
- if (movesToGo)
- {
- ratio = (type == OptimumTime ? 1.0 : 6.0) / std::min(50, movesToGo);
-
- if (moveNumber <= 40)
- ratio *= 1.1 - 0.001 * (moveNumber - 20) * (moveNumber - 20);
- else
- ratio *= 1.5;
- }
- // Otherwise we increase usage of remaining time as the game goes on
- else
- {
- sd = 1 + 20 * moveNumber / (500.0 + moveNumber);
- ratio = (type == OptimumTime ? 0.017 : 0.07) * sd;
- }
-
- ratio = std::min(1.0, ratio * (1 + inc / (myTime * sd)));
-
- return int(ratio * std::max(0, myTime - moveOverhead));
- }
-
-} // 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"];