// Use static evaluation difference to improve quiet move ordering (~4 Elo)
if (is_ok((ss - 1)->currentMove) && !(ss - 1)->inCheck && !priorCapture)
{
- int bonus = std::clamp(-13 * int((ss - 1)->staticEval + ss->staticEval), -1555, 1452);
+ int bonus = std::clamp(-13 * int((ss - 1)->staticEval + ss->staticEval), -1652, 1546);
thisThread->mainHistory[~us][from_to((ss - 1)->currentMove)] << bonus;
if (type_of(pos.piece_on(prevSq)) != PAWN && type_of((ss - 1)->currentMove) != PROMOTION)
thisThread->pawnHistory[pawn_structure(pos)][pos.piece_on(prevSq)][prevSq] << bonus / 4;
// much above beta, we can (almost) safely prune the previous move.
if (
!PvNode && depth > 3
- && abs(beta) < VALUE_TB_WIN_IN_MAX_PLY
+ && std::abs(beta) < VALUE_TB_WIN_IN_MAX_PLY
// If value from transposition table is lower than probCutBeta, don't attempt probCut
// there and in further interactions with transposition table cutoff depth is set to depth - 3
// because probCut search has depth set to depth - 4 but we also do a move before it
probCutBeta = beta + 425;
if (ss->inCheck && !PvNode && ttCapture && (tte->bound() & BOUND_LOWER)
&& tte->depth() >= depth - 4 && ttValue >= probCutBeta
- && abs(ttValue) < VALUE_TB_WIN_IN_MAX_PLY && abs(beta) < VALUE_TB_WIN_IN_MAX_PLY)
+ && std::abs(ttValue) < VALUE_TB_WIN_IN_MAX_PLY && std::abs(beta) < VALUE_TB_WIN_IN_MAX_PLY)
return probCutBeta;
const PieceToHistory* contHist[] = {(ss - 1)->continuationHistory,
// Recursive singular search is avoided.
if (!rootNode && move == ttMove && !excludedMove
&& depth >= 4 - (thisThread->completedDepth > 27) + 2 * (PvNode && tte->is_pv())
- && abs(ttValue) < VALUE_TB_WIN_IN_MAX_PLY && (tte->bound() & BOUND_LOWER)
+ && std::abs(ttValue) < VALUE_TB_WIN_IN_MAX_PLY && (tte->bound() & BOUND_LOWER)
&& tte->depth() >= depth - 3)
{
Value singularBeta = ttValue - (66 + 58 * (ss->ttPv && !PvNode)) * depth / 64;
// Bonus for prior countermove that caused the fail low
else if (!priorCapture && prevSq != SQ_NONE)
{
- int bonus = (depth > 6) + (PvNode || cutNode) + (bestValue < alpha - 656)
+ int bonus = (depth > 6) + (PvNode || cutNode) + ((ss - 1)->statScore < -18782)
+ ((ss - 1)->moveCount > 10);
update_continuation_histories(ss - 1, pos.piece_on(prevSq), prevSq,
stat_bonus(depth) * bonus);
ss->staticEval = bestValue =
(ss - 1)->currentMove != MOVE_NULL ? evaluate(pos) : -(ss - 1)->staticEval;
- // Stand pat. Return immediately if bestValue is at least beta at non-Pv nodes.
- // At PvNodes set bestValue between alpha and beta instead
+ // Stand pat. Return immediately if static value is at least beta
if (bestValue >= beta)
{
- 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);
+ if (!ss->ttHit)
+ tte->save(posKey, value_to_tt(bestValue, ss->ply), false, BOUND_LOWER, DEPTH_NONE,
+ MOVE_NONE, ss->staticEval);
- return bestValue;
- }
- bestValue = std::min((alpha + beta) / 2, beta - 1);
+ return bestValue;
}
if (bestValue > alpha)
return mated_in(ss->ply); // Plies to mate from the root
}
+ if (abs(bestValue) < VALUE_TB_WIN_IN_MAX_PLY)
+ bestValue = bestValue >= beta ? (3 * bestValue + beta) / 4 : bestValue;
+
// Save gathered info in transposition table
tte->save(posKey, value_to_tt(bestValue, ss->ply), pvHit,
bestValue >= beta ? BOUND_LOWER : BOUND_UPPER, ttDepth, bestMove, ss->staticEval);
if (v == -VALUE_INFINITE)
v = VALUE_ZERO;
- bool tb = TB::RootInTB && abs(v) <= VALUE_TB;
+ bool tb = TB::RootInTB && std::abs(v) <= VALUE_TB;
v = tb ? rootMoves[i].tbScore : v;
if (ss.rdbuf()->in_avail()) // Not at first line