]> git.sesse.net Git - stockfish/commitdiff
Save static evaluation also for failed low nodes
authorMarco Costalba <mcostalba@gmail.com>
Fri, 18 Sep 2009 08:32:57 +0000 (10:32 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 20 Sep 2009 19:05:40 +0000 (20:05 +0100)
When a node fails low and bestValue is still equal to
the original static node evaluation, then save this
in TT along with usual info.

This will allow us to avoid a future costly evaluation() call.

This patch extends to failed low nodes what we already do
for failed high ones.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/search.cpp
src/tt.cpp
src/value.h

index 0c9f1ee703ef3dd188710826d2c7e2d3713c9354..93a582035df07f4ada4a20cd82e17003720f34de 100644 (file)
@@ -1535,7 +1535,7 @@ namespace {
     if (isCheck)
         staticValue = -VALUE_INFINITE;
 
     if (isCheck)
         staticValue = -VALUE_INFINITE;
 
-    else if (tte && tte->type() == VALUE_TYPE_EVAL)
+    else if (tte && (tte->type() & VALUE_TYPE_EVAL))
     {
         // Use the cached evaluation score if possible
         assert(ei.futilityMargin == Value(0));
     {
         // Use the cached evaluation score if possible
         assert(ei.futilityMargin == Value(0));
@@ -1556,7 +1556,7 @@ namespace {
     {
         // Store the score to avoid a future costly evaluation() call
         if (!isCheck && !tte && ei.futilityMargin == 0)
     {
         // Store the score to avoid a future costly evaluation() call
         if (!isCheck && !tte && ei.futilityMargin == 0)
-            TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_EVAL, Depth(-127*OnePly), MOVE_NONE);
+            TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_EV_LO, Depth(-127*OnePly), MOVE_NONE);
 
         return bestValue;
     }
 
         return bestValue;
     }
@@ -1644,9 +1644,13 @@ namespace {
     Move m = ss[ply].pv[ply];
     if (!pvNode)
     {
     Move m = ss[ply].pv[ply];
     if (!pvNode)
     {
+        // If bestValue isn't changed it means it is still the static evaluation of
+        // the node, so keep this info to avoid a future costly evaluation() call.
+        ValueType type = (bestValue == staticValue && !ei.futilityMargin ? VALUE_TYPE_EV_UP : VALUE_TYPE_UPPER);
         Depth d = (depth == Depth(0) ? Depth(0) : Depth(-1));
         Depth d = (depth == Depth(0) ? Depth(0) : Depth(-1));
+
         if (bestValue < beta)
         if (bestValue < beta)
-            TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_UPPER, d, MOVE_NONE);
+            TT.store(pos.get_key(), value_to_tt(bestValue, ply), type, d, MOVE_NONE);
         else
             TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_LOWER, d, m);
     }
         else
             TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_LOWER, d, m);
     }
index e140a0ba10ec5fa2183b506b68750a4dcbc39289..9f0e21fdea148702d098e85aa354374dfc84a684 100644 (file)
@@ -121,8 +121,8 @@ void TranspositionTable::store(const Key posKey, Value v, ValueType t, Depth d,
   {
       if (!tte->key() || tte->key() == posKey32) // empty or overwrite old
       {
   {
       if (!tte->key() || tte->key() == posKey32) // empty or overwrite old
       {
-          // Do not overwrite when new type is VALUE_TYPE_EVAL
-          if (tte->key() && t == VALUE_TYPE_EVAL)
+          // Do not overwrite when new type is VALUE_TYPE_EV_LO
+          if (tte->key() && t == VALUE_TYPE_EV_LO)
               return;
 
           if (m == MOVE_NONE)
               return;
 
           if (m == MOVE_NONE)
index 51517462b41d2690d60ada2a35cd961631e1b9a0..3af00d8ece9fa2d34064ef396a27b2f701d40acc 100644 (file)
@@ -37,7 +37,9 @@ enum ValueType {
   VALUE_TYPE_UPPER = 1,  // Upper bound
   VALUE_TYPE_LOWER = 2,  // Lower bound
   VALUE_TYPE_EXACT = 3,  // Exact score
   VALUE_TYPE_UPPER = 1,  // Upper bound
   VALUE_TYPE_LOWER = 2,  // Lower bound
   VALUE_TYPE_EXACT = 3,  // Exact score
-  VALUE_TYPE_EVAL  = 4   // Evaluation cache
+  VALUE_TYPE_EVAL  = 4,  // Evaluation cache
+  VALUE_TYPE_EV_UP = 5,  // Evaluation cache for upper bound
+  VALUE_TYPE_EV_LO = 6   // Evaluation cache for lower bound
 };
 
 
 };