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