}
// Reset the threads, still sleeping: will be wake up at split time
- for (size_t i = 0; i < Threads.size(); i++)
+ for (size_t i = 0; i < Threads.size(); ++i)
Threads[i]->maxPly = 0;
Threads.sleepWhileIdle = Options["Idle Threads Sleep"];
// Set best timer interval to avoid lagging under time pressure. Timer is
- // used to check for remaining available thinking time. Timer will be started
- // at the end of first iteration to avoid returning with a random move.
+ // used to check for remaining available thinking time.
Threads.timer->msec =
Limits.use_time_management() ? std::min(100, std::max(TimeMgr.available_time() / 16, TimerResolution)) :
- Limits.nodes ? 2 * TimerResolution : 100;
+ Limits.nodes ? 2 * TimerResolution
+ : 100;
+
+ Threads.timer->notify_one(); // Wake up the recurring timer
id_loop(RootPos); // Let's start searching !
// Save last iteration's scores before first PV line is searched and all
// the move scores but the (new) PV are set to -VALUE_INFINITE.
- for (size_t i = 0; i < RootMoves.size(); i++)
+ for (size_t i = 0; i < RootMoves.size(); ++i)
RootMoves[i].prevScore = RootMoves[i].score;
// MultiPV loop. We perform a full root search for each PV line
// Write PV back to transposition table in case the relevant
// entries have been overwritten during the search.
- for (size_t i = 0; i <= PVIdx; i++)
+ for (size_t i = 0; i <= PVIdx; ++i)
RootMoves[i].insert_pv_in_tt(pos);
// If search has been stopped return immediately. Sorting and
assert(alpha >= -VALUE_INFINITE && beta <= VALUE_INFINITE);
}
- // Wake up the recurring timer after first iteration is finished
- if (depth == 1)
- Threads.timer->notify_one();
-
// Sort the PV lines searched so far and update the GUI
std::stable_sort(RootMoves.begin(), RootMoves.begin() + PVIdx + 1);
ext = ONE_PLY;
else if (givesCheck && pos.see_sign(move) >= 0)
- ext = ONE_PLY / 2;
+ ext = inCheck || ss->staticEval <= alpha ? ONE_PLY : ONE_PLY / 2;
// Singular extension search. If all moves but one fail low on a search of
// (alpha-s, beta-s), and just one fails high on (alpha, beta), then that move
// played non-capture moves.
Value bonus = Value(int(depth) * int(depth));
History.update(pos.piece_moved(bestMove), to_sq(bestMove), bonus);
- for (int i = 0; i < quietCount - 1; i++)
+ for (int i = 0; i < quietCount - 1; ++i)
{
Move m = quietsSearched[i];
History.update(pos.piece_moved(m), to_sq(m), -bonus);
// Choose best move. For each move score we add two terms both dependent on
// weakness, one deterministic and bigger for weaker moves, and one random,
// then we choose the move with the resulting highest score.
- for (size_t i = 0; i < PVSize; i++)
+ for (size_t i = 0; i < PVSize; ++i)
{
int s = RootMoves[i].score;
size_t uciPVSize = std::min((size_t)Options["MultiPV"], RootMoves.size());
int selDepth = 0;
- for (size_t i = 0; i < Threads.size(); i++)
+ for (size_t i = 0; i < Threads.size(); ++i)
if (Threads[i]->maxPly > selDepth)
selDepth = Threads[i]->maxPly;
- for (size_t i = 0; i < uciPVSize; i++)
+ for (size_t i = 0; i < uciPVSize; ++i)
{
bool updated = (i <= PVIdx);
// Loop across all split points and sum accumulated SplitPoint nodes plus
// all the currently active positions nodes.
- for (size_t i = 0; i < Threads.size(); i++)
+ for (size_t i = 0; i < Threads.size(); ++i)
for (int j = 0; j < Threads[i]->splitPointsSize; j++)
{
SplitPoint& sp = Threads[i]->splitPoints[j];