]> git.sesse.net Git - stockfish/commitdiff
Reshuffle in timeman.cpp
authorMarco Costalba <mcostalba@gmail.com>
Sat, 12 Apr 2014 10:00:37 +0000 (12:00 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 12 Apr 2014 10:00:37 +0000 (12:00 +0200)
Move template definitions before call site.

No functional change.

src/timeman.cpp
src/timeman.h

index 051d9726aa9ae29cb6398d00d79db23b090653bc..2092b7299ed1c3b78ac9b53178bf5e61e7672d8d 100644 (file)
@@ -27,7 +27,7 @@
 
 namespace {
 
-  /// Constants
+  enum TimeType { OptimumTime, MaxTime };
 
   const int MoveHorizon   = 50;   // Plan time management at most this many moves ahead
   const double MaxRatio   = 7.0;  // When in trouble, we can step over reserved time with this ratio
@@ -38,30 +38,35 @@ namespace {
   const double skewfactor = 0.172;
 
 
-  /// move_importance() is a skew-logistic function based on naive statistical
-  /// analysis of "how many games are still undecided after n half-moves". Game
-  /// is considered "undecided" as long as neither side has >275cp advantage.
-  /// Data was extracted from CCRL game database with some simple filtering criteria.
+  // move_importance() is a skew-logistic function based on naive statistical
+  // analysis of "how many games are still undecided after n half-moves". Game
+  // is considered "undecided" as long as neither side has >275cp advantage.
+  // Data was extracted from CCRL game database with some simple filtering criteria.
 
   double move_importance(int ply) {
 
     return pow((1 + exp((ply - xshift) / xscale)), -skewfactor) + DBL_MIN; // Ensure non-zero
   }
 
+  template<TimeType T>
+  int remaining(int myTime, int movesToGo, int currentPly, int slowMover)
+  {
+    const double TMaxRatio   = (T == OptimumTime ? 1 : MaxRatio);
+    const double TStealRatio = (T == OptimumTime ? 0 : StealRatio);
 
-  /// Function Prototypes
-
-  enum TimeType { OptimumTime, MaxTime };
+    double thisMoveImportance = (move_importance(currentPly) * slowMover) / 100;
+    double otherMovesImportance = 0;
 
-  template<TimeType>
-  int remaining(int myTime, int movesToGo, int fullMoveNumber, int slowMover);
-}
+    for (int i = 1; i < movesToGo; ++i)
+        otherMovesImportance += move_importance(currentPly + 2 * i);
 
+    double ratio1 = (TMaxRatio * thisMoveImportance) / (TMaxRatio * thisMoveImportance + otherMovesImportance);
+    double ratio2 = (thisMoveImportance + TStealRatio * otherMovesImportance) / (thisMoveImportance + otherMovesImportance);
 
-void TimeManager::pv_instability(double bestMoveChanges) {
+    return int(floor(myTime * std::min(ratio1, ratio2)));
+  }
 
-  unstablePvFactor = 1 + bestMoveChanges;
-}
+} // namespace
 
 
 void TimeManager::init(const Search::LimitsType& limits, int currentPly, Color us)
@@ -119,25 +124,3 @@ void TimeManager::init(const Search::LimitsType& limits, int currentPly, Color u
   // Make sure that maxSearchTime is not over absoluteMaxSearchTime
   optimumSearchTime = std::min(optimumSearchTime, maximumSearchTime);
 }
-
-
-namespace {
-
-  template<TimeType T>
-  int remaining(int myTime, int movesToGo, int currentPly, int slowMover)
-  {
-    const double TMaxRatio   = (T == OptimumTime ? 1 : MaxRatio);
-    const double TStealRatio = (T == OptimumTime ? 0 : StealRatio);
-
-    double thisMoveImportance = (move_importance(currentPly) * slowMover) / 100;
-    double otherMovesImportance = 0;
-
-    for (int i = 1; i < movesToGo; ++i)
-        otherMovesImportance += move_importance(currentPly + 2 * i);
-
-    double ratio1 = (TMaxRatio * thisMoveImportance) / (TMaxRatio * thisMoveImportance + otherMovesImportance);
-    double ratio2 = (thisMoveImportance + TStealRatio * otherMovesImportance) / (thisMoveImportance + otherMovesImportance);
-
-    return int(floor(myTime * std::min(ratio1, ratio2)));
-  }
-}
index 90bd18679d5af6f42fd7abfe3c6a523c6817832b..a15551af567461a43e55d202122f936513be8a8d 100644 (file)
@@ -26,7 +26,7 @@
 class TimeManager {
 public:
   void init(const Search::LimitsType& limits, int currentPly, Color us);
-  void pv_instability(double bestMoveChanges);
+  void pv_instability(double bestMoveChanges) { unstablePvFactor = 1 + bestMoveChanges; }
   int available_time() const { return int(optimumSearchTime * unstablePvFactor * 0.71); }
   int maximum_time() const { return maximumSearchTime; }