// Step 9. Internal iterative deepening
// Minimum depth for use of internal iterative deepening
- const Depth IIDDepthAtPVNodes = 5 * OnePly;
- const Depth IIDDepthAtNonPVNodes = 8 * OnePly;
+ const Depth IIDDepth[2] = { 8 * OnePly /* non-PV */, 5 * OnePly /* PV */};
// At Non-PV nodes we do an internal iterative deepening search
// when the static evaluation is at most IIDMargin below beta.
}
- // search_pv() is the main search function for PV nodes.
+ // search<>() is the main search function for both PV and non-PV nodes
template <NodeType PvNode>
- Value search(Position& pos, SearchStack ss[], Value alpha, Value beta,
- Depth depth, int ply, bool allowNullmove, int threadID, Move excludedMove) {
+ Value search(Position& pos, SearchStack ss[], Value alpha, Value beta, Depth depth,
+ int ply, bool allowNullmove, int threadID, Move excludedMove) {
assert(alpha >= -VALUE_INFINITE && alpha <= VALUE_INFINITE);
assert(beta > alpha && beta <= VALUE_INFINITE);
isCheck = pos.is_check();
if (!isCheck)
{
- if (!PvNode && tte && (tte->type() & VALUE_TYPE_EVAL))
+ if (tte && (tte->type() & VALUE_TYPE_EVAL))
ss[ply].eval = value_from_tt(tte->value(), ply);
else
ss[ply].eval = evaluate(pos, ei, threadID);
}
// Step 9. Internal iterative deepening
- // We have different rules for PV nodes and non-pv nodes
- if ( PvNode
- && depth >= IIDDepthAtPVNodes
- && ttMove == MOVE_NONE)
- {
- search<PV>(pos, ss, alpha, beta, depth-2*OnePly, ply, false, threadID);
- ttMove = ss[ply].pv[ply];
- tte = TT.retrieve(posKey);
- }
-
- if ( !PvNode
- && depth >= IIDDepthAtNonPVNodes
+ if ( depth >= IIDDepth[PvNode]
&& ttMove == MOVE_NONE
- && !isCheck
- && ss[ply].eval >= beta - IIDMargin)
+ && (PvNode || (!isCheck && ss[ply].eval >= beta - IIDMargin)))
{
- search<NonPV>(pos, ss, alpha, beta, depth/2, ply, false, threadID);
+ Depth d = (PvNode ? depth - 2 * OnePly : depth / 2);
+ search<PvNode>(pos, ss, alpha, beta, d, ply, false, threadID);
ttMove = ss[ply].pv[ply];
tte = TT.retrieve(posKey);
}