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.
+ // when the static evaluation is bigger then beta - IIDMargin.
const Value IIDMargin = Value(0x100);
// Step 11. Decide the new search depth
}
// Step 9. Internal iterative deepening
- if ( depth >= IIDDepth[PvNode]
- && ttMove == MOVE_NONE
+ if ( depth >= IIDDepth[PvNode]
+ && (ttMove == MOVE_NONE || (PvNode && tte->depth() <= depth - 4 * OnePly))
&& (PvNode || (!isCheck && ss[ply].eval >= beta - IIDMargin)))
{
Depth d = (PvNode ? depth - 2 * OnePly : depth / 2);
value = -search<PV>(pos, ss, -beta, -alpha, newDepth, ply+1, false, threadID);
else
{
- // Step 14. Reduced search
- // if the move fails high will be re-searched at full depth.
+ // Step 14. Reduced depth search
+ // If the move fails high will be re-searched at full depth.
bool doFullDepthSearch = true;
if ( depth >= 3 * OnePly
value = -search<NonPV>(pos, ss, -(alpha+1), -alpha, newDepth-ss[ply].reduction, ply+1, true, threadID);
doFullDepthSearch = (value > alpha);
}
+
+ // The move failed high, but if reduction is very big we could
+ // face a false positive, retry with a less aggressive reduction,
+ // if the move fails high again then go with full depth search.
+ if (doFullDepthSearch && ss[ply].reduction > 2 * OnePly)
+ {
+ ss[ply].reduction = OnePly;
+ value = -search<NonPV>(pos, ss, -(alpha+1), -alpha, newDepth-ss[ply].reduction, ply+1, true, threadID);
+ doFullDepthSearch = (value > alpha);
+ }
}
// Step 15. Full depth search
if (bestValue >= beta)
{
// Store the score to avoid a future costly evaluation() call
- if (!isCheck && !tte && ei.kingDanger[pos.side_to_move()] == 0)
+ if (!isCheck && !tte)
TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_LOWER, Depth(-127*OnePly), MOVE_NONE, ss[ply].eval, ei.kingDanger[pos.side_to_move()]);
return bestValue;
pos.do_move(move, st, ci, moveIsCheck);
// Step 14. Reduced search
- // if the move fails high will be re-searched at full depth.
+ // If the move fails high will be re-searched at full depth.
bool doFullDepthSearch = true;
if ( !dangerous
value = -search<NonPV>(pos, ss, -(localAlpha+1), -localAlpha, newDepth-ss[sp->ply].reduction, sp->ply+1, true, threadID);
doFullDepthSearch = (value > localAlpha);
}
+
+ // The move failed high, but if reduction is very big we could
+ // face a false positive, retry with a less aggressive reduction,
+ // if the move fails high again then go with full depth search.
+ if (doFullDepthSearch && ss[sp->ply].reduction > 2 * OnePly)
+ {
+ ss[sp->ply].reduction = OnePly;
+ Value localAlpha = sp->alpha;
+ value = -search<NonPV>(pos, ss, -(localAlpha+1), -localAlpha, newDepth-ss[sp->ply].reduction, sp->ply+1, true, threadID);
+ doFullDepthSearch = (value > localAlpha);
+ }
}
// Step 15. Full depth search