-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.h
72 lines (54 loc) · 958 Bytes
/
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
#pragma once
#include "board.h"
#include "move.h"
#include "string.h"
class Game {
vector<Move> hist;
public:
Game(){
}
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;
if(offset <= 0)
offset += hist.size();
for(int i = 0; i < offset; i++)
board.move(hist[i]);
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 moves_remain() const {
return getboard().moves_remain();
}
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;
}
};