int MultiPV;
// Time managment variables
- int SearchStartTime, MaxNodes, MaxDepth, MaxSearchTime;
- int AbsoluteMaxSearchTime, ExtraSearchTime, ExactMaxTime;
+ int SearchStartTime, MaxNodes, MaxDepth, OptimumSearchTime;
+ int MaximumSearchTime, ExtraSearchTime, ExactMaxTime;
bool UseTimeManagement, InfiniteSearch, PonderSearch, StopOnPonderhit;
bool FirstRootMove, AbortSearch, Quit, AspirationFailLow;
// Initialize global search variables
StopOnPonderhit = AbortSearch = Quit = AspirationFailLow = false;
- MaxSearchTime = AbsoluteMaxSearchTime = ExtraSearchTime = 0;
+ OptimumSearchTime = MaximumSearchTime = ExtraSearchTime = 0;
NodesSincePoll = 0;
TM.resetNodeCounters();
SearchStartTime = get_system_time();
int myIncrement = increment[pos.side_to_move()];
if (UseTimeManagement)
{
- calc_search_times(myTime, myIncrement, movesToGo, pos.startpos_ply_counter(), MaxSearchTime, AbsoluteMaxSearchTime);
+ get_search_times(myTime, myIncrement, movesToGo, pos.startpos_ply_counter(),
+ &OptimumSearchTime, &MaximumSearchTime);
if (get_option_value_bool("Ponder"))
{
- MaxSearchTime += MaxSearchTime / 4;
- MaxSearchTime = Min(MaxSearchTime, AbsoluteMaxSearchTime);
+ OptimumSearchTime += OptimumSearchTime / 4;
+ OptimumSearchTime = Min(OptimumSearchTime, MaximumSearchTime);
}
}
if ( Iteration >= 8
&& EasyMove == pv[0]
&& ( ( rml.get_move_cumulative_nodes(0) > (nodes * 85) / 100
- && current_search_time() > MaxSearchTime / 16)
+ && current_search_time() > OptimumSearchTime / 16)
||( rml.get_move_cumulative_nodes(0) > (nodes * 98) / 100
- && current_search_time() > MaxSearchTime / 32)))
+ && current_search_time() > OptimumSearchTime / 32)))
stopSearch = true;
// Add some extra time if the best move has changed during the last two iterations
if (Iteration > 5 && Iteration <= 50)
- ExtraSearchTime = BestMoveChangesByIteration[Iteration] * (MaxSearchTime / 2)
- + BestMoveChangesByIteration[Iteration-1] * (MaxSearchTime / 3);
+ ExtraSearchTime = BestMoveChangesByIteration[Iteration] * (OptimumSearchTime / 2)
+ + BestMoveChangesByIteration[Iteration-1] * (OptimumSearchTime / 3);
// 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() > ((MaxSearchTime + ExtraSearchTime) * 80) / 128)
+ if (current_search_time() > ((OptimumSearchTime + ExtraSearchTime) * 80) / 128)
stopSearch = true;
if (stopSearch)
Move movesSearched[256];
EvalInfo ei;
StateInfo st;
- const TTEntry* tte;
+ const TTEntry *tte, *ttx;
Key posKey;
Move ttMove, move, excludedMove, threatMove;
Depth ext, newDepth;
&& is_lower_bound(tte->type())
&& tte->depth() >= depth - 3 * OnePly;
- // Avoid to do an expensive singular extension search on nodes where
- // such search had already failed in the past.
- if ( !PvNode
- && singularExtensionNode
- && depth < SingularExtensionDepth[PvNode] + 5 * OnePly)
- {
- TTEntry* ttx = TT.retrieve(pos.get_exclusion_key());
- if (ttx && is_lower_bound(ttx->type()))
- singularExtensionNode = false;
- }
-
// Step 10. Loop through moves
// Loop through all legal moves until no moves remain or a beta cutoff occurs
while ( bestValue < beta
&& move == tte->move()
&& ext < OnePly)
{
+ // Avoid to do an expensive singular extension search on nodes where
+ // such search have already been done in the past, so assume the last
+ // singular extension search result is still valid.
+ if ( !PvNode
+ && depth < SingularExtensionDepth[PvNode] + 5 * OnePly
+ && ((ttx = TT.retrieve(pos.get_exclusion_key())) != NULL))
+ {
+ if (is_upper_bound(ttx->type()))
+ ext = OnePly;
+
+ singularExtensionNode = false;
+ }
+
Value ttValue = value_from_tt(tte->value(), ply);
- if (abs(ttValue) < VALUE_KNOWN_WIN)
+ if (singularExtensionNode && abs(ttValue) < VALUE_KNOWN_WIN)
{
Value b = ttValue - SingularExtensionMargin;
ss->excludedMove = move;
bool stillAtFirstMove = FirstRootMove
&& !AspirationFailLow
- && t > MaxSearchTime + ExtraSearchTime;
+ && t > OptimumSearchTime + ExtraSearchTime;
- bool noMoreTime = t > AbsoluteMaxSearchTime
+ bool noMoreTime = t > MaximumSearchTime
|| stillAtFirstMove;
if ( (Iteration >= 3 && UseTimeManagement && noMoreTime)
bool stillAtFirstMove = FirstRootMove
&& !AspirationFailLow
- && t > MaxSearchTime + ExtraSearchTime;
+ && t > OptimumSearchTime + ExtraSearchTime;
- bool noMoreTime = t > AbsoluteMaxSearchTime
+ bool noMoreTime = t > MaximumSearchTime
|| stillAtFirstMove;
if (Iteration >= 3 && UseTimeManagement && (noMoreTime || StopOnPonderhit))