]> git.sesse.net Git - stockfish/commitdiff
Fix errouneus reset of ss->threatMove
authorMarco Costalba <mcostalba@gmail.com>
Fri, 23 Jul 2010 01:26:10 +0000 (02:26 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Fri, 23 Jul 2010 01:26:57 +0000 (02:26 +0100)
After we set ss->threatMove we could go under a IID step that
resets SearchStack ss and so also ss->threatMove.

When later we use that field in futility pruning we have this
set to MOVE_NONE !

The fix is to use a local variable and add threatMove to SplitPoint
to pass this move to slaves.

Spotted by Ralph Stoesser, fix suggested by Richard Vida.

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

index 7d5e45fc326ace7a19b2071bcdf1581e88f492ca..35565d87841b083bb8527aac4c01520e98942bc3 100644 (file)
@@ -90,7 +90,7 @@ namespace {
 
     template <bool Fake>
     void split(const Position& pos, SearchStack* ss, int ply, Value* alpha, const Value beta, Value* bestValue,
 
     template <bool Fake>
     void split(const Position& pos, SearchStack* ss, int ply, Value* alpha, const Value beta, Value* bestValue,
-               Depth depth, bool mateThreat, int* moveCount, MovePicker* mp, bool pvNode);
+               Depth depth, Move threatMove, bool mateThreat, int* moveCount, MovePicker* mp, bool pvNode);
 
   private:
     friend void poll();
 
   private:
     friend void poll();
@@ -364,7 +364,7 @@ void init_search() {
 // Called at the beginning of search() when starting to examine a new node.
 void SearchStack::init() {
 
 // Called at the beginning of search() when starting to examine a new node.
 void SearchStack::init() {
 
-  currentMove = threatMove = bestMove = MOVE_NONE;
+  currentMove = bestMove = MOVE_NONE;
 }
 
 // SearchStack::initKillers() initializes killers for a search stack entry
 }
 
 // SearchStack::initKillers() initializes killers for a search stack entry
@@ -1026,6 +1026,7 @@ namespace {
     bool mateThreat = false;
     int moveCount = 0;
     int threadID = pos.thread();
     bool mateThreat = false;
     int moveCount = 0;
     int threadID = pos.thread();
+    Move threatMove = MOVE_NONE;
     refinedValue = bestValue = value = -VALUE_INFINITE;
     oldAlpha = alpha;
 
     refinedValue = bestValue = value = -VALUE_INFINITE;
     oldAlpha = alpha;
 
@@ -1190,10 +1191,10 @@ namespace {
             if (nullValue == value_mated_in(ply + 2))
                 mateThreat = true;
 
             if (nullValue == value_mated_in(ply + 2))
                 mateThreat = true;
 
-            ss->threatMove = (ss+1)->currentMove;
+            threatMove = (ss+1)->currentMove;
             if (   depth < ThreatDepth
                 && (ss-1)->reduction
             if (   depth < ThreatDepth
                 && (ss-1)->reduction
-                && connected_moves(pos, (ss-1)->currentMove, ss->threatMove))
+                && connected_moves(pos, (ss-1)->currentMove, threatMove))
                 return beta - 1;
         }
     }
                 return beta - 1;
         }
     }
@@ -1282,7 +1283,7 @@ namespace {
       {
           // Move count based pruning
           if (   moveCount >= futility_move_count(depth)
       {
           // Move count based pruning
           if (   moveCount >= futility_move_count(depth)
-              && !(ss->threatMove && connected_threat(pos, move, ss->threatMove))
+              && !(threatMove && connected_threat(pos, move, threatMove))
               && bestValue > value_mated_in(PLY_MAX))
               continue;
 
               && bestValue > value_mated_in(PLY_MAX))
               continue;
 
@@ -1390,7 +1391,7 @@ namespace {
           && !TM.thread_should_stop(threadID)
           && Iteration <= 99)
           TM.split<FakeSplit>(pos, ss, ply, &alpha, beta, &bestValue, depth,
           && !TM.thread_should_stop(threadID)
           && Iteration <= 99)
           TM.split<FakeSplit>(pos, ss, ply, &alpha, beta, &bestValue, depth,
-                              mateThreat, &moveCount, &mp, PvNode);
+                              threatMove, mateThreat, &moveCount, &mp, PvNode);
     }
 
     // Step 19. Check for mate and stalemate
     }
 
     // Step 19. Check for mate and stalemate
@@ -1664,7 +1665,7 @@ namespace {
       {
           // Move count based pruning
           if (   moveCount >= futility_move_count(sp->depth)
       {
           // Move count based pruning
           if (   moveCount >= futility_move_count(sp->depth)
-              && !(ss->threatMove && connected_threat(pos, move, ss->threatMove))
+              && !(sp->threatMove && connected_threat(pos, move, sp->threatMove))
               && sp->bestValue > value_mated_in(PLY_MAX))
           {
               lock_grab(&(sp->lock));
               && sp->bestValue > value_mated_in(PLY_MAX))
           {
               lock_grab(&(sp->lock));
@@ -2640,8 +2641,8 @@ namespace {
 
   template <bool Fake>
   void ThreadsManager::split(const Position& p, SearchStack* ss, int ply, Value* alpha,
 
   template <bool Fake>
   void ThreadsManager::split(const Position& p, SearchStack* ss, int ply, Value* alpha,
-                             const Value beta, Value* bestValue, Depth depth, bool mateThreat,
-                             int* moveCount, MovePicker* mp, bool pvNode) {
+                             const Value beta, Value* bestValue, Depth depth, Move threatMove,
+                             bool mateThreat, int* moveCount, MovePicker* mp, bool pvNode) {
     assert(p.is_ok());
     assert(ply > 0 && ply < PLY_MAX);
     assert(*bestValue >= -VALUE_INFINITE);
     assert(p.is_ok());
     assert(ply > 0 && ply < PLY_MAX);
     assert(*bestValue >= -VALUE_INFINITE);
@@ -2674,6 +2675,7 @@ namespace {
     splitPoint.stopRequest = false;
     splitPoint.ply = ply;
     splitPoint.depth = depth;
     splitPoint.stopRequest = false;
     splitPoint.ply = ply;
     splitPoint.depth = depth;
+    splitPoint.threatMove = threatMove;
     splitPoint.mateThreat = mateThreat;
     splitPoint.alpha = *alpha;
     splitPoint.beta = beta;
     splitPoint.mateThreat = mateThreat;
     splitPoint.alpha = *alpha;
     splitPoint.beta = beta;
index 74951548df0c6ec5d08e1298dfb174fd467bee3e..e2e76000793c6f890d569e6c769b680901053da5 100644 (file)
@@ -51,7 +51,6 @@ struct EvalInfo;
 struct SearchStack {
   Move currentMove;
   Move mateKiller;
 struct SearchStack {
   Move currentMove;
   Move mateKiller;
-  Move threatMove;
   Move excludedMove;
   Move bestMove;
   Move killers[2];
   Move excludedMove;
   Move bestMove;
   Move killers[2];
index 17354773b1fd9cb05f471c49c7293a806d118215..c209e125d1de0e62ec313307bdcd7d22c6b3f6ff 100644 (file)
@@ -55,6 +55,7 @@ struct SplitPoint {
   bool pvNode, mateThreat;
   Value beta;
   int ply;
   bool pvNode, mateThreat;
   Value beta;
   int ply;
+  Move threatMove;
   SearchStack sstack[MAX_THREADS][PLY_MAX_PLUS_2];
 
   // Const pointers to shared data
   SearchStack sstack[MAX_THREADS][PLY_MAX_PLUS_2];
 
   // Const pointers to shared data