All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
csaTime.h
Go to the documentation of this file.
1 #ifndef OSL_CSA_TIME_H
2 #define OSL_CSA_TIME_H
4 #include <string>
5 #include <cmath>
6 
7 namespace osl
8 {
9  namespace game_playing
10  {
11  class CsaTime
12  {
13  MilliSeconds start, opmove, mymove;
15  public:
16  explicit CsaTime(long timeleft)
17  : mytimeleft(timeleft), optimeleft(timeleft)
18  {
19  mymove = opmove = start = MilliSeconds::now();
20  }
21  CsaTime(long myTimeLeft, long opTimeLeft)
22  : mytimeleft(myTimeLeft), optimeleft(opTimeLeft)
23  {
24  mymove = opmove = start = MilliSeconds::now();
25  }
26  long makeOpMove() {
27  opmove = MilliSeconds::now();
28  long ret = (long)floor((opmove - mymove).toSeconds());
29  if (ret == 0) { ret = 1; }
30  optimeleft -= ret;
31  return ret;
32  }
33  long makeMyMove() {
34  mymove = MilliSeconds::now();
35  long ret = (long)floor((mymove - opmove).toSeconds());
36  if(ret == 0) { ret = 1; }
37  mytimeleft -= ret;
38  return ret;
39  }
40  long getMyLeft() const { return mytimeleft; }
41  long getOpLeft() const { return optimeleft; }
42  const std::string getStart() const;
43  static const std::string curruntTime();
44  };
45 } // namespace game_playing
46 } // namespace osl
47 #endif // OSL_CSA_TIME
48 // ;;; Local Variables:
49 // ;;; mode:c++
50 // ;;; c-basic-offset:2
51 // ;;; End: