]> git.sesse.net Git - stockfish/commitdiff
Use nullMove only through MovePicker.
authorJoona Kiiski <joona.kiiski@gmail.com>
Mon, 24 Aug 2009 15:08:31 +0000 (18:08 +0300)
committerMarco Costalba <mcostalba@gmail.com>
Wed, 26 Aug 2009 15:30:35 +0000 (16:30 +0100)
No functional change.

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

index f50f16b03b2ac9fbfd5c2f20d875fce22f1067e1..8089345546a1f1c58c31a8f3365fe0f2cf388c24 100644 (file)
@@ -44,6 +44,7 @@ namespace {
 
   CACHE_LINE_ALIGNMENT
   const MovegenPhaseT MainSearchPhaseTable[] = { PH_STOP, PH_NULL_MOVE, PH_TT_MOVES, PH_GOOD_CAPTURES, PH_KILLERS, PH_NONCAPTURES, PH_BAD_CAPTURES, PH_STOP};
+  const MovegenPhaseT MainSearchNoNullPhaseTable[] = { PH_STOP, PH_TT_MOVES, PH_GOOD_CAPTURES, PH_KILLERS, PH_NONCAPTURES, PH_BAD_CAPTURES, PH_STOP};
   const MovegenPhaseT EvasionsPhaseTable[] = { PH_STOP, PH_EVASIONS, PH_STOP};
   const MovegenPhaseT QsearchWithChecksPhaseTable[] = { PH_STOP, PH_TT_MOVES, PH_QCAPTURES, PH_QCHECKS, PH_STOP};
   const MovegenPhaseT QsearchWithoutChecksPhaseTable[] = { PH_STOP, PH_TT_MOVES, PH_QCAPTURES, PH_STOP};
@@ -79,7 +80,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d,
   if (p.is_check())
       phasePtr = EvasionsPhaseTable;
   else if (d > Depth(0))
-      phasePtr = MainSearchPhaseTable;
+      phasePtr = useNullMove ? MainSearchPhaseTable : MainSearchNoNullPhaseTable;
   else if (d == Depth(0))
       phasePtr = QsearchWithChecksPhaseTable;
   else
@@ -116,7 +117,7 @@ Move MovePicker::get_next_move() {
     switch (*phasePtr) {
 
     case PH_NULL_MOVE:
-        break;
+        return MOVE_NULL;
 
     case PH_TT_MOVES:
         movesPicked = 0; // This is used as index to ttMoves[]
index 704cf720008d76e300b512ad378c99a14c0900ca..804108b42b3815487692eac98bfa866c69ad9a6d 100644 (file)
@@ -1288,45 +1288,6 @@ namespace {
                         &&  ok_to_do_nullmove(pos)
                         &&  approximateEval >= beta - NullMoveMargin);
 
-    // Null move search
-    if (useNullMove)
-    {
-        ss[ply].currentMove = MOVE_NULL;
-
-        StateInfo st;
-        pos.do_null_move(st);
-        int R = (depth >= 5 * OnePly ? 4 : 3); // Null move dynamic reduction
-
-        Value nullValue = -search(pos, ss, -(beta-1), depth-R*OnePly, ply+1, false, threadID);
-
-        pos.undo_null_move();
-
-        if (nullValue >= beta)
-        {
-            if (depth < 6 * OnePly)
-                return beta;
-
-            // Do zugzwang verification search
-            Value v = search(pos, ss, beta, depth-5*OnePly, ply, false, threadID);
-            if (v >= beta)
-                return beta;
-        } 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
-            // the move that refuted the null move was somehow connected to the
-            // move which was reduced. If a connection is found, return a fail
-            // low score (which will cause the reduced move to fail high in the
-            // parent node, which will trigger a re-search with full depth).
-            if (nullValue == value_mated_in(ply + 2))
-                mateThreat = true;
-
-            ss[ply].threatMove = ss[ply + 1].currentMove;
-            if (   depth < ThreatDepth
-                && ss[ply - 1].reduction
-                && connected_moves(pos, ss[ply - 1].currentMove, ss[ply].threatMove))
-                return beta - 1;
-        }
-    }
     // Null move search not allowed, try razoring
     if (    !useNullMove
          && !value_is_mate(beta)
@@ -1351,7 +1312,7 @@ namespace {
 
     // Initialize a MovePicker object for the current position, and prepare
     // to search all moves.
-    MovePicker mp = MovePicker(pos, ttMove, depth, H, &ss[ply]);
+    MovePicker mp = MovePicker(pos, ttMove, depth, H, &ss[ply], useNullMove);
 
     Move move, movesSearched[256];
     int moveCount = 0;
@@ -1367,6 +1328,48 @@ namespace {
            && (move = mp.get_next_move()) != MOVE_NONE
            && !thread_should_stop(threadID))
     {
+
+      // Null move search
+      if (move == MOVE_NULL)
+      {
+          ss[ply].currentMove = MOVE_NULL;
+
+          StateInfo st;
+          pos.do_null_move(st);
+          int R = (depth >= 5 * OnePly ? 4 : 3); // Null move dynamic reduction
+
+          Value nullValue = -search(pos, ss, -(beta-1), depth-R*OnePly, ply+1, false, threadID);
+
+          pos.undo_null_move();
+
+          if (nullValue >= beta)
+          {
+              if (depth < 6 * OnePly)
+                  return beta;
+
+              // Do zugzwang verification search
+              Value v = search(pos, ss, beta, depth-5*OnePly, ply, false, threadID);
+              if (v >= beta)
+                  return beta;
+          } 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
+              // the move that refuted the null move was somehow connected to the
+              // move which was reduced. If a connection is found, return a fail
+              // low score (which will cause the reduced move to fail high in the
+              // parent node, which will trigger a re-search with full depth).
+              if (nullValue == value_mated_in(ply + 2))
+                  mateThreat = true;
+
+              ss[ply].threatMove = ss[ply + 1].currentMove;
+              if (   depth < ThreatDepth
+                  && ss[ply - 1].reduction
+                  && connected_moves(pos, ss[ply - 1].currentMove, ss[ply].threatMove))
+                  return beta - 1;
+          }
+          continue;
+      }
+
       assert(move_is_ok(move));
 
       bool singleReply = (isCheck && mp.number_of_moves() == 1);