Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgTimeControl.h

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


Sun Mar 13 2011 Doxygen 1.7.1