]> git.sesse.net Git - stockfish/commitdiff
Better clarify how we use TT depth in qsearch
authorMarco Costalba <mcostalba@gmail.com>
Sat, 18 Dec 2010 09:27:24 +0000 (10:27 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 18 Dec 2010 10:19:31 +0000 (11:19 +0100)
Namely we use only two types of depth in TT:
DEPTH_QS_CHECKS or DEPTH_QS_NO_CHECKS.

No functional change.

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

index f77dd0d3d926ac20dda6f5c48560c528db64ed63..6b266adb430409a7bd565bef77ac89d3836abb8f 100644 (file)
@@ -31,7 +31,10 @@ enum Depth {
 
   ONE_PLY = 2,
 
-  DEPTH_ZERO = 0,
+  DEPTH_ZERO         =  0 * ONE_PLY,
+  DEPTH_QS_CHECKS    = -1 * ONE_PLY,
+  DEPTH_QS_NO_CHECKS = -2 * ONE_PLY,
+
   DEPTH_NONE = -127 * ONE_PLY
 };
 
index 2e8eb665b9acd04573c9e438d77212f2888ccff6..05cd0052ad4cbe03732007fee8e033b4ddbfc853 100644 (file)
@@ -99,7 +99,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h,
 
       phasePtr = MainSearchPhaseTable;
   }
-  else if (d == DEPTH_ZERO)
+  else if (d >= DEPTH_QS_CHECKS)
       phasePtr = QsearchWithChecksPhaseTable;
   else
   {
index 83d052bbeb54c5bb656c053913ab2f8ceb782e65..9b1921f207a30a799bfcaefd569dcdb613dd8115 100644 (file)
@@ -1468,6 +1468,7 @@ split_point_start: // At split points actual search starts from here
     Value bestValue, value, evalMargin, futilityValue, futilityBase;
     bool isCheck, enoughMaterial, moveIsCheck, evasionPrunable;
     const TTEntry* tte;
+    Depth ttDepth;
     Value oldAlpha = alpha;
 
     ss->bestMove = ss->currentMove = MOVE_NONE;
@@ -1476,21 +1477,18 @@ split_point_start: // At split points actual search starts from here
     if (pos.is_draw() || ply >= PLY_MAX - 1)
         return VALUE_DRAW;
 
-    // Decide whether or not to include checks
+    // Decide whether or not to include checks, this fixes also the type of
+    // TT entry depth that we are going to use. Note that in qsearch we use
+    // only two types of depth in TT: DEPTH_QS_CHECKS or DEPTH_QS_NO_CHECKS.
     isCheck = pos.is_check();
-
-    Depth d;
-    if (isCheck || depth >= -ONE_PLY)
-        d = DEPTH_ZERO;
-    else
-        d = DEPTH_ZERO - ONE_PLY;
+    ttDepth = (isCheck || depth >= DEPTH_QS_CHECKS ? DEPTH_QS_CHECKS : DEPTH_QS_NO_CHECKS);
 
     // Transposition table lookup. At PV nodes, we don't use the TT for
     // pruning, but only for move ordering.
     tte = TT.retrieve(pos.get_key());
     ttMove = (tte ? tte->move() : MOVE_NONE);
 
-    if (!PvNode && tte && ok_to_use_TT(tte, d, beta, ply))
+    if (!PvNode && tte && ok_to_use_TT(tte, ttDepth, beta, ply))
     {
         ss->bestMove = ttMove; // Can be MOVE_NONE
         return value_from_tt(tte->value(), ply);
@@ -1536,9 +1534,9 @@ split_point_start: // At split points actual search starts from here
 
     // Initialize a MovePicker object for the current position, and prepare
     // to search the moves. Because the depth is <= 0 here, only captures,
-    // queen promotions and checks (only if depth == 0 or depth == -ONE_PLY
-    // and we are near beta) will be generated.
-    MovePicker mp = MovePicker(pos, ttMove, d, H);
+    // queen promotions and checks (only if depth >= DEPTH_QS_CHECKS) will
+    // be generated.
+    MovePicker mp = MovePicker(pos, ttMove, depth, H);
     CheckInfo ci(pos);
 
     // Loop through the moves until no moves remain or a beta cutoff occurs
@@ -1628,7 +1626,7 @@ split_point_start: // At split points actual search starts from here
 
     // Update transposition table
     ValueType vt = (bestValue <= oldAlpha ? VALUE_TYPE_UPPER : bestValue >= beta ? VALUE_TYPE_LOWER : VALUE_TYPE_EXACT);
-    TT.store(pos.get_key(), value_to_tt(bestValue, ply), vt, d, ss->bestMove, ss->eval, evalMargin);
+    TT.store(pos.get_key(), value_to_tt(bestValue, ply), vt, ttDepth, ss->bestMove, ss->eval, evalMargin);
 
     assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);