00001 //---------------------------------------------------------------------------- 00002 /** @file SgTimeControl.h */ 00003 //---------------------------------------------------------------------------- 00004 00005 #ifndef SG_TIMECONTROL_H 00006 #define SG_TIMECONTROL_H 00007 00008 #include "SgBlackWhite.h" 00009 00010 class SgTimeRecord; 00011 00012 //---------------------------------------------------------------------------- 00013 00014 /** Basic interface for all time managers. */ 00015 class SgTimeControl 00016 { 00017 public: 00018 virtual ~SgTimeControl(); 00019 00020 /** Suggest a time for the current move. 00021 See class description. 00022 @param timeRecord Time settings and clock state of current game. 00023 @param quiet Don't print logging information to SgDebug() 00024 @return Time suggestion for current move in seconds. 00025 */ 00026 virtual double TimeForCurrentMove(const SgTimeRecord& timeRecord, 00027 bool quiet = false) = 0; 00028 00029 }; 00030 00031 //---------------------------------------------------------------------------- 00032 00033 /** Time management. 00034 This class provides a reasonable default algorithm for time management. 00035 It queries the estimated number of remaining moves by a virtual 00036 function that needs to be implemented in the game-dependent subclass. 00037 -# If in an overtime period the remaining number of moves is used exactly 00038 as returned by GetPositionInfo(). 00039 -# The time for a move is the remaining time (in the main time or current 00040 overtime period) divided by the number of remaining moves. 00041 -# During the opening (first 10 moves; can be controlled by 00042 SetFastOpen()), the time for a move reduced by multiplying it 00043 by a constant factor (default factor is 0.25). 00044 -# [A minimum time of 0.1 is also enforced, but this might become 00045 obsolete, see SetMinTime()] 00046 -# The parameter RemainingConstant() can be used to spend exponentially 00047 more time earlier in the game 00048 */ 00049 class SgDefaultTimeControl 00050 : public SgTimeControl 00051 { 00052 public: 00053 SgDefaultTimeControl(); 00054 00055 00056 /** @name Parameters */ 00057 // @{ 00058 00059 /** Set time reduction factor for fast opening moves. 00060 Default is 0.25. 00061 See class description. 00062 */ 00063 double FastOpenFactor() const; 00064 00065 /** See FastOpenFactor() */ 00066 void SetFastOpenFactor(double factor); 00067 00068 /** Set how many opening moves should be played quickly. 00069 Default is 0. 00070 See class description. 00071 */ 00072 int FastOpenMoves() const; 00073 00074 /** See FastOpenMoves() */ 00075 void SetFastOpenMoves(int nummoves); 00076 00077 /** Parameter to spend exponentially more time earlier in the game. 00078 This parameter cuts the number of expected remaining moves from 00079 the real expectation to a constant. Always expecting a constant number 00080 of remaining moves gives earlier moves more time. Since a good value 00081 depends on the average game length and therefore probably the board 00082 size, the constant is not given in moves, but as a fraction between 0 00083 and 1, and the constant is computed by multiplication with the 00084 expected number of total moves by the current player in the current 00085 game (moves played plus expected remaining moves). The default value 00086 is 1.0, which does not limit the number of expected remaining moves. 00087 The smaller the value, the more time is spent in the early phase of 00088 the game. 00089 */ 00090 double RemainingConstant() const; 00091 00092 /** See RemainingConstant() */ 00093 void SetRemainingConstant(double value); 00094 00095 /** Set minimum time for any move. 00096 Could be made obsolete? If the player cannot generate a meaningful 00097 move in less than a minimum time, he can decide itself to ignore 00098 the time limit. 00099 */ 00100 void SetMinTime(double mintime); 00101 00102 // @} // @name Parameters 00103 00104 00105 double TimeForCurrentMove(const SgTimeRecord& timeRecord, 00106 bool quiet = false); 00107 00108 /** Get game-specific information about the current position. 00109 @param[out] toPlay Current color to move. 00110 @param[out] movesPlayed Moves already played (by the current player) 00111 @param[out] estimatedRemainingMoves An estimate of the number of 00112 remaining moves (for the current player) in the game. 00113 */ 00114 virtual void GetPositionInfo(SgBlackWhite& toPlay, 00115 int& movesPlayed, 00116 int& estimatedRemainingMoves) = 0; 00117 00118 private: 00119 /** See FastOpenFactor() */ 00120 double m_fastOpenFactor; 00121 00122 /** See FastOpenMoves() */ 00123 int m_fastOpenMoves; 00124 00125 /** See SetMinTime() */ 00126 double m_minTime; 00127 00128 /** See RemainingConstant() */ 00129 double m_remainingConstant; 00130 }; 00131 00132 //---------------------------------------------------------------------------- 00133 00134 /** Abstract interface for players (or other objects) that own an instance 00135 of SgDefaultTimeControl. 00136 Can be used to query a player at runtime (with a dynamic_cast), whether it 00137 uses such an object and set parameters. 00138 */ 00139 class SgObjectWithDefaultTimeControl 00140 { 00141 public: 00142 virtual ~SgObjectWithDefaultTimeControl(); 00143 00144 virtual SgDefaultTimeControl& TimeControl() = 0; 00145 00146 virtual const SgDefaultTimeControl& TimeControl() const = 0; 00147 }; 00148 00149 //---------------------------------------------------------------------------- 00150 00151 #endif // SG_TIMECONTROL_H