csaTime.h
Go to the documentation of this file.
00001 #ifndef OSL_CSA_TIME_H
00002 #define OSL_CSA_TIME_H
00003 #include "osl/misc/milliSeconds.h"
00004 #include <string>
00005 #include <cmath>
00006 
00007 namespace osl
00008 {
00009   namespace game_playing
00010   {
00011   class CsaTime
00012   {
00013     MilliSeconds start, opmove, mymove;
00014     long mytimeleft, optimeleft;
00015   public:
00016     explicit CsaTime(long timeleft) 
00017       : mytimeleft(timeleft), optimeleft(timeleft)
00018     {
00019       mymove = opmove = start = MilliSeconds::now();
00020     }
00021     CsaTime(long myTimeLeft, long opTimeLeft) 
00022       : mytimeleft(myTimeLeft), optimeleft(opTimeLeft)
00023     {
00024       mymove = opmove = start = MilliSeconds::now();
00025     }
00026     long makeOpMove() {
00027       opmove = MilliSeconds::now();
00028       long ret = (long)floor((opmove - mymove).toSeconds());
00029       if (ret == 0) { ret = 1; }
00030       optimeleft -= ret;
00031       return ret;
00032     }
00033     long makeMyMove() {
00034       mymove = MilliSeconds::now();
00035       long ret = (long)floor((mymove - opmove).toSeconds());
00036       if(ret == 0) { ret = 1; }
00037       mytimeleft -= ret;
00038       return ret;
00039     }
00040     long getMyLeft() const { return mytimeleft; }
00041     long getOpLeft() const { return optimeleft; }
00042     const std::string getStart() const;
00043     static const std::string curruntTime();
00044   };
00045 } // namespace game_playing
00046 } // namespace osl
00047 #endif // OSL_CSA_TIME
00048 // ;;; Local Variables:
00049 // ;;; mode:c++
00050 // ;;; c-basic-offset:2
00051 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines