- CheckExtension[1] = Options["Check Extension (PV nodes)"].value<Depth>();
- CheckExtension[0] = Options["Check Extension (non-PV nodes)"].value<Depth>();
- SingleEvasionExtension[1] = Options["Single Evasion Extension (PV nodes)"].value<Depth>();
- SingleEvasionExtension[0] = Options["Single Evasion Extension (non-PV nodes)"].value<Depth>();
- PawnPushTo7thExtension[1] = Options["Pawn Push to 7th Extension (PV nodes)"].value<Depth>();
- PawnPushTo7thExtension[0] = Options["Pawn Push to 7th Extension (non-PV nodes)"].value<Depth>();
- PassedPawnExtension[1] = Options["Passed Pawn Extension (PV nodes)"].value<Depth>();
- PassedPawnExtension[0] = Options["Passed Pawn Extension (non-PV nodes)"].value<Depth>();
- PawnEndgameExtension[1] = Options["Pawn Endgame Extension (PV nodes)"].value<Depth>();
- PawnEndgameExtension[0] = Options["Pawn Endgame Extension (non-PV nodes)"].value<Depth>();
- MateThreatExtension[1] = Options["Mate Threat Extension (PV nodes)"].value<Depth>();
- MateThreatExtension[0] = Options["Mate Threat Extension (non-PV nodes)"].value<Depth>();
- MultiPV = Options["MultiPV"].value<int>();
- UseLogFile = Options["Use Search Log"].value<bool>();
-
- if (UseLogFile)
- LogFile.open(Options["Search Log Filename"].value<std::string>().c_str(), std::ios::out | std::ios::app);
-
- read_weights(pos.side_to_move());
-
- // Set the number of active threads
- ThreadsMgr.read_uci_options();
- init_eval(ThreadsMgr.active_threads());
-
- // Wake up needed threads
- for (int i = 1; i < ThreadsMgr.active_threads(); i++)
- ThreadsMgr.wake_sleeping_thread(i);
-
- // Set thinking time
- int myTime = time[pos.side_to_move()];
- int myIncrement = increment[pos.side_to_move()];
- if (UseTimeManagement)
- TimeMgr.init(myTime, myIncrement, movesToGo, pos.startpos_ply_counter());
-
- // Set best NodesBetweenPolls interval to avoid lagging under
- // heavy time pressure.
- if (MaxNodes)
- NodesBetweenPolls = Min(MaxNodes, 30000);
- else if (myTime && myTime < 1000)
- NodesBetweenPolls = 1000;
- else if (myTime && myTime < 5000)
- NodesBetweenPolls = 5000;
- else
- NodesBetweenPolls = 30000;
-
- // Write search information to log file
- if (UseLogFile)
- LogFile << "Searching: " << pos.to_fen() << endl
- << "infinite: " << infinite
- << " ponder: " << ponder
- << " time: " << myTime
- << " increment: " << myIncrement
- << " moves to go: " << movesToGo << endl;
-
- // We're ready to start thinking. Call the iterative deepening loop function
- id_loop(pos, searchMoves);
-
- if (UseLogFile)
- LogFile.close();
-
- // This makes all the threads to go to sleep
- ThreadsMgr.set_active_threads(1);
-
- 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(Position& pos, Move searchMoves[]) {
-
- 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(pos, searchMoves);
-
- // Handle special case of searching on a mate/stale position
- if (rml.size() == 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(pos.is_chess960()) // Is enough to set once at the beginning
- << "info depth " << 1
- << "\ninfo depth " << 1
- << " score " << value_to_uci(rml[0].pv_score)
- << " time " << current_search_time()
- << " nodes " << pos.nodes_searched()
- << " nps " << nps(pos)
- << " pv " << rml[0].move << "\n";
-
- // Initialize
- TT.new_search();
- H.clear();
- init_ss_array(ss, PLY_MAX_PLUS_2);
- pv[0] = pv[1] = MOVE_NONE;
- ValueByIteration[1] = rml[0].pv_score;
- Iteration = 1;
-
- // Is one move significantly better than others after initial scoring ?
- if ( rml.size() == 1
- || rml[0].pv_score > rml[1].pv_score + EasyMoveMargin)
- EasyMove = rml[0].move;
-
- // Iterative deepening loop
- while (Iteration < PLY_MAX)
- {
- // Initialize iteration
- Iteration++;
- BestMoveChangesByIteration[Iteration] = 0;
-
- cout << "info depth " << Iteration << endl;