io-chess
UCI chess engine
Loading...
Searching...
No Matches
TimeManager Class Reference

Handles adaptive time allocation during search. More...

#include <TimeManager.h>

Collaboration diagram for TimeManager:

Classes

struct  TimeAllocation
 Recommended time limits for the current move. More...
struct  Config
 Tunable configuration for time management heuristics. More...

Public Types

enum class  TimeControl {
  BULLET , BLITZ , RAPID , CLASSICAL ,
  CORRESPONDENCE
}
 Categorization of time controls based on base time. More...

Public Member Functions

 TimeManager ()=default
 TimeManager (const Config &cfg)
TimeAllocation calculate (const SearchParams &params, chess::Color side, float phase, float evalCp, int moveNumber) const
 Calculates time allocation for a position.
bool shouldStop (int64_t elapsed, int depth, int bestMoveChanges, int scoreDrops, const TimeAllocation &allocation) const
 Checks if search should stop based on elapsed time and stability.
float getExtensionFactor (int bestMoveChanges, int scoreDrops) const
 Gets the extension factor based on search instability.
const Configconfig () const
void setConfig (const Config &cfg)

Private Member Functions

TimeControl detectTimeControl (int baseTimeMs, int incrementMs) const
float getPhaseMultiplier (float phase) const
float getEvalMultiplier (float evalCp) const
float getControlMultiplier (TimeControl control) const
int estimateMovesRemaining (int moveNumber, float phase, int movestogo) const

Private Attributes

Config config_

Detailed Description

Handles adaptive time allocation during search.

Member Enumeration Documentation

◆ TimeControl

enum class TimeManager::TimeControl
strong

Categorization of time controls based on base time.

Enumerator
BULLET 

< 2 minutes base

BLITZ 

2-5 minutes base

RAPID 

5-15 minutes base

CLASSICAL 

15 minutes base

CORRESPONDENCE 

1 hour or untimed

Constructor & Destructor Documentation

◆ TimeManager() [1/2]

TimeManager::TimeManager ( )
default

◆ TimeManager() [2/2]

TimeManager::TimeManager ( const Config & cfg)
inlineexplicit

Member Function Documentation

◆ calculate()

TimeManager::TimeAllocation TimeManager::calculate ( const SearchParams & params,
chess::Color side,
float phase,
float evalCp,
int moveNumber ) const

Calculates time allocation for a position.

Parameters
paramsSearch parameters (time, inc, movestogo, etc.).
sideSide to move.
phaseGame phase from FeatureExtractor (0.0=opening, 1.0=endgame).
evalCpCurrent evaluation in centipawns (from previous search).
moveNumberFull move number (1-based).
Returns
TimeAllocation with soft/hard limits.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ config()

const Config & TimeManager::config ( ) const
inline

◆ detectTimeControl()

TimeManager::TimeControl TimeManager::detectTimeControl ( int baseTimeMs,
int incrementMs ) const
private
Here is the caller graph for this function:

◆ estimateMovesRemaining()

int TimeManager::estimateMovesRemaining ( int moveNumber,
float phase,
int movestogo ) const
private
Here is the caller graph for this function:

◆ getControlMultiplier()

float TimeManager::getControlMultiplier ( TimeControl control) const
private
Here is the caller graph for this function:

◆ getEvalMultiplier()

float TimeManager::getEvalMultiplier ( float evalCp) const
private
Here is the caller graph for this function:

◆ getExtensionFactor()

float TimeManager::getExtensionFactor ( int bestMoveChanges,
int scoreDrops ) const

Gets the extension factor based on search instability.

Called during iterative deepening to adjust time limits dynamically.

Parameters
bestMoveChangesCount of root best move changes.
scoreDropsCount of significant score drops.
Returns
Multiplier to extend the soft limit.
Here is the caller graph for this function:

◆ getPhaseMultiplier()

float TimeManager::getPhaseMultiplier ( float phase) const
private
Here is the caller graph for this function:

◆ setConfig()

void TimeManager::setConfig ( const Config & cfg)
inline

◆ shouldStop()

bool TimeManager::shouldStop ( int64_t elapsed,
int depth,
int bestMoveChanges,
int scoreDrops,
const TimeAllocation & allocation ) const

Checks if search should stop based on elapsed time and stability.

Parameters
elapsedTime spent so far (ms).
depthCurrent search depth.
bestMoveChangesHow many times best move changed.
scoreDropsHow many times score dropped significantly.
allocationPreviously calculated allocation limits.
Returns
True if the search should abort.
Here is the call graph for this function:

Member Data Documentation

◆ config_

Config TimeManager::config_
private

The documentation for this class was generated from the following files: