]> git.sesse.net Git - stockfish/commitdiff
Document why is safe ttValue == VALUE_NONE
authorMarco Costalba <mcostalba@gmail.com>
Sun, 14 Oct 2012 10:36:05 +0000 (12:36 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 14 Oct 2012 10:47:16 +0000 (12:47 +0200)
We can have ttValue == VALUE_NONE when we use a TT
slot to just save a position static evaluation, but
in this case we also save DEPTH_NONE so to avoid
using the ttValue in search. This happens to work,
but due to a number of lucky and tricky cases that
we now documnet through a bunch of asserts and a
little change to value_from_tt() that has no real
effect but clarifing the code.

No functional change.

src/search.cpp

index 856c003a3654f758f44cc5523264fb84910255d7..b45679560e701c487fd4e63164363df35d6c0d11 100644 (file)
@@ -557,6 +557,8 @@ namespace {
             : ttValue >= beta ? (tte->type() & BOUND_LOWER)
                               : (tte->type() & BOUND_UPPER)))
     {
             : ttValue >= beta ? (tte->type() & BOUND_LOWER)
                               : (tte->type() & BOUND_UPPER)))
     {
+        assert(ttValue != VALUE_NONE); // Due to depth > DEPTH_NONE
+
         TT.refresh(tte);
         ss->currentMove = ttMove; // Can be MOVE_NONE
 
         TT.refresh(tte);
         ss->currentMove = ttMove; // Can be MOVE_NONE
 
@@ -574,6 +576,7 @@ namespace {
     // Step 5. Evaluate the position statically and update parent's gain statistics
     if (inCheck)
         ss->eval = ss->evalMargin = refinedValue = VALUE_NONE;
     // Step 5. Evaluate the position statically and update parent's gain statistics
     if (inCheck)
         ss->eval = ss->evalMargin = refinedValue = VALUE_NONE;
+
     else if (tte)
     {
         assert(tte->static_value() != VALUE_NONE);
     else if (tte)
     {
         assert(tte->static_value() != VALUE_NONE);
@@ -818,6 +821,8 @@ split_point_start: // At split points actual search starts from here
           &&  pos.pl_move_is_legal(move, ci.pinned)
           &&  abs(ttValue) < VALUE_KNOWN_WIN)
       {
           &&  pos.pl_move_is_legal(move, ci.pinned)
           &&  abs(ttValue) < VALUE_KNOWN_WIN)
       {
+          assert(ttValue != VALUE_NONE);
+
           Value rBeta = ttValue - int(depth);
           ss->excludedMove = move;
           ss->skipNullMove = true;
           Value rBeta = ttValue - int(depth);
           ss->excludedMove = move;
           ss->skipNullMove = true;
@@ -1111,6 +1116,8 @@ split_point_start: // At split points actual search starts from here
             : ttValue >= beta ? (tte->type() & BOUND_LOWER)
                               : (tte->type() & BOUND_UPPER)))
     {
             : ttValue >= beta ? (tte->type() & BOUND_LOWER)
                               : (tte->type() & BOUND_UPPER)))
     {
+        assert(ttValue != VALUE_NONE); // Due to ttDepth > DEPTH_NONE
+
         ss->currentMove = ttMove; // Can be MOVE_NONE
         return ttValue;
     }
         ss->currentMove = ttMove; // Can be MOVE_NONE
         return ttValue;
     }
@@ -1368,13 +1375,10 @@ split_point_start: // At split points actual search starts from here
 
   Value value_to_tt(Value v, int ply) {
 
 
   Value value_to_tt(Value v, int ply) {
 
-    if (v >= VALUE_MATE_IN_MAX_PLY)
-      return v + ply;
+    assert(v != VALUE_NONE);
 
 
-    if (v <= VALUE_MATED_IN_MAX_PLY)
-      return v - ply;
-
-    return v;
+    return  v >= VALUE_MATE_IN_MAX_PLY  ? v + ply
+          : v <= VALUE_MATED_IN_MAX_PLY ? v - ply : v;
   }
 
 
   }
 
 
@@ -1384,13 +1388,9 @@ split_point_start: // At split points actual search starts from here
 
   Value value_from_tt(Value v, int ply) {
 
 
   Value value_from_tt(Value v, int ply) {
 
-    if (v >= VALUE_MATE_IN_MAX_PLY)
-      return v - ply;
-
-    if (v <= VALUE_MATED_IN_MAX_PLY)
-      return v + ply;
-
-    return v;
+    return  v == VALUE_NONE             ? VALUE_NONE
+          : v >= VALUE_MATE_IN_MAX_PLY  ? v - ply
+          : v <= VALUE_MATED_IN_MAX_PLY ? v + ply : v;
   }
 
 
   }
 
 
@@ -1435,11 +1435,13 @@ split_point_start: // At split points actual search starts from here
 
 
   // refine_eval() returns the transposition table score if possible, otherwise
 
 
   // refine_eval() returns the transposition table score if possible, otherwise
-  // falls back on static position evaluation.
+  // falls back on static position evaluation. Note that we never return VALUE_NONE
+  // even if v == VALUE_NONE.
 
   Value refine_eval(const TTEntry* tte, Value v, Value defaultEval) {
 
       assert(tte);
 
   Value refine_eval(const TTEntry* tte, Value v, Value defaultEval) {
 
       assert(tte);
+      assert(v != VALUE_NONE || !tte->type());
 
       if (   ((tte->type() & BOUND_LOWER) && v >= defaultEval)
           || ((tte->type() & BOUND_UPPER) && v < defaultEval))
 
       if (   ((tte->type() & BOUND_LOWER) && v >= defaultEval)
           || ((tte->type() & BOUND_UPPER) && v < defaultEval))