]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Include castle moves in 'dangerous' flag
[stockfish] / src / search.cpp
index 9c1d0b5eca66e1e928accfaec998d3f3d426d2d1..74b79e1c802ee4785b51c06e2446daf9be154766 100644 (file)
@@ -171,16 +171,16 @@ namespace {
   // 'dangerous' moves so that we avoid to prune it.
   FORCE_INLINE bool is_dangerous(const Position& pos, Move m, bool captureOrPromotion) {
 
-    // Test for a pawn pushed to 7th or a passed pawn move
-    if (type_of(pos.piece_moved(m)) == PAWN)
-    {
-        Color c = pos.side_to_move();
-        if (   relative_rank(c, to_sq(m)) == RANK_7
-            || pos.pawn_is_passed(c, to_sq(m)))
-            return true;
-    }
+    // Castle move?
+    if (type_of(m) == CASTLE)
+        return true;
 
-    // Test for a capture that triggers a pawn endgame
+    // Passed pawn move?
+    if (   type_of(pos.piece_moved(m)) == PAWN
+        && pos.pawn_is_passed(pos.side_to_move(), to_sq(m)))
+        return true;
+
+    // Entering a pawn endgame?
     if (    captureOrPromotion
         &&  type_of(pos.piece_on(to_sq(m))) != PAWN
         &&  type_of(m) == NORMAL
@@ -708,16 +708,16 @@ namespace {
         ss->currentMove = MOVE_NULL;
 
         // Null move dynamic reduction based on depth
-        int R = 3 + (depth >= 5 * ONE_PLY ? depth / 8 : 0);
+        Depth R = 3 * ONE_PLY + depth / 4;
 
         // Null move dynamic reduction based on value
         if (refinedValue - PawnValueMidgame > beta)
-            R++;
+            R += ONE_PLY;
 
         pos.do_null_move<true>(st);
         (ss+1)->skipNullMove = true;
-        nullValue = depth-R*ONE_PLY < ONE_PLY ? -qsearch<NonPV>(pos, ss+1, -beta, -alpha, DEPTH_ZERO)
-                                              : - search<NonPV>(pos, ss+1, -beta, -alpha, depth-R*ONE_PLY);
+        nullValue = depth-R < ONE_PLY ? -qsearch<NonPV>(pos, ss+1, -beta, -alpha, DEPTH_ZERO)
+                                      : - search<NonPV>(pos, ss+1, -beta, -alpha, depth-R);
         (ss+1)->skipNullMove = false;
         pos.do_null_move<false>(st);
 
@@ -732,7 +732,7 @@ namespace {
 
             // Do verification search at high depths
             ss->skipNullMove = true;
-            Value v = search<NonPV>(pos, ss, alpha, beta, depth-R*ONE_PLY);
+            Value v = search<NonPV>(pos, ss, alpha, beta, depth-R);
             ss->skipNullMove = false;
 
             if (v >= beta)
@@ -878,19 +878,18 @@ split_point_start: // At split points actual search starts from here
       if (    singularExtensionNode
           && !ext
           &&  move == ttMove
-          &&  pos.pl_move_is_legal(move, ci.pinned))
+          &&  pos.pl_move_is_legal(move, ci.pinned)
+          &&  abs(ttValue) < VALUE_KNOWN_WIN)
       {
-          if (abs(ttValue) < VALUE_KNOWN_WIN)
-          {
-              Value rBeta = ttValue - int(depth);
-              ss->excludedMove = move;
-              ss->skipNullMove = true;
-              value = search<NonPV>(pos, ss, rBeta - 1, rBeta, depth / 2);
-              ss->skipNullMove = false;
-              ss->excludedMove = MOVE_NONE;
-              if (value < rBeta)
-                  ext = ONE_PLY;
-          }
+          Value rBeta = ttValue - int(depth);
+          ss->excludedMove = move;
+          ss->skipNullMove = true;
+          value = search<NonPV>(pos, ss, rBeta - 1, rBeta, depth / 2);
+          ss->skipNullMove = false;
+          ss->excludedMove = MOVE_NONE;
+
+          if (value < rBeta)
+              ext = ONE_PLY;
       }
 
       // Update current move (this must be done after singular extension search)
@@ -902,7 +901,6 @@ split_point_start: // At split points actual search starts from here
           && !inCheck
           && !dangerous
           &&  move != ttMove
-          &&  type_of(move) != CASTLE
           && (bestValue > VALUE_MATED_IN_MAX_PLY || bestValue == -VALUE_INFINITE))
       {
           // Move count based pruning
@@ -961,7 +959,6 @@ split_point_start: // At split points actual search starts from here
           && !isPvMove
           && !captureOrPromotion
           && !dangerous
-          &&  type_of(move) != CASTLE
           &&  ss->killers[0] != move
           &&  ss->killers[1] != move)
       {
@@ -1354,7 +1351,7 @@ split_point_start: // At split points actual search starts from here
     while (b)
     {
         // Note that here we generate illegal "double move"!
-        if (futilityBase + PieceValueEndgame[pos.piece_on(pop_1st_bit(&b))] >= beta)
+        if (futilityBase + PieceValueEndgame[pos.piece_on(pop_lsb(&b))] >= beta)
             return true;
     }