]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Sync sp_search() with main search()
[stockfish] / src / search.cpp
index 30179e8f27fafa2c931c3ef0840d95875a21b568..5e04dbb7b696cc874f63641c2643f9ca34f9653d 100644 (file)
@@ -1673,9 +1673,9 @@ namespace {
 
       // Step 12. Futility pruning (is omitted in PV nodes)
       if (   !PvNode
-          && !isCheck
-          && !dangerous
           && !captureOrPromotion
+          && !isCheck
+          && !dangerous          
           && !move_is_castle(move))
       {
           // Move count based pruning
@@ -1709,16 +1709,18 @@ namespace {
       // If the move fails high will be re-searched at full depth.
       bool doFullDepthSearch = true;
 
-      if (   !dangerous
-          && !captureOrPromotion
+      if (   !captureOrPromotion
+          && !dangerous
           && !move_is_castle(move)
           && !move_is_killer(move, ss))
       {
           ss->reduction = reduction<PvNode>(sp->depth, moveCount);
           if (ss->reduction)
           {
-              Value localAlpha = sp->alpha;
-              value = -search<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, newDepth-ss->reduction, true, threadID);
+              Value localAlpha = sp->alpha;              
+              Depth d = newDepth - ss->reduction;
+              value = d < OnePly ? -qsearch<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, Depth(0), threadID)
+                                 : - search<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, d, true, threadID);
               doFullDepthSearch = (value > localAlpha);
           }
 
@@ -1727,6 +1729,8 @@ namespace {
           // if the move fails high again then go with full depth search.
           if (doFullDepthSearch && ss->reduction > 2 * OnePly)
           {
+              assert(newDepth - OnePly >= OnePly);
+
               ss->reduction = OnePly;
               Value localAlpha = sp->alpha;
               value = -search<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, newDepth-ss->reduction, true, threadID);
@@ -1739,10 +1743,15 @@ namespace {
       {
           ss->reduction = Depth(0);
           Value localAlpha = sp->alpha;
-          value = -search<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, newDepth, true, threadID);
+          value = newDepth < OnePly ? -qsearch<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, Depth(0), threadID)
+                                    : - search<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, newDepth, true, threadID);
 
+          // Step extra. pv search (only in PV nodes)
+          // Search only for possible new PV nodes, if instead value >= beta then
+          // parent node fails low with value <= alpha and tries another move.
           if (PvNode && value > localAlpha && value < sp->beta)
-              value = -search<PV>(pos, ss+1, -sp->beta, -sp->alpha, newDepth, false, threadID);
+              value = newDepth < OnePly ? -qsearch<PV>(pos, ss+1, -sp->beta, -sp->alpha, Depth(0), threadID)
+                                        : - search<PV>(pos, ss+1, -sp->beta, -sp->alpha, newDepth, false, threadID);
       }
 
       // Step 16. Undo move