- }
-
- if (StopRequest)
- break; // Value cannot be trusted. Break out immediately!
-
- //Save info about search result
- ValueByIteration[Iteration] = value;
-
- // Drop the easy move if differs from the new best move
- if (rml[0].pv[0] != EasyMove)
- EasyMove = MOVE_NONE;
-
- if (UseTimeManagement)
- {
- // Time to stop?
- bool stopSearch = false;
-
- // Stop search early if there is only a single legal move,
- // we search up to Iteration 6 anyway to get a proper score.
- if (Iteration >= 6 && rml.size() == 1)
- stopSearch = true;
-
- // Stop search early when the last two iterations returned a mate score
- if ( Iteration >= 6
- && abs(ValueByIteration[Iteration]) >= abs(VALUE_MATE) - 100
- && abs(ValueByIteration[Iteration-1]) >= abs(VALUE_MATE) - 100)
- stopSearch = true;
-
- // Stop search early if one move seems to be much better than the others
- if ( Iteration >= 8
- && EasyMove == rml[0].pv[0]
- && ( ( rml[0].nodes > (pos.nodes_searched() * 85) / 100
- && current_search_time() > TimeMgr.available_time() / 16)
- ||( rml[0].nodes > (pos.nodes_searched() * 98) / 100
- && current_search_time() > TimeMgr.available_time() / 32)))
- stopSearch = true;
-
- // Add some extra time if the best move has changed during the last two iterations
- if (Iteration > 5 && Iteration <= 50)
- TimeMgr.pv_instability(BestMoveChangesByIteration[Iteration],
- BestMoveChangesByIteration[Iteration-1]);
-
- // Stop search if most of MaxSearchTime is consumed at the end of the
- // iteration. We probably don't have enough time to search the first
- // move at the next iteration anyway.
- if (current_search_time() > (TimeMgr.available_time() * 80) / 128)
- stopSearch = true;
-
- if (stopSearch)
- {
- 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) {