]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Fix aspiration corner case
[stockfish] / src / search.cpp
index 915e1af25d69ccee4e5faead5f68cf58b14ecd96..3f367d83bd0218fed704ad6d720d3c0eb2c9a2a9 100644 (file)
@@ -600,17 +600,17 @@ namespace {
     Value value, alpha, beta;
     Move bestMove, easyMove;
 
-    // Moves to search are verified and copied
-    Rml.init(pos, searchMoves);
-
-    // Initialize FIXME move before Rml.init()
+    // Initialize stuff before a new search
+    memset(ss, 0, 4 * sizeof(SearchStack));
     TT.new_search();
     H.clear();
-    memset(ss, 0, 4 * sizeof(SearchStack));
     *ponderMove = bestMove = easyMove = MOVE_NONE;
     depth = aspirationDelta = 0;
-    ss->currentMove = MOVE_NULL; // Hack to skip update_gains()
     alpha = -VALUE_INFINITE, beta = VALUE_INFINITE;
+    ss->currentMove = MOVE_NULL; // Hack to skip update_gains()
+
+    // Moves to search are verified and copied
+    Rml.init(pos, searchMoves);
 
     // Handle special case of searching on a mate/stalemate position
     if (Rml.size() == 0)
@@ -643,8 +643,7 @@ namespace {
 
         // Start with a small aspiration window and, in case of fail high/low,
         // research with bigger window until not failing high/low anymore.
-        while (true)
-        {
+        do {
             // Search starting from ss+1 to allow calling update_gains()
             value = search<PV, false, true>(pos, ss+1, alpha, beta, depth * ONE_PLY, 0);
 
@@ -680,7 +679,8 @@ namespace {
             }
             else
                 break;
-        }
+
+        } while (abs(value) < VALUE_KNOWN_WIN);
 
         // Collect info about search result
         bestMove = Rml[0].pv[0];