-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSide.h
77 lines (65 loc) · 1.61 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
#ifndef SIDE_INCLUDED
#define SIDE_INCLUDED
#include <chrono>
enum Side { NORTH, SOUTH };
const int NSIDES = 2;
const int POT = 0;
class Board;
class Timer //Timer class from the Project 3 FAQ (didn't need any adapting)
{
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;
};
class JumpyTimer //JumpyTimer from the Project 3 FAQ (didn't need any adapting)
{
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;
};
inline
Side opponent(Side s)
{
return Side(NSIDES - 1 - s);
}
double eval(const Board& b); //Returns how good a position is for South
void bestMove(Side s, const Board& b, int depth, int &bestHole, double &value, JumpyTimer& timer, double timeLimit);
//Finds the best move for side s on board b and sets bestHole to that move (and does it in <5 seconds)
#endif