Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #ifndef SG_TIMERECORD_H
00007 #define SG_TIMERECORD_H
00008
00009 #include <iosfwd>
00010 #include "SgBWArray.h"
00011
00012 class SgNode;
00013
00014
00015
00016
00017 enum SgClockState {
00018
00019 SG_CLOCK_OFF,
00020
00021
00022 SG_CLOCK_RUNNING,
00023
00024
00025
00026 SG_CLOCK_SUSPENDED
00027 };
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 class SgTimeRecord
00046 {
00047 public:
00048 explicit SgTimeRecord(int numMoves = 0, double period = 0,
00049 double overhead = 0, bool loseOnTime = false);
00050
00051
00052
00053
00054
00055
00056 SgTimeRecord(bool oneMoveOnly, double timeForMove);
00057
00058 ~SgTimeRecord();
00059
00060
00061
00062
00063
00064 bool UseOvertime() const;
00065
00066 int OTNumMoves() const;
00067
00068 double OTPeriod() const;
00069
00070 double Overhead() const;
00071
00072 bool LoseOnTime() const;
00073
00074 void SetOTNumMoves(int numMoves);
00075
00076 void SetOTPeriod(double period);
00077
00078 void SetOverhead(double overhead);
00079
00080 void SetLoseOnTime(bool lose);
00081
00082
00083
00084
00085
00086
00087
00088
00089 SgClockState GetClockState() const;
00090
00091 bool ClockIsRunning() const;
00092
00093
00094
00095 double TimeLeft(SgBlackWhite player) const;
00096
00097
00098
00099 int MovesLeft(SgBlackWhite color) const;
00100
00101 void SetTimeLeft(SgBlackWhite color, double timeLeft);
00102
00103
00104
00105
00106 void TurnClockOn(bool turnOn);
00107
00108
00109
00110 void SetMovesLeft(SgBlackWhite color, int moves);
00111
00112
00113 void SuspendClock();
00114
00115
00116
00117
00118 void UpdateTimeLeft();
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 void EnterNode(SgNode& node, SgBlackWhite player);
00133
00134
00135
00136
00137
00138
00139 void PlayedMove(SgNode& node, SgBlackWhite player);
00140
00141
00142
00143 void SetClock(SgNode& node, SgBlackWhite player, double time);
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 static SgBWArray<double> GetTimeFromTree(SgNode& node);
00154
00155
00156
00157 static SgBWArray<int> GetOTMovesFromTree(SgNode& node);
00158
00159
00160 static void SetTimeInTree(SgNode& node, SgBWArray<double> time);
00161
00162
00163
00164 private:
00165
00166
00167 int m_overtimeNumMoves;
00168
00169
00170 double m_overtimePeriod;
00171
00172
00173
00174 double m_overhead;
00175
00176
00177 bool m_loseOnTime;
00178
00179
00180
00181 SgBlackWhite m_player;
00182
00183
00184 bool m_clockIsOn;
00185
00186
00187
00188 bool m_suspended;
00189
00190
00191 SgNode* m_atNode;
00192
00193
00194
00195
00196 SgBWArray<double> m_timeLeft;
00197
00198
00199
00200 SgBWArray<int> m_movesLeft;
00201
00202
00203 double m_timeOfLastUpdate;
00204 };
00205
00206 inline SgTimeRecord::~SgTimeRecord()
00207 {
00208 }
00209
00210 inline bool SgTimeRecord::ClockIsRunning() const
00211 {
00212 return m_clockIsOn;
00213 }
00214
00215 inline bool SgTimeRecord::LoseOnTime() const
00216 {
00217 return m_loseOnTime;
00218 }
00219
00220 inline int SgTimeRecord::MovesLeft(SgBlackWhite color) const
00221 {
00222 return m_movesLeft[color];
00223 }
00224
00225 inline int SgTimeRecord::OTNumMoves() const
00226 {
00227 return m_overtimeNumMoves;
00228 }
00229
00230 inline double SgTimeRecord::OTPeriod() const
00231 {
00232 return m_overtimePeriod;
00233 }
00234
00235 inline double SgTimeRecord::Overhead() const
00236 {
00237 return m_overhead;
00238 }
00239
00240 inline void SgTimeRecord::SetLoseOnTime(bool lose)
00241 {
00242 m_loseOnTime = lose;
00243 }
00244
00245 inline void SgTimeRecord::SetMovesLeft(SgBlackWhite color, int moves)
00246 {
00247 SG_ASSERT(moves >= 0); m_movesLeft[color] = moves;
00248 }
00249
00250 inline void SgTimeRecord::SetOTNumMoves(int numMoves)
00251 {
00252 m_overtimeNumMoves = numMoves;
00253 }
00254
00255 inline void SgTimeRecord::SetOTPeriod(double period)
00256 {
00257 m_overtimePeriod = period;
00258 }
00259
00260 inline void SgTimeRecord::SetOverhead(double overhead)
00261 {
00262 m_overhead = overhead;
00263 }
00264
00265 inline void SgTimeRecord::SetTimeLeft(SgBlackWhite color, double timeLeft)
00266 {
00267 m_timeLeft[color] = timeLeft;
00268 }
00269
00270 inline bool SgTimeRecord::UseOvertime() const
00271 {
00272 return m_overtimeNumMoves > 0;
00273 }
00274
00275
00276
00277
00278
00279 std::ostream& operator<<(std::ostream& out, const SgTimeRecord& time);
00280
00281
00282 std::ostream& operator<<(std::ostream& out, SgClockState clockState);
00283
00284
00285
00286 #endif // SG_TIMERECORD_H