Color RootColor;
Time::point SearchTime;
StateStackPtr SetupStates;
- Value Contempt[2]; // [bestValue > VALUE_DRAW]
}
using std::string;
RootColor = RootPos.side_to_move();
TimeMgr.init(Limits, RootPos.game_ply(), RootColor);
- DrawValue[0] = DrawValue[1] = VALUE_DRAW;
- Contempt[0] = Options["Contempt Factor"] * PawnValueEg / 100; // From centipawns
- Contempt[1] = (Options["Contempt Factor"] + 12) * PawnValueEg / 100;
+ int cf = Options["Contempt Factor"] * PawnValueEg / 100; // From centipawns
+ DrawValue[ RootColor] = VALUE_DRAW - Value(cf);
+ DrawValue[~RootColor] = VALUE_DRAW + Value(cf);
if (RootMoves.empty())
{
{
bestValue = search<Root>(pos, ss, alpha, beta, depth * ONE_PLY, false);
- DrawValue[ RootColor] = VALUE_DRAW - Contempt[bestValue > VALUE_DRAW];
- DrawValue[~RootColor] = VALUE_DRAW + Contempt[bestValue > VALUE_DRAW];
-
// Bring the best move to the front. It is critical that sorting
// is done with a stable algorithm because all the values but the
// first and eventually the new best one are set to -VALUE_INFINITE
alpha = splitPoint->alpha;
}
- // Finished searching the move. If Signals.stop is true, the search
- // was aborted because the user interrupted the search or because we
- // ran out of time. In this case, the return value of the search cannot
- // be trusted, and we don't update the best move and/or PV.
+ // Finished searching the move. If a stop or a cutoff occurred, the return
+ // value of the search cannot be trusted, and we return immediately without
+ // updating best move, PV and TT.
if (Signals.stop || thisThread->cutoff_occurred())
- return value; // To avoid returning VALUE_INFINITE
+ return VALUE_ZERO;
if (RootNode)
{
&& Threads.available_slave(thisThread)
&& thisThread->splitPointsSize < MAX_SPLITPOINTS_PER_THREAD)
{
- assert(bestValue < beta);
+ assert(bestValue > -VALUE_INFINITE && bestValue < beta);
thisThread->split<FakeSplit>(pos, ss, alpha, beta, &bestValue, &bestMove,
depth, moveCount, &mp, NT, cutNode);
+
+ if (Signals.stop || thisThread->cutoff_occurred())
+ return VALUE_ZERO;
+
if (bestValue >= beta)
break;
}
if (SpNode)
return bestValue;
+ // Following condition would detect a stop or a cutoff set only after move
+ // loop has been completed. But in this case bestValue is valid because we
+ // have fully searched our subtree, and we can anyhow save the result in TT.
+ /*
+ if (Signals.stop || thisThread->cutoff_occurred())
+ return VALUE_DRAW;
+ */
+
// Step 20. Check for mate and stalemate
// All legal moves have been searched and if there are no legal moves, it
- // must be mate or stalemate. Note that we can have a false positive in
- // case of Signals.stop or thread.cutoff_occurred() are set, but this is
- // harmless because return value is discarded anyhow in the parent nodes.
- // If we are in a singular extension search then return a fail low score.
- // A split node has at least one move - the one tried before to be split.
+ // must be mate or stalemate. If we are in a singular extension search then
+ // return a fail low score.
if (!moveCount)
return excludedMove ? alpha
: inCheck ? mated_in(ss->ply) : DrawValue[pos.side_to_move()];
- // If we have pruned all the moves without searching return a fail-low score
- if (bestValue == -VALUE_INFINITE)
- bestValue = alpha;
-
TT.store(posKey, value_to_tt(bestValue, ss->ply),
bestValue >= beta ? BOUND_LOWER :
PvNode && bestMove ? BOUND_EXACT : BOUND_UPPER,