@@ -82,12 +82,12 @@ void TimeManagement::init(Search::LimitsType& limits,
8282 limits.npmsec = npmsec;
8383 }
8484
85- // Maximum move horizon of 50 moves
85+ // Maximum and default move horizon of 50 moves
8686 int mtg = limits.movestogo ? std::min (limits.movestogo , 50 ) : 50 ;
8787
88- // Make sure timeLeft is > 0 since we may use it as a divisor
89- TimePoint timeLeft = std::max ( TimePoint ( 1 ), limits. time [us] + limits. inc [us] * (mtg - 1 )
90- - moveOverhead * ( 2 + mtg) );
88+ // Make sure timeLeft is > 0 since we use it as a divisor
89+ double timeLeft =
90+ std::max (limits. time [us], limits. time [us] + limits. inc [us] * (mtg - 1 ) - moveOverhead * mtg);
9191
9292 // Use extra time with larger increments
9393 double optExtra = std::clamp (1.0 + 12.5 * limits.inc [us] / limits.time [us], 1.0 , 1.11 );
@@ -97,20 +97,20 @@ void TimeManagement::init(Search::LimitsType& limits,
9797 double maxConstant = std::max (3.4 + 3.0 * std::log10 (limits.time [us] / 1000.0 ), 2.76 );
9898
9999 // x basetime (+ z increment)
100- // If there is a healthy increment, timeLeft can exceed actual available
100+ // If there is a healthy increment and low mtg , timeLeft can exceed actual available
101101 // game time for the current move, so also cap to 20% of available game time.
102102 if (limits.movestogo == 0 )
103103 {
104104 optScale = std::min (0.0120 + std::pow (ply + 3.1 , 0.44 ) * optConstant,
105- 0.21 * limits.time [us] / double ( timeLeft) )
105+ 0.21 * limits.time [us] / timeLeft)
106106 * optExtra;
107107 maxScale = std::min (6.9 , maxConstant + ply / 12.2 );
108108 }
109109
110110 // x moves in y seconds (+ z increment)
111111 else
112112 {
113- optScale = std::min ((0.88 + ply / 116.4 ) / mtg, 0.88 * limits.time [us] / double ( timeLeft) );
113+ optScale = std::min ((0.88 + ply / 116.4 ) / mtg, 0.88 * limits.time [us] / timeLeft);
114114 maxScale = std::min (6.3 , 1.5 + 0.11 * mtg);
115115 }
116116
0 commit comments