]> git.sesse.net Git - stockfish/commitdiff
Merge Joona's razoring tweaks
authorMarco Costalba <mcostalba@gmail.com>
Tue, 28 Apr 2009 06:51:11 +0000 (08:51 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Tue, 28 Apr 2009 07:00:09 +0000 (09:00 +0200)
After proof testing on 3 different engines these
are the results:

Stockfish - Toga II 1.4.1SE +130 -132 =132 49.75%
Stockfish - Deep Sieng 3.0  +145 -110 =150 54.45%
Stockfish - HIARCS 12 MP    +94  -149 =150 43.00%

So it seems no regressions occurs, although also no
improvment. But anyhow this patch increases Stockfish
strenght against itself, so merge it.

Note that this patch not only adds back razoring at depth
one, but also increases razor depth limit from 3 to 4
because hard coded depth 4 limit is no more overwritten
by UCI parameter that otherwise defaults to 3.

1  2 
src/search.cpp
src/ucioption.cpp

diff --combined src/search.cpp
index 0ac38d0539f6bbc503ea26e5ada4e40c3863e5a9,4e5103f035fceb52253d00a739c701114999323a..3ad5423d9d41a7f4600dc97cce32bed306514b2c
@@@ -139,7 -139,7 +139,7 @@@ namespace 
    Depth ThreatDepth;
  
    // Depth limit for selective search
 -  Depth SelectiveDepth;
 +  const Depth SelectiveDepth = 7*OnePly;
  
    // Use internal iterative deepening?
    const bool UseIIDAtPVNodes = true;
  
    // Margins for futility pruning in the quiescence search, and at frontier
    // and near frontier nodes
-   Value FutilityMarginQS;
-   Value FutilityMargins[6] = { Value(0x100), Value(0x200), Value(0x250),
-                                Value(0x2A0), Value(0x340), Value(0x3A0) };
+   const Value FutilityMarginQS = Value(0x80);
  
-   // Razoring
-   const bool RazorAtDepthOne = false;
-   Depth RazorDepth;
-   Value RazorMargin;
+    // Remaining depth:                  1 ply         1.5 ply       2 ply         2.5 ply       3 ply         3.5 ply
+    const Value FutilityMargins[12] = { Value(0x100), Value(0x120), Value(0x200), Value(0x220), Value(0x250), Value(0x270),
+   //                                   4 ply         4.5 ply       5 ply         5.5 ply       6 ply         6.5 ply
+                                       Value(0x2A0), Value(0x2C0), Value(0x340), Value(0x360), Value(0x3A0), Value(0x3C0) };
+    // Razoring
+    const Depth RazorDepth = 4*OnePly;
+   // Remaining depth:                 1 ply         1.5 ply       2 ply         2.5 ply       3 ply         3.5 ply
+   const Value RazorMargins[6]     = { Value(0x180), Value(0x300), Value(0x300), Value(0x3C0), Value(0x3C0), Value(0x3C0) };
+   // Remaining depth:                 1 ply         1.5 ply       2 ply         2.5 ply       3 ply         3.5 ply
+    const Value RazorApprMargins[6] = { Value(0x520), Value(0x300), Value(0x300), Value(0x300), Value(0x300), Value(0x300) };
  
    // Last seconds noise filtering (LSN)
    bool UseLSNFiltering;
  ////
  
  // The main transposition table
 -TranspositionTable TT = TranspositionTable(TTDefaultSize);
 +TranspositionTable TT;
  
  
  // Number of active threads:
@@@ -426,6 -432,7 +432,6 @@@ void think(const Position &pos, bool in
    LMRPVMoves     = get_option_value_int("Full Depth Moves (PV nodes)") + 1;
    LMRNonPVMoves  = get_option_value_int("Full Depth Moves (non-PV nodes)") + 1;
    ThreatDepth    = get_option_value_int("Threat Depth") * OnePly;
 -  SelectiveDepth = get_option_value_int("Selective Plies") * OnePly;
  
    Chess960 = get_option_value_bool("UCI_Chess960");
    ShowCurrentLine = get_option_value_bool("UCI_ShowCurrLine");
    UseQSearchFutilityPruning = get_option_value_bool("Futility Pruning (Quiescence Search)");
    UseFutilityPruning = get_option_value_bool("Futility Pruning (Main Search)");
  
-   FutilityMarginQS = value_from_centipawns(get_option_value_int("Futility Margin (Quiescence Search)"));
-   int fmScale = get_option_value_int("Futility Margin Scale Factor (Main Search)");
-   for (int i = 0; i < 6; i++)
-       FutilityMargins[i] = (FutilityMargins[i] * fmScale) / 100;
-   RazorDepth = (get_option_value_int("Maximum Razoring Depth") + 1) * OnePly;
-   RazorMargin = value_from_centipawns(get_option_value_int("Razoring Margin"));
    UseLSNFiltering = get_option_value_bool("LSN filtering");
    LSNTime = get_option_value_int("LSN Time Margin (sec)") * 1000;
    LSNValue = value_from_centipawns(get_option_value_int("LSN Value Margin"));
@@@ -1190,7 -1189,7 +1188,7 @@@ namespace 
          return bestValue;
  
      if (bestValue <= oldAlpha)
 -        TT.store(pos, value_to_tt(bestValue, ply), depth, MOVE_NONE, VALUE_TYPE_UPPER);
 +        TT.store(pos, value_to_tt(bestValue, ply), VALUE_TYPE_UPPER, depth, MOVE_NONE);
  
      else if (bestValue >= beta)
      {
              update_history(pos, m, depth, movesSearched, moveCount);
              update_killers(m, ss[ply]);
          }
 -        TT.store(pos, value_to_tt(bestValue, ply), depth, m, VALUE_TYPE_LOWER);
 +        TT.store(pos, value_to_tt(bestValue, ply), VALUE_TYPE_LOWER, depth, m);
      }
      else
 -        TT.store(pos, value_to_tt(bestValue, ply), depth, ss[ply].pv[ply], VALUE_TYPE_EXACT);
 +        TT.store(pos, value_to_tt(bestValue, ply), VALUE_TYPE_EXACT, depth, ss[ply].pv[ply]);
  
      return bestValue;
    }
      }
      // Null move search not allowed, try razoring
      else if (   !value_is_mate(beta)
-              && approximateEval < beta - RazorMargin
               && depth < RazorDepth
-              && (RazorAtDepthOne || depth > OnePly)
+              && approximateEval < beta - RazorApprMargins[int(depth) - 2]
               && ttMove == MOVE_NONE
               && !pos.has_pawn_on_7th(pos.side_to_move()))
      {
          Value v = qsearch(pos, ss, beta-1, beta, Depth(0), ply, threadID);
-         if (   (v < beta - RazorMargin - RazorMargin / 4)
-             || (depth <= 2*OnePly && v < beta - RazorMargin)
-             || (depth <=   OnePly && v < beta - RazorMargin / 2))
-             return v;
+         if (v < beta - RazorMargins[int(depth) - 2])
+           return v;
      }
  
      // Go with internal iterative deepening if we don't have a TT move
                continue;
  
            // Value based pruning
 -          if (depth < 7 * OnePly && approximateEval < beta)
 +          if (approximateEval < beta)
            {
                if (futilityValue == VALUE_NONE)
                    futilityValue =  evaluate(pos, ei, threadID)
-                                  + FutilityMargins[int(depth)/2 - 1]
-                                  + 32 * (depth & 1);
+                                  + FutilityMargins[int(depth) - 2];
  
                if (futilityValue < beta)
                {
          return bestValue;
  
      if (bestValue < beta)
 -        TT.store(pos, value_to_tt(bestValue, ply), depth, MOVE_NONE, VALUE_TYPE_UPPER);
 +        TT.store(pos, value_to_tt(bestValue, ply), VALUE_TYPE_UPPER, depth, MOVE_NONE);
      else
      {
          BetaCounter.add(pos.side_to_move(), depth, threadID);
              update_history(pos, m, depth, movesSearched, moveCount);
              update_killers(m, ss[ply]);
          }
 -        TT.store(pos, value_to_tt(bestValue, ply), depth, m, VALUE_TYPE_LOWER);
 +        TT.store(pos, value_to_tt(bestValue, ply), VALUE_TYPE_LOWER, depth, m);
      }
  
      assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);
      {
          // Store the score to avoid a future costly evaluation() call
          if (!isCheck && !tte && ei.futilityMargin == 0)
 -            TT.store(pos, value_to_tt(bestValue, ply), Depth(-127*OnePly), MOVE_NONE, VALUE_TYPE_EVAL);
 +            TT.store(pos, value_to_tt(bestValue, ply), VALUE_TYPE_EVAL, Depth(-127*OnePly), MOVE_NONE);
  
          return bestValue;
      }
      {
          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);
 +            TT.store(pos, value_to_tt(bestValue, ply), VALUE_TYPE_UPPER, d, MOVE_NONE);
          else
 -            TT.store(pos, value_to_tt(bestValue, ply), d, m, VALUE_TYPE_LOWER);
 +            TT.store(pos, value_to_tt(bestValue, ply), VALUE_TYPE_LOWER, d, m);
      }
  
      // Update killers only for good check moves
diff --combined src/ucioption.cpp
index 006c4c56a59e2e223a4cafa441259e1463fa5f1d,63c27403356251b4d703f52b825904e74f1a6f6e..442ca924e10761a030213f8a32533ad943509963
@@@ -125,12 -125,9 +125,8 @@@ namespace 
      o["Full Depth Moves (PV nodes)"] = Option(14, 1, 100);
      o["Full Depth Moves (non-PV nodes)"] = Option(3, 1, 100);
      o["Threat Depth"] = Option(5, 0, 100);
 -    o["Selective Plies"] = Option(7, 0, 10);
      o["Futility Pruning (Main Search)"] = Option(true);
      o["Futility Pruning (Quiescence Search)"] = Option(true);
-     o["Futility Margin (Quiescence Search)"] = Option(50, 0, 1000);
-     o["Futility Margin Scale Factor (Main Search)"] = Option(100, 0, 1000);
-     o["Maximum Razoring Depth"] = Option(3, 0, 4);
-     o["Razoring Margin"] = Option(300, 150, 600);
      o["LSN filtering"] = Option(true);
      o["LSN Time Margin (sec)"] = Option(4, 1, 10);
      o["LSN Value Margin"] = Option(200, 100, 600);