]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Increase LMR limit by one ply
[stockfish] / src / search.cpp
index 17a221110462c6173f4d83602881a7031e9b8ab9..3862e27b74a1c4d6123441616cbcefa428a0f201 100644 (file)
@@ -243,9 +243,6 @@ namespace {
   template <NodeType NT>
   Value qsearch(Position& pos, SearchStack* ss, Value alpha, Value beta, Depth depth);
 
-  template <bool PvNode>
-  Depth extension(const Position& pos, Move m, bool captureOrPromotion, bool moveIsCheck, bool* dangerous);
-
   bool check_is_dangerous(Position &pos, Move move, Value futilityBase, Value beta, Value *bValue);
   bool connected_moves(const Position& pos, Move m1, Move m2);
   Value value_to_tt(Value v, int ply);
@@ -285,6 +282,51 @@ namespace {
     return os;
   }
 
+  // extension() decides whether a move should be searched with normal depth,
+  // or with extended depth. Certain classes of moves (checking moves, in
+  // particular) are searched with bigger depth than ordinary moves and in
+  // any case are marked as 'dangerous'. Note that also if a move is not
+  // extended, as example because the corresponding UCI option is set to zero,
+  // the move is marked as 'dangerous' so, at least, we avoid to prune it.
+  template <bool PvNode>
+  FORCE_INLINE Depth extension(const Position& pos, Move m, bool captureOrPromotion,
+                               bool moveIsCheck, bool* dangerous) {
+    assert(m != MOVE_NONE);
+
+    Depth result = DEPTH_ZERO;
+    *dangerous = moveIsCheck;
+
+    if (moveIsCheck && pos.see_sign(m) >= 0)
+        result += CheckExtension[PvNode];
+
+    if (pos.type_of_piece_on(move_from(m)) == PAWN)
+    {
+        Color c = pos.side_to_move();
+        if (relative_rank(c, move_to(m)) == RANK_7)
+        {
+            result += PawnPushTo7thExtension[PvNode];
+            *dangerous = true;
+        }
+        if (pos.pawn_is_passed(c, move_to(m)))
+        {
+            result += PassedPawnExtension[PvNode];
+            *dangerous = true;
+        }
+    }
+
+    if (   captureOrPromotion
+        && pos.type_of_piece_on(move_to(m)) != PAWN
+        && (  pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK)
+            - pos.midgame_value_of_piece_on(move_to(m)) == VALUE_ZERO)
+        && !move_is_special(m))
+    {
+        result += PawnEndgameExtension[PvNode];
+        *dangerous = true;
+    }
+
+    return Min(result, ONE_PLY);
+  }
+
 } // namespace
 
 
@@ -721,7 +763,7 @@ namespace {
 
     // Step 2. Check for aborted search and immediate draw
     if ((   StopRequest
-         || pos.is_draw()
+         || pos.is_draw<false>()
          || ss->ply > PLY_MAX) && !RootNode)
         return VALUE_DRAW;
 
@@ -1092,7 +1134,7 @@ split_point_start: // At split points actual search starts from here
           bool doFullDepthSearch = true;
           alpha = SpNode ? sp->alpha : alpha;
 
-          if (    depth >= 3 * ONE_PLY
+          if (    depth > 3 * ONE_PLY
               && !captureOrPromotion
               && !dangerous
               && !move_is_castle(move)
@@ -1291,7 +1333,7 @@ split_point_start: // At split points actual search starts from here
     ss->ply = (ss-1)->ply + 1;
 
     // Check for an instant draw or maximum ply reached
-    if (ss->ply > PLY_MAX || pos.is_draw())
+    if (pos.is_draw<true>() || ss->ply > PLY_MAX)
         return VALUE_DRAW;
 
     // Decide whether or not to include checks, this fixes also the type of
@@ -1330,8 +1372,6 @@ split_point_start: // At split points actual search starts from here
         else
             ss->eval = bestValue = evaluate(pos, evalMargin);
 
-        update_gains(pos, (ss-1)->currentMove, (ss-1)->eval, ss->eval);
-
         // Stand pat. Return immediately if static value is at least beta
         if (bestValue >= beta)
         {
@@ -1605,53 +1645,6 @@ split_point_start: // At split points actual search starts from here
   }
 
 
-  // extension() decides whether a move should be searched with normal depth,
-  // or with extended depth. Certain classes of moves (checking moves, in
-  // particular) are searched with bigger depth than ordinary moves and in
-  // any case are marked as 'dangerous'. Note that also if a move is not
-  // extended, as example because the corresponding UCI option is set to zero,
-  // the move is marked as 'dangerous' so, at least, we avoid to prune it.
-  template <bool PvNode>
-  Depth extension(const Position& pos, Move m, bool captureOrPromotion,
-                  bool moveIsCheck, bool* dangerous) {
-
-    assert(m != MOVE_NONE);
-
-    Depth result = DEPTH_ZERO;
-    *dangerous = moveIsCheck;
-
-    if (moveIsCheck && pos.see_sign(m) >= 0)
-        result += CheckExtension[PvNode];
-
-    if (pos.type_of_piece_on(move_from(m)) == PAWN)
-    {
-        Color c = pos.side_to_move();
-        if (relative_rank(c, move_to(m)) == RANK_7)
-        {
-            result += PawnPushTo7thExtension[PvNode];
-            *dangerous = true;
-        }
-        if (pos.pawn_is_passed(c, move_to(m)))
-        {
-            result += PassedPawnExtension[PvNode];
-            *dangerous = true;
-        }
-    }
-
-    if (   captureOrPromotion
-        && pos.type_of_piece_on(move_to(m)) != PAWN
-        && (  pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK)
-            - pos.midgame_value_of_piece_on(move_to(m)) == VALUE_ZERO)
-        && !move_is_special(m))
-    {
-        result += PawnEndgameExtension[PvNode];
-        *dangerous = true;
-    }
-
-    return Min(result, ONE_PLY);
-  }
-
-
   // connected_threat() tests whether it is safe to forward prune a move or if
   // is somehow connected to the threat move returned by null search.
 
@@ -2024,7 +2017,7 @@ split_point_start: // At split points actual search starts from here
            && pos.move_is_pl(tte->move())
            && pos.pl_move_is_legal(tte->move(), pos.pinned_pieces(pos.side_to_move()))
            && ply < PLY_MAX
-           && (!pos.is_draw() || ply < 2))
+           && (!pos.is_draw<false>() || ply < 2))
     {
         pv[ply] = tte->move();
         pos.do_move(pv[ply++], *st++);