Sync sp_search() with main search()
authorMarco Costalba <mcostalba@gmail.com>
Wed, 2 Jun 2010 09:49:34 +0000 (10:49 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Wed, 2 Jun 2010 09:49:34 +0000 (10:49 +0100)
And fix qserahc() dispatch also there.

No functional change tested wit Faked Split.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
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