- if (Pondering)
- StopOnPonderhit = true;
- else
- break;
- }
- }
-
- if (MaxDepth && Iteration >= MaxDepth)
- break;
- }
-
- *ponderMove = rml[0].pv[1];
- return rml[0].pv[0];
- }
-
-
- // root_search() is the function which searches the root node. It is
- // similar to search_pv except that it prints some information to the
- // standard output and handles the fail low/high loops.
-
- Value root_search(Position& pos, SearchStack* ss, Value alpha,
- Value beta, Depth depth, RootMoveList& rml) {
-
- assert(alpha >= -VALUE_INFINITE && alpha <= VALUE_INFINITE);
- assert(beta > alpha && beta <= VALUE_INFINITE);
- assert(pos.thread() >= 0 && pos.thread() < ThreadsMgr.active_threads());
-
- Move movesSearched[MOVES_MAX];
- StateInfo st;
- Key posKey;
- Move move;
- Depth ext, newDepth;
- ValueType vt;
- Value bestValue, value, oldAlpha;
- bool isCheck, moveIsCheck, captureOrPromotion, dangerous, isPvMove;
- int moveCount = 0;
-
- bestValue = value = -VALUE_INFINITE;
- oldAlpha = alpha;
- isCheck = pos.is_check();
-
- // Step 1. Initialize node (polling is omitted at root)
- ss->currentMove = ss->bestMove = MOVE_NONE;
- (ss+2)->killers[0] = (ss+2)->killers[1] = (ss+2)->mateKiller = MOVE_NONE;
-
- // Step 2. Check for aborted search (omitted at root)
- // Step 3. Mate distance pruning (omitted at root)
- // Step 4. Transposition table lookup (omitted at root)
- posKey = pos.get_key();
-
- // Step 5. Evaluate the position statically
- // At root we do this only to get reference value for child nodes
- ss->evalMargin = VALUE_NONE;
- ss->eval = isCheck ? VALUE_NONE : evaluate(pos, ss->evalMargin);
-
- // Step 6. Razoring (omitted at root)
- // Step 7. Static null move pruning (omitted at root)
- // Step 8. Null move search with verification search (omitted at root)
- // Step 9. Internal iterative deepening (omitted at root)
-
- CheckInfo ci(pos);
- int64_t nodes;
- RootMoveList::iterator rm = rml.begin();
- bestValue = alpha;
-
- // Step 10. Loop through moves
- // Loop through all legal moves until no moves remain or a beta cutoff occurs
- while ( bestValue < beta
- && rm != rml.end()
- && !StopRequest)
- {
- move = ss->currentMove = rm->pv[0];
- movesSearched[moveCount++] = move;
- isPvMove = (moveCount <= MultiPV);
-
- // This is used by time management
- FirstRootMove = (rm == rml.begin());
-
- // Save the current node count before the move is searched
- nodes = pos.nodes_searched();
-
- // If it's time to send nodes info, do it here where we have the
- // correct accumulated node counts searched by each thread.
- if (SendSearchedNodes)
- {
- SendSearchedNodes = false;
- cout << "info nodes " << nodes
- << " nps " << nps(pos)
- << " time " << current_search_time() << endl;
- }
-
- if (current_search_time() >= 1000)
- cout << "info currmove " << move
- << " currmovenumber " << moveCount << endl;
-
- moveIsCheck = pos.move_is_check(move);
- captureOrPromotion = pos.move_is_capture_or_promotion(move);
-
- // Step 11. Decide the new search depth
- ext = extension<PV>(pos, move, captureOrPromotion, moveIsCheck, false, false, &dangerous);
- newDepth = depth + ext;
-
- // Step 12. Futility pruning (omitted at root)
- // Step 13. Make the move
- pos.do_move(move, st, ci, moveIsCheck);
-
- // Step extra. pv search
- // We do pv search for PV moves
- if (isPvMove)
- {
- // Aspiration window is disabled in multi-pv case
- if (MultiPV > 1)