- // Start with a small aspiration window and, in the case of a fail
- // high/low, re-search with a bigger window until we're not failing
- // high/low anymore.
- while (true)
- {
- bestValue = search<Root, false>(pos, ss, alpha, beta, depth, false);
-
- // 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
- // and we want to keep the same order for all the moves except the
- // new PV that goes to the front. Note that in case of MultiPV
- // search the already searched PV lines are preserved.
- std::stable_sort(RootMoves.begin() + PVIdx, RootMoves.end());
-
- // 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)
- RootMoves[i].insert_pv_in_tt(pos);
-
- // If search has been stopped break immediately. Sorting and
- // writing PV back to TT is safe because RootMoves is still
- // valid, although it refers to previous iteration.
- if (Signals.stop)
- break;
-
- // When failing high/low give some update (without cluttering
- // the UI) before a re-search.
- if ( (bestValue <= alpha || bestValue >= beta)
- && Time::now() - SearchTime > 3000)
- sync_cout << uci_pv(pos, depth, alpha, beta) << sync_endl;
-
- // In case of failing low/high increase aspiration window and
- // re-search, otherwise exit the loop.
- if (bestValue <= alpha)
- {
- beta = (alpha + beta) / 2;
- alpha = std::max(bestValue - delta, -VALUE_INFINITE);
-
- Signals.failedLowAtRoot = true;
- Signals.stopOnPonderhit = false;
- }
- else if (bestValue >= beta)
- {
- alpha = (alpha + beta) / 2;
- beta = std::min(bestValue + delta, VALUE_INFINITE);
- }
- else
- break;
-
- delta += delta / 2;
-
- assert(alpha >= -VALUE_INFINITE && beta <= VALUE_INFINITE);
- }
+ // MultiPV loop. We perform a full root search for each PV line
+ for (PVIdx = 0; PVIdx < multiPV && !Signals.stop; ++PVIdx)
+ {
+ // Reset aspiration window starting size
+ if (rootDepth >= 5 * ONE_PLY)
+ {
+ delta = Value(18);
+ alpha = std::max(rootMoves[PVIdx].previousScore - delta,-VALUE_INFINITE);
+ beta = std::min(rootMoves[PVIdx].previousScore + delta, VALUE_INFINITE);
+ }