// Sort the PV lines searched so far and update the GUI
sort<RootMove>(RootMoves.begin(), RootMoves.begin() + PVIdx + 1);
- sync_cout << uci_pv(pos, depth, alpha, beta) << sync_endl;
+ if (PVIdx + 1 == PVSize || Time::now() - SearchTime > 3000)
+ sync_cout << uci_pv(pos, depth, alpha, beta) << sync_endl;
}
// Do we need to pick now the sub-optimal best move ?
// Step 5. Evaluate the position statically and update parent's gain statistics
if (inCheck)
ss->staticEval = ss->evalMargin = eval = VALUE_NONE;
-
- else if (tte)
+ else
{
- // Following asserts are valid only in single thread condition because
- // TT access is always racy and its contents cannot be trusted.
- assert(tte->static_value() != VALUE_NONE || Threads.size() > 1);
- assert(ttValue != VALUE_NONE || tte->type() == BOUND_NONE || Threads.size() > 1);
-
- ss->staticEval = eval = tte->static_value();
- ss->evalMargin = tte->static_value_margin();
-
- if (eval == VALUE_NONE || ss->evalMargin == VALUE_NONE) // Due to a race
- eval = ss->staticEval = evaluate(pos, ss->evalMargin);
+ eval = ss->staticEval = evaluate(pos, ss->evalMargin);
// Can ttValue be used as a better position evaluation?
- if (ttValue != VALUE_NONE)
+ if (tte && ttValue != VALUE_NONE)
+ {
if ( ((tte->type() & BOUND_LOWER) && ttValue > eval)
|| ((tte->type() & BOUND_UPPER) && ttValue < eval))
eval = ttValue;
- }
- else
- {
- eval = ss->staticEval = evaluate(pos, ss->evalMargin);
- TT.store(posKey, VALUE_NONE, BOUND_NONE, DEPTH_NONE, MOVE_NONE,
- ss->staticEval, ss->evalMargin);
+ }
}
// Update gain for the parent non-capture move given the static position
{
Signals.firstRootMove = (moveCount == 1);
- if (thisThread == Threads.main_thread() && Time::now() - SearchTime > 2000)
+ if (thisThread == Threads.main_thread() && Time::now() - SearchTime > 3000)
sync_cout << "info depth " << depth / ONE_PLY
<< " currmove " << move_to_uci(move, pos.is_chess960())
<< " currmovenumber " << moveCount + PVIdx << sync_endl;
}
// Check for legality only before to do the move
- if (!pos.pl_move_is_legal(move, ci.pinned))
+ if (!RootNode && !SpNode && !pos.pl_move_is_legal(move, ci.pinned))
{
moveCount--;
continue;
if (bestValue >= beta) // Failed high
{
- TT.store(posKey, value_to_tt(bestValue, ss->ply), BOUND_LOWER, depth,
- bestMove, ss->staticEval, ss->evalMargin);
+ TT.store(posKey, value_to_tt(bestValue, ss->ply), BOUND_LOWER, depth, bestMove);
if (!pos.is_capture_or_promotion(bestMove) && !inCheck)
{
else // Failed low or PV search
TT.store(posKey, value_to_tt(bestValue, ss->ply),
PvNode && bestMove != MOVE_NONE ? BOUND_EXACT : BOUND_UPPER,
- depth, bestMove, ss->staticEval, ss->evalMargin);
+ depth, bestMove);
assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);
{
if (fromNull)
{
+ // Approximated score. Real one is slightly higher due to tempo
ss->staticEval = bestValue = -(ss-1)->staticEval;
ss->evalMargin = VALUE_ZERO;
}
- else if (tte)
- {
- assert(tte->static_value() != VALUE_NONE || Threads.size() > 1);
-
- ss->staticEval = bestValue = tte->static_value();
- ss->evalMargin = tte->static_value_margin();
-
- if (ss->staticEval == VALUE_NONE || ss->evalMargin == VALUE_NONE) // Due to a race
- ss->staticEval = bestValue = evaluate(pos, ss->evalMargin);
- }
else
ss->staticEval = bestValue = evaluate(pos, ss->evalMargin);
if (bestValue >= beta)
{
if (!tte)
- TT.store(pos.key(), value_to_tt(bestValue, ss->ply), BOUND_LOWER,
- DEPTH_NONE, MOVE_NONE, ss->staticEval, ss->evalMargin);
+ TT.store(pos.key(), value_to_tt(bestValue, ss->ply), BOUND_LOWER, DEPTH_NONE, MOVE_NONE);
return bestValue;
}
// Futility pruning
if ( !PvNode
&& !InCheck
- && !givesCheck
&& !fromNull
+ && !givesCheck
&& move != ttMove
&& enoughMaterial
&& type_of(move) != PROMOTION
if (futilityValue < beta)
{
- if (futilityValue > bestValue)
- bestValue = futilityValue;
-
+ bestValue = std::max(bestValue, futilityValue);
continue;
}
if ( futilityBase < beta
&& depth < DEPTH_ZERO
&& pos.see(move) <= 0)
+ {
+ bestValue = std::max(bestValue, futilityBase);
continue;
+ }
}
// Detect non-capture evasions that are candidate to be pruned
}
else // Fail high
{
- TT.store(posKey, value_to_tt(value, ss->ply), BOUND_LOWER,
- ttDepth, move, ss->staticEval, ss->evalMargin);
-
+ TT.store(posKey, value_to_tt(value, ss->ply), BOUND_LOWER, ttDepth, move);
return value;
}
}
TT.store(posKey, value_to_tt(bestValue, ss->ply),
PvNode && bestValue > oldAlpha ? BOUND_EXACT : BOUND_UPPER,
- ttDepth, bestMove, ss->staticEval, ss->evalMargin);
+ ttDepth, bestMove);
assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);
StateInfo state[MAX_PLY_PLUS_2], *st = state;
TTEntry* tte;
int ply = 0;
- Value v, m;
do {
tte = TT.probe(pos.key());
if (!tte || tte->move() != pv[ply]) // Don't overwrite correct entries
- {
- if (pos.in_check())
- v = m = VALUE_NONE;
- else
- v = evaluate(pos, m);
-
- TT.store(pos.key(), VALUE_NONE, BOUND_NONE, DEPTH_NONE, pv[ply], v, m);
- }
+ TT.store(pos.key(), VALUE_NONE, BOUND_NONE, DEPTH_NONE, pv[ply]);
assert(pos.move_is_legal(pv[ply]));
pos.do_move(pv[ply++], *st++);