]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Fix two bugs in ok_to_prune() (2)
[stockfish] / src / search.cpp
index dd5e921ef41bb605e543295bcd3d40ee64f14b9b..8e6efb7a1bd9bdc50e041194f9a8c97b35fade5f 100644 (file)
@@ -107,7 +107,7 @@ namespace {
   const bool UseIIDAtNonPVNodes = false;
 
   // Use null move driven internal iterative deepening?
-  bool UseNullDrivenIID = true;
+  bool UseNullDrivenIID = false;
 
   // Internal iterative deepening margin.  At Non-PV moves, when
   // UseIIDAtNonPVNodes is true, we do an internal iterative deepening search
@@ -1139,6 +1139,7 @@ namespace {
 
     // Null move search
     if (    allowNullmove
+        &&  depth > OnePly
         && !isCheck
         &&  ok_to_do_nullmove(pos)
         &&  approximateEval >= beta - NullMoveMargin)
@@ -1160,7 +1161,7 @@ namespace {
             && ttMove == MOVE_NONE
             && ss[ply + 1].currentMove != MOVE_NONE
             && pos.move_is_capture(ss[ply + 1].currentMove)
-            && pos.see(ss[ply + 1].currentMove) * PawnValueMidgame + nullValue > beta - IIDMargin)
+            && pos.see(ss[ply + 1].currentMove) + nullValue >= beta)
             nullDrivenIID = true;
 
         pos.undo_null_move(u);
@@ -1176,9 +1177,9 @@ namespace {
                 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
+            // 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
+            // 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))
@@ -1217,8 +1218,9 @@ namespace {
         Move tm = ss[ply].threatMove;
 
         assert(tm != MOVE_NONE);
+        assert(ttMove == MOVE_NONE);
 
-        search(pos, ss, beta, Min(depth/2, depth-3*OnePly), ply, false, threadID);
+        search(pos, ss, beta, depth/2, ply, false, threadID);
         ttMove = ss[ply].pv[ply];
         ss[ply].threatMove = tm;
     }
@@ -2156,31 +2158,34 @@ namespace {
     tto = move_to(threat);
 
     // Case 1: Castling moves are never pruned.
-    if(move_is_castle(m))
-      return false;
+    if (move_is_castle(m))
+        return false;
 
     // Case 2: Don't prune moves which move the threatened piece
-    if(!PruneEscapeMoves && threat != MOVE_NONE && mfrom == tto)
-      return false;
+    if (!PruneEscapeMoves && threat != MOVE_NONE && mfrom == tto)
+        return false;
 
     // Case 3: If the threatened piece has value less than or equal to the
     // value of the threatening piece, don't prune move which defend it.
-    if(!PruneDefendingMoves && threat != MOVE_NONE
-       && (piece_value_midgame(pos.piece_on(tfrom))
-           >= piece_value_midgame(pos.piece_on(tto)))
-       && pos.move_attacks_square(m, tto))
+    if (   !PruneDefendingMoves
+        && threat != MOVE_NONE
+        && pos.type_of_piece_on(tto) != NO_PIECE_TYPE
+        && (   pos.midgame_value_of_piece_on(tfrom) >= pos.midgame_value_of_piece_on(tto)
+            || pos.type_of_piece_on(tfrom) == KING)
+        && pos.move_attacks_square(m, tto))
       return false;
 
     // Case 4: Don't prune moves with good history.
-    if(!H.ok_to_prune(pos.piece_on(move_from(m)), m, d))
-      return false;
+    if (!H.ok_to_prune(pos.piece_on(move_from(m)), m, d))
+        return false;
 
     // Case 5: If the moving piece in the threatened move is a slider, don't
     // prune safe moves which block its ray.
-    if(!PruneBlockingMoves && threat != MOVE_NONE
-       && piece_is_slider(pos.piece_on(tfrom))
-       && bit_is_set(squares_between(tfrom, tto), mto) && pos.see(m) >= 0)
-      return false;
+    if (  !PruneBlockingMoves
+        && threat != MOVE_NONE
+        && piece_is_slider(pos.piece_on(tfrom))
+        && bit_is_set(squares_between(tfrom, tto), mto) && pos.see(m) >= 0)
+            return false;
 
     return true;
   }