-
Notifications
You must be signed in to change notification settings - Fork 2
/
game.h
78 lines (59 loc) · 1.04 KB
/
game.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
#pragma once
#include "board.h"
#include "move.h"
#include "string.h"
class HavannahGame {
vector<Move> hist;
int size;
public:
HavannahGame(int s = 8){
size = s;
}
int getsize() const {
return size;
}
const vector<Move> & get_hist() const {
return hist;
}
Move get_last() const {
if(hist.size() == 0)
return M_NONE;
return hist[hist.size()-1];
}
Board getboard(int offset = 0) const {
Board board(size);
if(offset <= 0)
offset += hist.size();
for(int i = 0; i < offset; i++)
board.move(hist[i], true, true);
return board;
}
int len() const {
return hist.size();
}
void clear(){
hist.clear();
}
bool undo(){
if(hist.size() <= 0)
return false;
hist.pop_back();
return true;
}
int movesremain() const {
return getboard().movesremain();
}
int toplay() const {
return getboard().toplay();
}
bool valid(const Move & m) const {
return getboard().valid_move(m);
}
bool move(const Move & m){
if(getboard().move(m)){
hist.push_back(m);
return true;
}
return false;
}
};