From d55a5a4d81b613e5a82e428770347b06fbd2d9a8 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sat, 18 Dec 2010 10:27:24 +0100 Subject: [PATCH] Better clarify how we use TT depth in qsearch 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 --- src/depth.h | 5 ++++- src/movepick.cpp | 2 +- src/search.cpp | 22 ++++++++++------------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/depth.h b/src/depth.h index f77dd0d3..6b266adb 100644 --- a/src/depth.h +++ b/src/depth.h @@ -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 }; diff --git a/src/movepick.cpp b/src/movepick.cpp index 2e8eb665..05cd0052 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -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 { diff --git a/src/search.cpp b/src/search.cpp index 83d052bb..9b1921f2 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -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); -- 2.39.2