All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
timeKeeper.cc
Go to the documentation of this file.
1 /* timeKeeper.cc
2  */
4 #include "osl/stl/stack.h"
5 
7  : public osl::vector<std::pair<int,int> >
8 {
9 };
10 
12 TimeKeeper::TimeKeeper() : seconds(new Stack())
13 {
14  reset(1500, 1500); // default: 25 min
15 }
16 
18 TimeKeeper::TimeKeeper(int black_time, int white_time)
19  : seconds(new Stack())
20 {
21  reset(black_time, white_time);
22 }
23 
26 {
27 }
28 
30 TimeKeeper::reset(int black_time, int white_time)
31 {
32  seconds->clear();
33  seconds->push_back(std::make_pair(black_time, white_time));
34 }
35 
37 TimeKeeper::pushMove(Player turn, int consumed)
38 {
39  std::pair<int,int> time_left = seconds->back();
40  if (turn == BLACK)
41  time_left.first -= consumed;
42  else
43  time_left.second -= consumed;
44  seconds->push_back(time_left);
45 }
46 
49 {
50  assert(! seconds->empty());
51  seconds->pop_back();
52 }
53 
56 {
57  const std::pair<int,int>& time_left = seconds->back();
58  return (player == BLACK) ? time_left.first : time_left.second;
59 }
60 
63 {
64  return timeLimit(player) - timeLeft(player);
65 }
66 
69 {
70  const std::pair<int,int>& time_left = seconds->front();
71  return (player == BLACK) ? time_left.first : time_left.second;
72 }
73 
74 /* ------------------------------------------------------------------------- */
75 // ;;; Local Variables:
76 // ;;; mode:c++
77 // ;;; c-basic-offset:2
78 // ;;; End: