- double ratio; // Which ratio of myTime we are going to use
-
- // Usage of increment follows quadratic distribution with the maximum at move 25
- double inc = myInc * std::max(55.0, 120 - 0.12 * (moveNum - 25) * (moveNum - 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 (moveNum <= 40)
- ratio *= 1.1 - 0.001 * (moveNum - 20) * (moveNum - 20);
- else
- ratio *= 1.5;
-
- if (movesToGo > 1)
- ratio = std::min(0.75, ratio);
-
- ratio *= 1 + inc / (myTime * 8.5);
- }
- // Otherwise we increase usage of remaining time as the game goes on
- else
- {
- double k = 1 + 20 * moveNum / (500.0 + moveNum);
- ratio = (type == OptimumTime ? 0.017 : 0.07) * (k + inc / myTime);
- }
-
- int time = int(std::min(1.0, ratio) * std::max(0, myTime - moveOverhead));
-
- if (type == OptimumTime && ponder)
- time = 5 * time / 4;
-
- return 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"];