- ThreadsMgr.put_threads_to_sleep();
-
- return !Quit;
-}
-
-
-namespace {
-
- // id_loop() is the main iterative deepening loop. It calls root_search
- // repeatedly with increasing depth until the allocated thinking time has
- // been consumed, the user stops the search, or the maximum search depth is
- // reached.
-
- Value id_loop(const Position& pos, Move searchMoves[]) {
-
- Position p(pos, pos.thread());
- SearchStack ss[PLY_MAX_PLUS_2];
- Move pv[PLY_MAX_PLUS_2];
- Move EasyMove = MOVE_NONE;
- Value value, alpha = -VALUE_INFINITE, beta = VALUE_INFINITE;
-
- // Moves to search are verified, copied, scored and sorted
- RootMoveList rml(p, searchMoves);
-
- // Handle special case of searching on a mate/stale position
- if (rml.move_count() == 0)
- {
- if (PonderSearch)
- wait_for_stop_or_ponderhit();
-
- return pos.is_check() ? -VALUE_MATE : VALUE_DRAW;
- }
-
- // Print RootMoveList startup scoring to the standard output,
- // so to output information also for iteration 1.
- cout << set960(p.is_chess960()) // Is enough to set once at the beginning
- << "info depth " << 1
- << "\ninfo depth " << 1
- << " score " << value_to_uci(rml.move_score(0))
- << " time " << current_search_time()
- << " nodes " << ThreadsMgr.nodes_searched()
- << " nps " << nps()
- << " pv " << rml.move(0) << "\n";
-
- // Initialize
- TT.new_search();
- H.clear();
- init_ss_array(ss, PLY_MAX_PLUS_2);
- pv[0] = pv[1] = MOVE_NONE;
- ValueByIteration[1] = rml.move_score(0);
- Iteration = 1;
-
- // Is one move significantly better than others after initial scoring ?
- if ( rml.move_count() == 1
- || rml.move_score(0) > rml.move_score(1) + EasyMoveMargin)
- EasyMove = rml.move(0);
-
- // Iterative deepening loop
- while (Iteration < PLY_MAX)
- {
- // Initialize iteration
- Iteration++;
- BestMoveChangesByIteration[Iteration] = 0;
-
- cout << "info depth " << Iteration << endl;
-
- // Calculate dynamic aspiration window based on previous iterations
- if (MultiPV == 1 && Iteration >= 6 && abs(ValueByIteration[Iteration - 1]) < VALUE_KNOWN_WIN)
- {
- int prevDelta1 = ValueByIteration[Iteration - 1] - ValueByIteration[Iteration - 2];
- int prevDelta2 = ValueByIteration[Iteration - 2] - ValueByIteration[Iteration - 3];
-
- AspirationDelta = Max(abs(prevDelta1) + abs(prevDelta2) / 2, 16);
- AspirationDelta = (AspirationDelta + 7) / 8 * 8; // Round to match grainSize
-
- alpha = Max(ValueByIteration[Iteration - 1] - AspirationDelta, -VALUE_INFINITE);
- beta = Min(ValueByIteration[Iteration - 1] + AspirationDelta, VALUE_INFINITE);
- }
-
- // Search to the current depth, rml is updated and sorted, alpha and beta could change
- value = root_search(p, ss, pv, rml, &alpha, &beta);