uint64_t perft(Position& pos, Depth depth) {
StateInfo st;
+ ASSERT_ALIGNED(&st, Eval::NNUE::kCacheLineSize);
+
uint64_t cnt, nodes = 0;
const bool leaf = (depth == 2);
}
double bestMoveInstability = 1 + 2 * totBestMoveChanges / Threads.size();
- double totalTime = rootMoves.size() == 1 ? 0 :
- Time.optimum() * fallingEval * reduction * bestMoveInstability;
+ double totalTime = Time.optimum() * fallingEval * reduction * bestMoveInstability;
+
+ // Cap used time in case of a single legal move for a better viewer experience in tournaments
+ // yielding correct scores and sufficiently fast moves.
+ if (rootMoves.size() == 1)
+ totalTime = std::min(500.0, totalTime);
- // Stop the search if we have exceeded the totalTime, at least 1ms search
+ // Stop the search if we have exceeded the totalTime
if (Time.elapsed() > totalTime)
{
// If we are allowed to ponder do not stop the search now but
constexpr bool PvNode = NT == PV;
const bool rootNode = PvNode && ss->ply == 0;
+ const Depth maxNextDepth = rootNode ? depth : depth + 1;
// Check if we have an upcoming move which draws by repetition, or
// if the opponent had an alternative move earlier to this position.
Move pv[MAX_PLY+1], capturesSearched[32], quietsSearched[64];
StateInfo st;
+ ASSERT_ALIGNED(&st, Eval::NNUE::kCacheLineSize);
+
TTEntry* tte;
Key posKey;
Move ttMove, move, excludedMove, bestMove;
(ss+1)->pv = pv;
(ss+1)->pv[0] = MOVE_NONE;
- value = -search<PV>(pos, ss+1, -beta, -alpha, newDepth, false);
+ value = -search<PV>(pos, ss+1, -beta, -alpha,
+ std::min(maxNextDepth, newDepth), false);
}
// Step 18. Undo move
Move pv[MAX_PLY+1];
StateInfo st;
+ ASSERT_ALIGNED(&st, Eval::NNUE::kCacheLineSize);
+
TTEntry* tte;
Key posKey;
Move ttMove, move, bestMove;
// CounterMove based pruning
if ( !captureOrPromotion
- && moveCount
+ && bestValue > VALUE_TB_LOSS_IN_MAX_PLY
&& (*contHist[0])[pos.moved_piece(move)][to_sq(move)] < CounterMovePruneThreshold
&& (*contHist[1])[pos.moved_piece(move)][to_sq(move)] < CounterMovePruneThreshold)
continue;
// All legal moves have been searched. A special case: if we're in check
// and no legal moves were found, it is checkmate.
if (ss->inCheck && bestValue == -VALUE_INFINITE)
+ {
+ assert(!MoveList<LEGAL>(pos).size());
+
return mated_in(ss->ply); // Plies to mate from the root
+ }
tte->save(posKey, value_to_tt(bestValue, ss->ply), pvHit,
bestValue >= beta ? BOUND_LOWER :
bool RootMove::extract_ponder_from_tt(Position& pos) {
StateInfo st;
+ ASSERT_ALIGNED(&st, Eval::NNUE::kCacheLineSize);
+
bool ttHit;
assert(pv.size() == 1);