]> git.sesse.net Git - stockfish/commitdiff
Improve time managment
authorMarco Costalba <mcostalba@gmail.com>
Thu, 18 Sep 2008 09:32:12 +0000 (10:32 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Thu, 18 Sep 2008 10:27:09 +0000 (12:27 +0200)
If we need some more and we are in time
advantage take it.

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

index 4c6c0da67253e335e014fc17c1ddbe77e07a57d7..7e2628b1ea77e7d82b38547bd8cdb8d0d64e751c 100644 (file)
@@ -123,7 +123,8 @@ void benchmark(const std::string& commandLine) {
   for (it = positions.begin(); it != positions.end(); ++it)\r
   {
       Move moves[1] = {MOVE_NONE};\r
   for (it = positions.begin(); it != positions.end(); ++it)\r
   {
       Move moves[1] = {MOVE_NONE};\r
+      int dummy[2] = {0, 0};\r
       Position pos(*it);      
       Position pos(*it);      
-      think(pos, true, false, 0, 0, 0, 0, 0, 0, secsPerPos * 1000, moves);\r
+      think(pos, true, false, 0, dummy, dummy, 0, 0, 0, secsPerPos * 1000, moves);\r
   }
 }
   }
 }
index 5599faab242a6164d0d23b0ec8334a173689518b..c05bbd4c54d12a790ab38bc1f9be8a7a4bf34662 100644 (file)
@@ -181,7 +181,7 @@ namespace {
   // Time managment variables
   int SearchStartTime;
   int MaxNodes, MaxDepth;
   // Time managment variables
   int SearchStartTime;
   int MaxNodes, MaxDepth;
-  int MaxSearchTime, AbsoluteMaxSearchTime, ExtraSearchTime;
+  int MaxSearchTime, AbsoluteMaxSearchTime, ExtraSearchTime, TimeAdvantage;
   Move BestRootMove, PonderMove, EasyMove;
   int RootMoveNumber;
   bool InfiniteSearch;
   Move BestRootMove, PonderMove, EasyMove;
   int RootMoveNumber;
   bool InfiniteSearch;
@@ -407,14 +407,6 @@ void think(const Position &pos, bool infinite, bool ponder, int side_to_move,
     init_eval(ActiveThreads);
   }
 
     init_eval(ActiveThreads);
   }
 
-  // Write information to search log file:
-  if(UseLogFile) {
-    LogFile << "Searching: " << pos.to_fen() << '\n';
-    LogFile << "infinite: " << infinite << " ponder: " << ponder
-            << " time: " << time << " increment: " << increment
-            << " moves to go: " << movesToGo << '\n';
-  }
-
   // Wake up sleeping threads:
   wake_sleeping_threads();
 
   // Wake up sleeping threads:
   wake_sleeping_threads();
 
@@ -425,7 +417,8 @@ void think(const Position &pos, bool infinite, bool ponder, int side_to_move,
   int myTime = time[side_to_move];
   int myIncrement = increment[side_to_move];
   int oppTime = time[1 - side_to_move];
   int myTime = time[side_to_move];
   int myIncrement = increment[side_to_move];
   int oppTime = time[1 - side_to_move];
-  int oppIncrement = increment[1 - side_to_move];
+  
+  TimeAdvantage = myTime - oppTime;
 
   if(!movesToGo) { // Sudden death time control
     if(increment) {
 
   if(!movesToGo) { // Sudden death time control
     if(increment) {
@@ -465,6 +458,15 @@ void think(const Position &pos, bool infinite, bool ponder, int side_to_move,
   else
     NodesBetweenPolls = 30000;
 
   else
     NodesBetweenPolls = 30000;
 
+
+  // Write information to search log file:
+  if(UseLogFile) {
+    LogFile << "Searching: " << pos.to_fen() << '\n';
+    LogFile << "infinite: " << infinite << " ponder: " << ponder
+            << " time: " << myTime << " increment: " << myIncrement
+            << " moves to go: " << movesToGo << '\n';
+  }
+
   // We're ready to start thinking.  Call the iterative deepening loop
   // function:
   id_loop(pos, searchMoves);
   // We're ready to start thinking.  Call the iterative deepening loop
   // function:
   id_loop(pos, searchMoves);
@@ -640,6 +642,10 @@ namespace {
             BestMoveChangesByIteration[Iteration] * (MaxSearchTime / 2) +
             BestMoveChangesByIteration[Iteration-1] * (MaxSearchTime / 3);
 
             BestMoveChangesByIteration[Iteration] * (MaxSearchTime / 2) +
             BestMoveChangesByIteration[Iteration-1] * (MaxSearchTime / 3);
 
+        // If we need some more and we are in time advantage take it.
+        if (ExtraSearchTime > 0 && TimeAdvantage > 2 * MaxSearchTime)
+            ExtraSearchTime += MaxSearchTime / 2;
+
         // Stop search if most of MaxSearchTime is consumed at the end of the
         // iteration.  We probably don't have enough time to search the first
         // move at the next iteration anyway.
         // Stop search if most of MaxSearchTime is consumed at the end of the
         // iteration.  We probably don't have enough time to search the first
         // move at the next iteration anyway.
index 1a2c05a40fccbc007b0f384f5ba2af3610d122dc..6862a5e84dc6cac3ef7f2efaefc8681929128f56 100644 (file)
@@ -134,7 +134,6 @@ namespace {
         TT.clear();
         Position::init_piece_square_tables();
         RootPosition.from_fen(StartPosition);
         TT.clear();
         Position::init_piece_square_tables();
         RootPosition.from_fen(StartPosition);
-
     }
     else if (token == "isready")
         std::cout << "readyok" << std::endl;
     }
     else if (token == "isready")
         std::cout << "readyok" << std::endl;