-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSide.h
79 lines (69 loc) · 1.9 KB
/
Side.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef Side_h
#define Side_h
//========================================================================
// Timer t; // create and start a timer
// t.start(); // restart the timer
// double d = t.elapsed(); // milliseconds since timer was last started
//========================================================================
#include <chrono>
class Timer
{
public:
Timer()
{
start();
}
void start()
{
m_time = std::chrono::high_resolution_clock::now();
}
double elapsed() const
{
std::chrono::duration<double, std::milli> diff =
std::chrono::high_resolution_clock::now() - m_time;
return diff.count();
}
private:
std::chrono::high_resolution_clock::time_point m_time;
};
//========================================================================
// Advance jumpy timer only after jumpInterval calls to elapsed
class JumpyTimer
{
public:
JumpyTimer(int jumpInterval)
: m_jumpInterval(jumpInterval), m_callsMade(0)
{
actualElapsed();
}
double elapsed()
{
m_callsMade++;
if (m_callsMade == m_jumpInterval)
{
m_lastElapsed = m_timer.elapsed();
m_callsMade = 0;
}
return m_lastElapsed;
}
double actualElapsed()
{
m_lastElapsed = m_timer.elapsed();
return m_lastElapsed;
}
private:
Timer m_timer;
int m_jumpInterval;
int m_callsMade;
int m_lastElapsed;
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TIMER CLASSES //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
enum Side { NORTH, SOUTH };
const int NSIDES = 2;
const int POT = 0;
inline
Side opponent(Side s)
{
return Side(NSIDES - 1 - s);
}
#endif /* Side_h */