-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
192 lines (141 loc) · 3.42 KB
/
test.cpp
File metadata and controls
192 lines (141 loc) · 3.42 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include <assert.h>
#include <iostream>
#include <ctime>
#include "test.h"
#include "game_state.h"
#include "mcts_node.h"
void ko_test()
{
GameState game;
Coordinate move;
move.set(4,4);
game.play_move(move);
move.set(3,4);
game.play_move(move);
move.set(3,3);
game.play_move(move);
move.set(2,3);
game.play_move(move);
move.set(3,5);
game.play_move(move);
move.set(2,5);
game.play_move(move);
move.set(8,8);
game.play_move(move);
move.set(1,4);
game.play_move(move);
move.set(2,4);
game.play_move(move);
move.set(3,4);
// Shouldn't be able to take the ko.
assert(game.is_legal(move) == KO_POINT);
move.set(8,7);
game.play_move(move);
move.set(7,8);
game.play_move(move);
move.set(3,4);
// Should now be able to take the ko.
assert(game.is_legal(move) == LEGAL_MOVE);
// Test for case where single stone is captured but larger
// group can be recaptured (snapback).
GameState game1;
move.set(1,0);
game1.play_move(move);
move.set(2,0);
game1.play_move(move);
move.set(1,1);
game1.play_move(move);
move.set(2,1);
game1.play_move(move);
move.set(1,2);
game1.play_move(move);
move.set(2,2);
game1.play_move(move);
move.set(0,2);
game1.play_move(move);
move.set(1,3);
game1.play_move(move);
move.set(8,8);
game1.play_move(move);
move.set(0,3);
game1.play_move(move);
move.set(7,8);
game1.play_move(move);
move.set(0,0);
game1.play_move(move);
move.set(0,1);
game1.play_move(move);
move.set(0,0);
// This shouldn't be a ko.
assert(game1.is_legal(move) != KO_POINT);
std::cout << "Ko test passed" << std::endl;
}
void eye_test()
{
GameState game;
Coordinate move;
move.set(4,4);
game.play_move(move);
move.set(1,0);
game.play_move(move);
move.set(4,6);
game.play_move(move);
move.set(0,1);
game.play_move(move);
// False eye in the corner.
assert(game.is_eye(move, EMPTY) == false);
move.set(5,5);
game.play_move(move);
move.set(1,1);
game.play_move(move);
// Real eye in the corner.
move.set(0,0);
assert(game.is_eye(move, EMPTY) == true);
move.set(3,5);
game.play_move(move);
move.set(2,1);
game.play_move(move);
move.set(3,4);
game.play_move(move);
move.set(3,0);
game.play_move(move);
// False eye on the side.
move.set(2,0);
assert(game.is_eye(move, EMPTY) == false);
move.set(5,6);
game.play_move(move);
// False eye in the middle.
move.set(4,5);
assert(game.is_eye(move, EMPTY) == false);
move.set(3,1);
game.play_move(move);
// Real eye on the side
move.set(2,0);
assert(game.is_eye(move, EMPTY) == true);
move.set(5,4);
game.play_move(move);
// Real eye in the middle.
move.set(4,5);
assert(game.is_eye(move, EMPTY) == true);
std::cout << "Eye test passed" << std::endl;
}
void MCTSNode_test()
{
GameState game_state;
MCTSNode mcts_node(game_state);
std::clock_t start;
start = std::clock();
int num_simulations = 1;
for (int i = 0; i < num_simulations; i++)
{
mcts_node.simulate_and_update();
}
double duration = (std::clock()-start) / (double) CLOCKS_PER_SEC;
std::cout << "Time for " << num_simulations << " simulations: " << duration << std::endl;
start = std::clock();
mcts_node.expand();
duration = (std::clock()-start) / (double) CLOCKS_PER_SEC;
std::cout << "Time to expand node: " << duration << std::endl;
// mcts_node.print_visit_map();
// mcts_node.print_uct_map();
}