]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Time management simplification
[stockfish] / src / search.cpp
index dc5164ea38a99e85faff9f9e499b85c39f71bf18..763a6ac31194a8ae8b8a6e92bbbf0700894373a7 100644 (file)
@@ -353,6 +353,33 @@ void MainThread::search() {
   std::cout << sync_endl;
 }
 
+const int halfDensityMap[][9] =
+{
+    {2, 0, 1},
+    {2, 1, 0},
+
+    {4, 0, 0, 1, 1},
+    {4, 0, 1, 1, 0},
+    {4, 1, 1, 0, 0},
+    {4, 1, 0, 0, 1},
+
+    {6, 0, 0, 0, 1, 1, 1},
+    {6, 0, 0, 1, 1, 1, 0},
+    {6, 0, 1, 1, 1, 0, 0},
+    {6, 1, 1, 1, 0, 0, 0},
+    {6, 1, 1, 0, 0, 0, 1},
+    {6, 1, 0, 0, 0, 1, 1},
+
+    {8, 0, 0, 0, 0, 1, 1, 1, 1},
+    {8, 0, 0, 0, 1, 1, 1, 1, 0},
+    {8, 0, 0, 1, 1, 1, 1, 0 ,0},
+    {8, 0, 1, 1, 1, 1, 0, 0 ,0},
+    {8, 1, 1, 1, 1, 0, 0, 0 ,0},
+    {8, 1, 1, 1, 0, 0, 0, 0 ,1},
+    {8, 1, 1, 0, 0, 0, 0, 1 ,1},
+    {8, 1, 0, 0, 0, 0, 1, 1 ,1},
+};
+
 
 // Thread::search() is the main iterative deepening loop. It calls search()
 // repeatedly with increasing depth until the allocated thinking time has been
@@ -394,27 +421,12 @@ void Thread::search() {
   while (++rootDepth < DEPTH_MAX && !Signals.stop && (!Limits.depth || rootDepth <= Limits.depth))
   {
       // Set up the new depths for the helper threads skipping on average every
-      // 2nd ply (using a half-density map similar to a Hadamard matrix).
+      // 2nd ply (using a half-density matrix).
       if (!mainThread)
       {
-          int d = rootDepth + rootPos.game_ply();
-
-          if (idx <= 6 || idx > 24)
-          {
-              if (((d + idx) >> (msb(idx + 1) - 1)) % 2)
-                  continue;
-          }
-          else
-          {
-              // Table of values of 6 bits with 3 of them set
-              static const int HalfDensityMap[] = {
-                0x07, 0x0b, 0x0d, 0x0e, 0x13, 0x16, 0x19, 0x1a, 0x1c,
-                0x23, 0x25, 0x26, 0x29, 0x2c, 0x31, 0x32, 0x34, 0x38
-              };
-
-              if ((HalfDensityMap[idx - 7] >> (d % 6)) & 1)
-                  continue;
-          }
+          int row = (idx - 1) % 20;
+          if (halfDensityMap[row][(rootDepth + rootPos.game_ply()) % halfDensityMap[row][0] + 1])
+             continue;
       }
 
       // Age out PV variability metric
@@ -532,10 +544,6 @@ void Thread::search() {
       {
           if (!Signals.stop && !Signals.stopOnPonderhit)
           {
-              // Take some extra time if the best move has changed
-              if (rootDepth > 4 * ONE_PLY && multiPV == 1)
-                  Time.pv_instability(mainThread->bestMoveChanges);
-
               // Stop the search if only one legal move is available, or if all
               // of the available time has been used, or if we matched an easyMove
               // from the previous search and just did a fast verification.
@@ -543,13 +551,14 @@ void Thread::search() {
                                  bestValue >= mainThread->previousScore };
 
               int improvingFactor = 640 - 160*F[0] - 126*F[1] - 124*F[0]*F[1];
+              double unstablePvFactor = 1 + mainThread->bestMoveChanges;
 
               bool doEasyMove =   rootMoves[0].pv[0] == easyMove
                                && mainThread->bestMoveChanges < 0.03
-                               && Time.elapsed() > Time.available() * 25 / 206;
+                               && Time.elapsed() > Time.optimum() * 25 / 204;
 
               if (   rootMoves.size() == 1
-                  || Time.elapsed() > Time.available() * improvingFactor / 640
+                  || Time.elapsed() > Time.optimum() * unstablePvFactor * improvingFactor / 634
                   || (mainThread->easyMovePlayed = doEasyMove))
               {
                   // If we are allowed to ponder do not stop the search now but