-
Notifications
You must be signed in to change notification settings - Fork 0
/
state_machine.cc
61 lines (49 loc) · 1.38 KB
/
state_machine.cc
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
#include "state_machine.hh"
State_Machine::State_Machine(eval_fn e, bool t) :
board(std::make_unique<Board>()), eval(e), past_states(std::vector<board_array>(0)), turn(t)
{
past_states.push_back(board->get_board());
}
State_Machine::State_Machine(const board_array &b, eval_fn e=null_eval, bool t) :
board(std::make_unique<Board>(b)), eval(e), past_states(std::vector<board_array>(0)), turn(t)
{
past_states.push_back(board->get_board());
}
State_Machine::~State_Machine()
{}
double State_Machine::evaluate(){
if (is_terminal()) {
if (board->white_wins()){
return 100;
}
if (board->black_wins()){
return -100;
}
return 0;
}
return eval(*board);
}
std::vector<Move> State_Machine::get_actions() {
return board->get_legal_moves(turn);
}
void State_Machine::perform_action(const Move &m){
board->play_move(m);
past_states.push_back(board->get_board());
}
board_array State_Machine::get_board() {
return board->get_board();
}
void State_Machine::undo(){
past_states.pop_back();
board->set_board(past_states.back());
}
void State_Machine::set_state(const board_array &b){
board->set_board(b);
while(past_states.size() > 0){
past_states.pop_back();
}
past_states.push_back(board->get_board());
}
bool State_Machine::is_terminal() {
return board->game_over()
}