]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Less aggressive null move dynamic reduction
[stockfish] / src / search.cpp
index 3617853e5f23d2f3589b7af48da9decbf48e4593..e7c4e6ca2c04d4d1b9008125dfacc68633b1e103 100644 (file)
@@ -121,9 +121,6 @@ namespace {
   // Depth limit for selective search:
   Depth SelectiveDepth = 7*OnePly;
 
-  // Use dynamic LMR?
-  const bool UseDynamicLMR = false;
-
   // Use internal iterative deepening?
   const bool UseIIDAtPVNodes = true;
   const bool UseIIDAtNonPVNodes = false;
@@ -258,7 +255,7 @@ namespace {
                 Depth depth, int ply, int threadID);
   void sp_search(SplitPoint *sp, int threadID);
   void sp_search_pv(SplitPoint *sp, int threadID);
-  void init_node(const Position &pos, SearchStack ss[], int ply, int threadID);
+  void init_node(SearchStack ss[], int ply, int threadID);
   void update_pv(SearchStack ss[], int ply);
   void sp_update_pv(SearchStack *pss, SearchStack ss[], int ply);
   bool connected_moves(const Position &pos, Move m1, Move m2);
@@ -959,7 +956,7 @@ namespace {
 
     // Initialize, and make an early exit in case of an aborted search,
     // an instant draw, maximum ply reached, etc.
-    init_node(pos, ss, ply, threadID);
+    init_node(ss, ply, threadID);
 
     // After init_node() that calls poll()
     if (AbortSearch || thread_should_stop(threadID))
@@ -1155,7 +1152,7 @@ namespace {
 
     // Initialize, and make an early exit in case of an aborted search,
     // an instant draw, maximum ply reached, etc.
-    init_node(pos, ss, ply, threadID);
+    init_node(ss, ply, threadID);
 
     // After init_node() that calls poll()
     if (AbortSearch || thread_should_stop(threadID))
@@ -1202,7 +1199,7 @@ namespace {
 
         StateInfo st;
         pos.do_null_move(st);
-        int R = (depth >= 4 * OnePly ? 4 : 3); // Null move dynamic reduction
+        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);
 
@@ -1335,13 +1332,8 @@ namespace {
           && !move_is_castle(move)
           && !move_is_killer(move, ss[ply]))
       {
-          // LMR dynamic reduction
-          Depth R =    UseDynamicLMR
-                    && moveCount >= 2 * LMRNonPVMoves
-                    && depth > 7*OnePly ? 2*OnePly : OnePly;
-
-          ss[ply].reduction = R;
-          value = -search(pos, ss, -(beta-1), newDepth-R, ply+1, true, threadID);
+          ss[ply].reduction = OnePly;
+          value = -search(pos, ss, -(beta-1), newDepth-OnePly, ply+1, true, threadID);
       }
       else
         value = beta; // Just to trigger next condition
@@ -1424,7 +1416,7 @@ namespace {
 
     // Initialize, and make an early exit in case of an aborted search,
     // an instant draw, maximum ply reached, etc.
-    init_node(pos, ss, ply, threadID);
+    init_node(ss, ply, threadID);
 
     // After init_node() that calls poll()
     if (AbortSearch || thread_should_stop(threadID))
@@ -1451,6 +1443,7 @@ namespace {
     EvalInfo ei;
     Value staticValue;
     bool isCheck = pos.is_check();
+    ei.futilityMargin = Value(0); // Manually initialize futilityMargin
 
     if (isCheck)
         staticValue = -VALUE_INFINITE;
@@ -1462,7 +1455,6 @@ namespace {
         assert(ei.futilityMargin == Value(0));
 
         staticValue = tte->value();
-        ei.futilityMargin = Value(0); // manually initialize futilityMargin
     }
     else
         staticValue = evaluate(pos, ei, threadID);
@@ -1475,15 +1467,12 @@ namespace {
     Value bestValue = staticValue;
 
     if (bestValue >= beta)
-    {
-        // Update transposition table before to leave
-        TT.store(pos, value_to_tt(bestValue, ply), depth, MOVE_NONE, VALUE_TYPE_EXACT);
-        return bestValue;
-    }
-    else if (!isCheck && !tte && ei.futilityMargin == 0)
     {
         // Store the score to avoid a future costly evaluation() call
-        TT.store(pos, value_to_tt(bestValue, ply), Depth(-127*OnePly), MOVE_NONE, VALUE_TYPE_EVAL);
+        if (!isCheck && !tte && ei.futilityMargin == 0)
+            TT.store(pos, value_to_tt(bestValue, ply), Depth(-127*OnePly), MOVE_NONE, VALUE_TYPE_EVAL);
+
+        return bestValue;
     }
 
     if (bestValue > alpha)
@@ -1568,6 +1557,16 @@ namespace {
 
     assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);
 
+    // Update transposition table
+    if (!pvNode)
+    {
+        Depth d = (depth == Depth(0) ? Depth(0) : Depth(-1));
+        if (bestValue < beta)
+            TT.store(pos, value_to_tt(bestValue, ply), d, MOVE_NONE, VALUE_TYPE_UPPER);
+        else
+            TT.store(pos, value_to_tt(bestValue, ply), d, MOVE_NONE, VALUE_TYPE_LOWER);
+    }
+
     // Update killers only for good check moves
     Move m = ss[ply].currentMove;
     if (alpha >= beta && ok_to_history(pos, m)) // Only non capture moves are considered
@@ -2018,7 +2017,7 @@ namespace {
   // NodesBetweenPolls nodes, init_node() also calls poll(), which polls
   // for user input and checks whether it is time to stop the search.
 
-  void init_node(const Position &pos, SearchStack ss[], int ply, int threadID) {
+  void init_node(SearchStack ss[], int ply, int threadID) {
     assert(ply >= 0 && ply < PLY_MAX);
     assert(threadID >= 0 && threadID < ActiveThreads);