ss->inCheck = pos.checkers();
moveCount = 0;
+ // Used to send selDepth info to GUI (selDepth counts from 1, ply from 0)
+ if (PvNode && thisThread->selDepth < ss->ply + 1)
+ thisThread->selDepth = ss->ply + 1;
+
// Step 2. Check for an immediate draw or maximum ply reached
if (pos.is_draw(ss->ply) || ss->ply >= MAX_PLY)
return (ss->ply >= MAX_PLY && !ss->inCheck) ? evaluate(pos) : VALUE_DRAW;
ss->staticEval = bestValue =
(ss - 1)->currentMove != MOVE_NULL ? evaluate(pos) : -(ss - 1)->staticEval;
- // Stand pat. Return immediately if static value is at least beta
+ // Stand pat. Return immediately if bestValue is at least beta at non-Pv nodes.
+ // At PvNodes set bestValue between alpha and beta instead
if (bestValue >= beta)
{
- if (!ss->ttHit)
- tte->save(posKey, value_to_tt(bestValue, ss->ply), false, BOUND_LOWER, DEPTH_NONE,
- MOVE_NONE, ss->staticEval);
+ if (!PvNode || abs(bestValue) >= VALUE_TB_WIN_IN_MAX_PLY)
+ {
+ if (!ss->ttHit)
+ tte->save(posKey, value_to_tt(bestValue, ss->ply), false, BOUND_LOWER,
+ DEPTH_NONE, MOVE_NONE, ss->staticEval);
- return bestValue;
+ return bestValue;
+ }
+ bestValue = std::min((alpha + beta) / 2, beta - 1);
}
if (bestValue > alpha)