00001 /* timeKeeper.cc 00002 */ 00003 #include "osl/game_playing/timeKeeper.h" 00004 #include "osl/stl/stack.h" 00005 00006 struct osl::game_playing::TimeKeeper::Stack 00007 : public osl::stack<std::pair<int,int> > 00008 { 00009 }; 00010 00011 osl::game_playing:: 00012 TimeKeeper::TimeKeeper() : seconds(new Stack()) 00013 { 00014 reset(1500, 1500); // default: 25 min 00015 } 00016 00017 osl::game_playing:: 00018 TimeKeeper::TimeKeeper(int black_time, int white_time) 00019 : seconds(new Stack()) 00020 { 00021 reset(black_time, white_time); 00022 } 00023 00024 osl::game_playing:: 00025 TimeKeeper::~TimeKeeper() 00026 { 00027 } 00028 00029 void osl::game_playing:: 00030 TimeKeeper::reset(int black_time, int white_time) 00031 { 00032 // clear ޤǤʤ 00033 seconds->push(std::make_pair(black_time, white_time)); 00034 } 00035 00036 void osl::game_playing:: 00037 TimeKeeper::pushMove(Player turn, int consumed) 00038 { 00039 std::pair<int,int> time_left = seconds->top(); 00040 if (turn == BLACK) 00041 time_left.first -= consumed; 00042 else 00043 time_left.second -= consumed; 00044 seconds->push(time_left); 00045 } 00046 00047 void osl::game_playing:: 00048 TimeKeeper::popMove() 00049 { 00050 assert(! seconds->empty()); 00051 seconds->pop(); 00052 } 00053 00054 int osl::game_playing:: 00055 TimeKeeper::timeLeft(Player player) const 00056 { 00057 const std::pair<int,int>& time_left = seconds->top(); 00058 return (player == BLACK) ? time_left.first : time_left.second; 00059 } 00060 00061 /* ------------------------------------------------------------------------- */ 00062 // ;;; Local Variables: 00063 // ;;; mode:c++ 00064 // ;;; c-basic-offset:2 00065 // ;;; End: