]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Do not return unproven mate scores from null move search
[stockfish] / src / search.cpp
index b8cf5b908df2ba1780321588be3d0235ec40f2f3..67c98709521ae5d63707a56d39a2f63b2a010d41 100644 (file)
@@ -1,7 +1,7 @@
 /*
   Stockfish, a UCI chess playing engine derived from Glaurung 2.1
   Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
-  Copyright (C) 2008-2009 Marco Costalba
+  Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
 
   Stockfish is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -441,10 +441,6 @@ bool think(const Position& pos, bool infinite, bool ponder, int side_to_move,
   {
       TM.set_active_threads(newActiveThreads);
       init_eval(TM.active_threads());
-      // HACK: init_eval() destroys the static castleRightsMask[] array in the
-      // Position class. The below line repairs the damage.
-      Position p(pos.to_fen());
-      assert(pos.is_ok());
   }
 
   // Wake up sleeping threads
@@ -789,15 +785,17 @@ namespace {
 
     EvalInfo ei;
     StateInfo st;
+    CheckInfo ci(pos);
     int64_t nodes;
     Move move;
     Depth depth, ext, newDepth;
     Value value, alpha, beta;
     bool isCheck, moveIsCheck, captureOrPromotion, dangerous;
-    int researchCount = 0;
+    int researchCountFH, researchCountFL;
+
+    researchCountFH = researchCountFL = 0;
     alpha = *alphaPtr;
     beta = *betaPtr;
-    CheckInfo ci(pos);
     isCheck = pos.is_check();
 
     // Step 1. Initialize node and poll (omitted at root, but I can see no good reason for this, FIXME)
@@ -929,8 +927,8 @@ namespace {
                 print_pv_info(pos, ss, alpha, beta, value);
 
                 // Prepare for a research after a fail high, each time with a wider window
-                researchCount++;
-                *betaPtr = beta = Min(beta + AspirationDelta * (1 << researchCount), VALUE_INFINITE);
+                *betaPtr = beta = Min(beta + AspirationDelta * (1 << researchCountFH), VALUE_INFINITE);
+                researchCountFH++;
 
             } // End of fail high loop
 
@@ -1015,8 +1013,8 @@ namespace {
             break;
 
         // Prepare for a research after a fail low, each time with a wider window
-        researchCount++;
-        *alphaPtr = alpha = Max(alpha - AspirationDelta * (1 << researchCount), -VALUE_INFINITE);
+        *alphaPtr = alpha = Max(alpha - AspirationDelta * (1 << researchCountFL), -VALUE_INFINITE);
+        researchCountFL++;
 
     } // Fail low loop
 
@@ -1380,13 +1378,17 @@ namespace {
 
         if (nullValue >= beta)
         {
+            // Do not return unproven mate scores
+            if (nullValue >= value_mate_in(PLY_MAX))
+                nullValue = beta;
+
             if (depth < 6 * OnePly)
-                return beta;
+                return nullValue;
 
             // Do zugzwang verification search
             Value v = search(pos, ss, beta, depth-5*OnePly, ply, false, threadID);
             if (v >= beta)
-                return beta;
+                return nullValue;
         } else {
             // The null move failed low, which means that we may be faced with
             // some kind of threat. If the previous move was reduced, check if