00001 #ifndef _CSA_TIME_H
00002 #define _CSA_TIME_H
00003 #include <string>
00004 #include <sys/time.h>
00005
00006 namespace osl
00007 {
00008 namespace game_playing
00009 {
00010 class CsaTime
00011 {
00012 timeval start, opmove, mymove;
00013 long mytimeleft, optimeleft;
00014 public:
00015 explicit CsaTime(long timeleft)
00016 : mytimeleft(timeleft), optimeleft(timeleft)
00017 {
00018 gettimeofday(&start, 0);
00019 mymove=opmove=start;
00020 }
00021 CsaTime(long myTimeLeft, long opTimeLeft)
00022 : mytimeleft(myTimeLeft), optimeleft(opTimeLeft)
00023 {
00024 gettimeofday(&start, 0);
00025 mymove=opmove=start;
00026 }
00027 long makeOpMove() {
00028 gettimeofday(&opmove, 0);
00029 long ret = opmove.tv_sec - mymove.tv_sec;
00030 if (opmove.tv_usec < mymove.tv_usec) { ret--; }
00031 if (ret == 0) { ret = 1; }
00032 optimeleft -= ret;
00033 return ret;
00034 }
00035 long makeMyMove() {
00036 gettimeofday(&mymove, 0);
00037 long ret = mymove.tv_sec - opmove.tv_sec;
00038 if(mymove.tv_usec < opmove.tv_usec) { ret--; }
00039 if(ret == 0) { ret = 1; }
00040 mytimeleft -= ret;
00041 return ret;
00042 }
00043 long getMyLeft() const { return mytimeleft; }
00044 long getOpLeft() const { return optimeleft; }
00045 const std::string getStart() const;
00046 static const std::string curruntTime();
00047 };
00048 }
00049 }
00050 #endif //_CSA_TIME
00051
00052
00053
00054