votes[th->rootMoves[0].pv[0]] +=
(th->rootMoves[0].score - minScore + 14) * int(th->completedDepth);
- if (bestThread->rootMoves[0].score >= VALUE_MATE_IN_MAX_PLY)
+ if (bestThread->rootMoves[0].score >= VALUE_TB_WIN_IN_MAX_PLY)
{
// Make sure we pick the shortest mate
if (th->rootMoves[0].score > bestThread->rootMoves[0].score)
bestThread = th;
}
- else if ( th->rootMoves[0].score >= VALUE_MATE_IN_MAX_PLY
+ else if ( th->rootMoves[0].score >= VALUE_TB_WIN_IN_MAX_PLY
|| votes[th->rootMoves[0].pv[0]] > votes[bestThread->rootMoves[0].pv[0]])
bestThread = th;
}
int drawScore = TB::UseRule50 ? 1 : 0;
- value = wdl < -drawScore ? -VALUE_MATE + MAX_PLY + ss->ply + 1
- : wdl > drawScore ? VALUE_MATE - MAX_PLY - ss->ply - 1
- : VALUE_DRAW + 2 * wdl * drawScore;
+ // use the range VALUE_MATE_IN_MAX_PLY to VALUE_TB_WIN_IN_MAX_PLY to score
+ value = wdl < -drawScore ? VALUE_MATED_IN_MAX_PLY + ss->ply + 1
+ : wdl > drawScore ? VALUE_MATE_IN_MAX_PLY - ss->ply - 1
+ : VALUE_DRAW + 2 * wdl * drawScore;
Bound b = wdl < -drawScore ? BOUND_UPPER
: wdl > drawScore ? BOUND_LOWER : BOUND_EXACT;
&& (ss-1)->statScore < 23397
&& eval >= beta
&& eval >= ss->staticEval
- && ss->staticEval >= beta - 32 * depth + 292 - improving * 30
+ && ss->staticEval >= beta - 32 * depth - 30 * improving + 120 * ttPv + 292
&& !excludedMove
&& pos.non_pawn_material(us)
&& (ss->ply >= thisThread->nmpMinPly || us != thisThread->nmpColor))
if (nullValue >= beta)
{
// Do not return unproven mate scores
- if (nullValue >= VALUE_MATE_IN_MAX_PLY)
+ if (nullValue >= VALUE_TB_WIN_IN_MAX_PLY)
nullValue = beta;
if (thisThread->nmpMinPly || (abs(beta) < VALUE_KNOWN_WIN && depth < 13))
// much above beta, we can (almost) safely prune the previous move.
if ( !PvNode
&& depth >= 5
- && abs(beta) < VALUE_MATE_IN_MAX_PLY)
+ && abs(beta) < VALUE_TB_WIN_IN_MAX_PLY)
{
Value raisedBeta = std::min(beta + 189 - 45 * improving, VALUE_INFINITE);
MovePicker mp(pos, ttMove, raisedBeta - ss->staticEval, &thisThread->captureHistory);
// Step 13. Pruning at shallow depth (~200 Elo)
if ( !rootNode
&& pos.non_pawn_material(us)
- && bestValue > VALUE_MATED_IN_MAX_PLY)
+ && bestValue > VALUE_TB_LOSS_IN_MAX_PLY)
{
// Skip quiet moves if movecount exceeds our FutilityMoveCount threshold
moveCountPruning = moveCount >= futility_move_count(improving, depth);
continue;
}
else if (!pos.see_ge(move, Value(-194) * depth)) // (~25 Elo)
- continue;
+ continue;
}
// Step 14. Extensions (~75 Elo)
&& tte->depth() >= depth - 3
&& pos.legal(move))
{
- Value singularBeta = ttValue - 2 * depth;
+ Value singularBeta = ttValue - (((ttPv && !PvNode) + 4) * depth) / 2;
Depth halfDepth = depth / 2;
ss->excludedMove = move;
value = search<NonPV>(pos, ss, singularBeta - 1, singularBeta, halfDepth, cutNode);
// Step 16. Reduced depth search (LMR, ~200 Elo). If the move fails high it will be
// re-searched at full depth.
if ( depth >= 3
- && moveCount > 1 + rootNode + (rootNode && bestValue < alpha)
+ && moveCount > 1 + 2 * rootNode
&& (!rootNode || thisThread->best_move_count(move) == 0)
&& ( !captureOrPromotion
|| moveCountPruning
// Detect non-capture evasions that are candidates to be pruned
evasionPrunable = inCheck
&& (depth != 0 || moveCount > 2)
- && bestValue > VALUE_MATED_IN_MAX_PLY
+ && bestValue > VALUE_TB_LOSS_IN_MAX_PLY
&& !pos.capture(move);
// Don't search moves with negative SEE values
}
- // value_to_tt() adjusts a mate score from "plies to mate from the root" to
- // "plies to mate from the current position". Non-mate scores are unchanged.
+ // value_to_tt() adjusts a mate or TB score from "plies to mate from the root" to
+ // "plies to mate from the current position". standard scores are unchanged.
// The function is called before storing a value in the transposition table.
Value value_to_tt(Value v, int ply) {
assert(v != VALUE_NONE);
- return v >= VALUE_MATE_IN_MAX_PLY ? v + ply
- : v <= VALUE_MATED_IN_MAX_PLY ? v - ply : v;
+ return v >= VALUE_TB_WIN_IN_MAX_PLY ? v + ply
+ : v <= VALUE_TB_LOSS_IN_MAX_PLY ? v - ply : v;
}
- // value_from_tt() is the inverse of value_to_tt(): It adjusts a mate score
+ // value_from_tt() is the inverse of value_to_tt(): It adjusts a mate or TB score
// from the transposition table (which refers to the plies to mate/be mated
- // from current position) to "plies to mate/be mated from the root".
+ // from current position) to "plies to mate/be mated (TB win/loss) from the root".
+ // However, for mate scores, to avoid potentially false mate scores related to the 50 moves rule,
+ // and the graph history interaction, return an optimal TB score instead.
Value value_from_tt(Value v, int ply, int r50c) {
- return v == VALUE_NONE ? VALUE_NONE
- : v >= VALUE_MATE_IN_MAX_PLY ? VALUE_MATE - v > 99 - r50c ? VALUE_MATE_IN_MAX_PLY : v - ply
- : v <= VALUE_MATED_IN_MAX_PLY ? VALUE_MATE + v > 99 - r50c ? VALUE_MATED_IN_MAX_PLY : v + ply : v;
+ if (v == VALUE_NONE)
+ return VALUE_NONE;
+
+ if (v >= VALUE_TB_WIN_IN_MAX_PLY) // TB win or better
+ {
+ if (v >= VALUE_MATE_IN_MAX_PLY && VALUE_MATE - v > 99 - r50c)
+ return VALUE_MATE_IN_MAX_PLY - 1; // do not return a potentially false mate score
+
+ return v - ply;
+ }
+
+ if (v <= VALUE_TB_LOSS_IN_MAX_PLY) // TB loss or worse
+ {
+ if (v <= VALUE_MATED_IN_MAX_PLY && VALUE_MATE + v > 99 - r50c)
+ return VALUE_MATED_IN_MAX_PLY + 1; // do not return a potentially false mate score
+
+ return v + ply;
+ }
+
+ return v;
}
Depth d = updated ? depth : depth - 1;
Value v = updated ? rootMoves[i].score : rootMoves[i].previousScore;
- bool tb = TB::RootInTB && abs(v) < VALUE_MATE - MAX_PLY;
+ bool tb = TB::RootInTB && abs(v) < VALUE_MATE_IN_MAX_PLY;
v = tb ? rootMoves[i].tbScore : v;
if (ss.rdbuf()->in_avail()) // Not at first line