]> git.sesse.net Git - stockfish/commitdiff
Introduce TimeManager class
authorMarco Costalba <mcostalba@gmail.com>
Tue, 3 Aug 2010 09:10:16 +0000 (11:10 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Tue, 3 Aug 2010 10:39:42 +0000 (11:39 +0100)
Firt step in unifying all time management under
a single umbrella. Just introduced the class without
even member data.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/search.cpp
src/timeman.cpp
src/timeman.h

index ad0660d1582dbfce6ef27fc654897fcaf0eb4929..5048381d2bf91c363e386864437ca8fe07cedc44 100644 (file)
@@ -255,6 +255,7 @@ namespace {
   int MaximumSearchTime, ExtraSearchTime, ExactMaxTime;
   bool UseTimeManagement, InfiniteSearch, PonderSearch, StopOnPonderhit;
   bool FirstRootMove, AbortSearch, Quit, AspirationFailLow;
+  TimeManager TimeMgr;
 
   // Log file
   bool UseLogFile;
@@ -473,16 +474,8 @@ bool think(const Position& pos, bool infinite, bool ponder, int time[], int incr
   int myTime = time[pos.side_to_move()];
   int myIncrement = increment[pos.side_to_move()];
   if (UseTimeManagement)
-  {
-      get_search_times(myTime, myIncrement, movesToGo, pos.startpos_ply_counter(),
-                       &OptimumSearchTime, &MaximumSearchTime);
-
-      if (get_option_value_bool("Ponder"))
-      {
-          OptimumSearchTime += OptimumSearchTime / 4;
-          OptimumSearchTime = Min(OptimumSearchTime, MaximumSearchTime);
-      }
-  }
+      TimeMgr.update(myTime, myIncrement, movesToGo, pos.startpos_ply_counter(),
+                     &OptimumSearchTime, &MaximumSearchTime);
 
   // Set best NodesBetweenPolls interval to avoid lagging under
   // heavy time pressure.
index 3798a96f4cd109e869645466726c85b625d65271..fb817e56d5ddfd8f1345b87e36855bb0712f2936 100644 (file)
@@ -25,6 +25,7 @@
 #include <cmath>
 
 #include "misc.h"
+#include "timeman.h"
 #include "ucioption.h"
 
 ////
@@ -87,8 +88,8 @@ namespace {
 //// Functions
 ////
 
-void get_search_times(int myTime, int myInc, int movesToGo, int currentPly,
-                      int* optimumSearchTime, int* maximumSearchTime)
+void TimeManager::update(int myTime, int myInc, int movesToGo, int currentPly,
+                         int* optimumSearchTime, int* maximumSearchTime)
 {
   /* We support four different kind of time controls:
 
@@ -130,6 +131,9 @@ void get_search_times(int myTime, int myInc, int movesToGo, int currentPly,
       *maximumSearchTime = Min(*maximumSearchTime, aTime);
   }
 
+  if (get_option_value_bool("Ponder"))
+      *optimumSearchTime += *optimumSearchTime / 4;
+
   // Make sure that maxSearchTime is not over absoluteMaxSearchTime
   *optimumSearchTime = Min(*optimumSearchTime, *maximumSearchTime);
 }
index 46bc94e157c9fa85b5d48030b31f8dcb8a99b8f2..03dc991dd842828c64219e7b26e8ae1190f3b2a9 100644 (file)
 //// Prototypes
 ////
 
-void get_search_times(int myTime, int myInc, int movesToGo, int currentPly,
-                      int* optimumSearchTime, int* maximumSearchTime);
+class TimeManager {
+public:
+
+  void update(int myTime, int myInc, int movesToGo, int currentPly,
+              int* optimumSearchTime, int* maximumSearchTime);
+};
 
 #endif // !defined(TIMEMAN_H_INCLUDED)