]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Rewrite time formula
[stockfish] / src / search.cpp
index a5203b2e4802c1e77b2aa6ed11c1a528741cc202..a4bf172a99e7442f50109bc8d9b82dfa51c063b0 100644 (file)
@@ -188,7 +188,7 @@ void Search::clear() {
       th->counterMoves.clear();
   }
 
       th->counterMoves.clear();
   }
 
-  Threads.main()->previousMoveScore = VALUE_INFINITE;
+  Threads.main()->previousScore = VALUE_INFINITE;
 }
 
 
 }
 
 
@@ -338,7 +338,7 @@ void MainThread::search() {
               bestThread = th;
   }
 
               bestThread = th;
   }
 
-  previousMoveScore = bestThread->rootMoves[0].score;
+  previousScore = bestThread->rootMoves[0].score;
 
   // Send new PV when needed
   if (bestThread != this)
 
   // Send new PV when needed
   if (bestThread != this)
@@ -538,13 +538,18 @@ void Thread::search() {
               // 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.
               // 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.
+              const bool F[] = { !mainThread->failedLow,
+                                 bestValue >= mainThread->previousScore };
+
+              int improvingFactor = 640 - 160*F[0] - 126*F[1] - 124*F[0]*F[1];
+
+              bool doEasyMove =   rootMoves[0].pv[0] == easyMove
+                               && mainThread->bestMoveChanges < 0.03
+                               && Time.elapsed() > Time.available() * 25 / 206;
+
               if (   rootMoves.size() == 1
               if (   rootMoves.size() == 1
-                  || Time.elapsed() > Time.available() * ( 640  - 160 * !mainThread->failedLow
-                     - 126 * (bestValue >= mainThread->previousMoveScore)
-                     - 124 * (bestValue >= mainThread->previousMoveScore && !mainThread->failedLow))/640
-                  || ( mainThread->easyMovePlayed = ( rootMoves[0].pv[0] == easyMove
-                                                     && mainThread->bestMoveChanges < 0.03
-                                                     && Time.elapsed() > Time.available() * 25/206)))
+                  || Time.elapsed() > Time.available() * improvingFactor / 640
+                  || (mainThread->easyMovePlayed = doEasyMove))
               {
                   // If we are allowed to ponder do not stop the search now but
                   // keep pondering until the GUI sends "ponderhit" or "stop".
               {
                   // If we are allowed to ponder do not stop the search now but
                   // keep pondering until the GUI sends "ponderhit" or "stop".
@@ -999,11 +1004,10 @@ moves_loop: // When in check search starts from here
                   && cmh[pos.piece_on(to_sq(move))][to_sq(move)] <= VALUE_ZERO))
               r += ONE_PLY;
 
                   && cmh[pos.piece_on(to_sq(move))][to_sq(move)] <= VALUE_ZERO))
               r += ONE_PLY;
 
-          // Decrease reduction for moves with a good history and
-          // increase reduction for moves with a bad history
-          int rDecrease = (  thisThread->history[pos.piece_on(to_sq(move))][to_sq(move)]
-                           + cmh[pos.piece_on(to_sq(move))][to_sq(move)]) / 14980;
-          r = std::max(DEPTH_ZERO, r - rDecrease * ONE_PLY);
+          // Decrease/increase reduction for moves with a good/bad history
+          int rHist = (  thisThread->history[pos.piece_on(to_sq(move))][to_sq(move)]
+                       + cmh[pos.piece_on(to_sq(move))][to_sq(move)]) / 14980;
+          r = std::max(DEPTH_ZERO, r - rHist * ONE_PLY);
 
           // Decrease reduction for moves that escape a capture. Filter out
           // castling moves, because they are coded as "king captures rook" and
 
           // Decrease reduction for moves that escape a capture. Filter out
           // castling moves, because they are coded as "king captures rook" and
@@ -1472,7 +1476,7 @@ moves_loop: // When in check search starts from here
     int maxScore = -VALUE_INFINITE;
 
     // Choose best move. For each move score we add two terms, both dependent on
     int maxScore = -VALUE_INFINITE;
 
     // Choose best move. For each move score we add two terms, both dependent on
-    // weakness. One is deterministic and bigger for weaker levels, and one is 
+    // weakness. One is deterministic and bigger for weaker levels, and one is
     // random. Then we choose the move with the resulting highest score.
     for (size_t i = 0; i < multiPV; ++i)
     {
     // random. Then we choose the move with the resulting highest score.
     for (size_t i = 0; i < multiPV; ++i)
     {