-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.h
173 lines (153 loc) · 3.66 KB
/
ui.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
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
#pragma once
#include "tree.h"
// run this for stand along program
void computer_vs_computer_ui()
{
Int Nx, Ny;
Doub komi;
cout << "random game..." << endl;
cout << "input board size x : "; cin >> Nx;
cout << "input board size y : "; cin >> Ny;
cout << "input komi : "; cin >> komi;
board_Nx(Nx); board_Ny(Ny); // set board size
komi2(round(komi * 2)); // set koomi
Tree tree;
tree.rand_game(0, true);
getchar();
getchar();
}
// run this for stand alone human vs computer
void human_vs_computer_ui()
{
Int Nx, Ny, ret, i = 0, bscore4, x, y;
Doub komi;
Char color;
cout << "human vs computer..." << endl;
cout << "input board size x : "; cin >> Nx;
cout << "input board size y : "; cin >> Ny;
cout << "input komi : "; cin >> komi;
cout << "your color : "; cin >> color;
board_Nx(Nx); board_Ny(Ny); // set board size
komi2(round(komi * 2)); // set koomi
Tree tree;
i = 0;
cout << "\n\nstep " << i << " "; ++i;
tree.disp_board();
if (color == 'b' || color == 'B') {
for (; i < 10000; ++i) {
// human move
cout << "input x y (negative to pass): ";
cin >> x >> y;
if (x < 0 || y < 0) {
if (tree.pass()) // pass !
break; // double pass !
}
if (tree.place(x, y)) {
error("illegal move!");
}
cout << "step " << i << " ";
tree.disp_board();
// computer move
ret = tree.rand_smart_move();
if (ret == -1)
error("unkown error!");
if (ret == -2) {
cout << "double pass !\n\n\n";
break;
}
cout << "step " << i << " ";
tree.disp_board();
}
}
else if (color == 'w' || color == 'W') {
for (; i < 10000; ++i) {
// computer move
ret = tree.rand_smart_move();
if (ret == -1)
error("unkown error!");
if (ret == -2) {
cout << "double pass !\n\n\n";
break;
}
cout << "step " << i << " ";
tree.disp_board();
// human move
cout << "input x y (negative to pass): ";
cin >> x >> y;
if (x < 0 || y < 0) {
if (tree.pass()) // pass !
break; // double pass !
}
if (tree.place(x, y)) {
error("illegal move!");
}
cout << "step " << i << " ";
tree.disp_board();
}
}
else
error("illegal color! must be 'b' or 'w'!");
cout << "game over!" << "\n\n";
tree.solve_end();
if (tree.winner() == Who::BLACK) {
cout << "black wins!";
cout << " (score: " << 0.5*tree.score2() << ")\n\n";
}
else if (tree.winner() == Who::WHITE) {
cout << "white wins!";
cout << " (score: " << 0.5*tree.score2() << ")\n\n";
}
else { // draw
cout << "draw!\n\n";
}
tree.writeSGF("record.sgf");
getchar();
getchar();
}
// run this for stand alone human vs computer
void human_vs_human_ui()
{
Int Nx, Ny, ret, i = 0, bscore4, x, y;
Doub komi;
Char color;
cout << "human vs computer..." << endl;
cout << "input board size x : "; cin >> Nx;
cout << "input board size y : "; cin >> Ny;
cout << "input komi : "; cin >> komi;
board_Nx(Nx); board_Ny(Ny); // set board size
komi2(round(komi * 2)); // set koomi
Tree tree;
i = 0;
cout << "\n\nstep " << i << " "; ++i;
tree.disp_board();
for (; i < 10000; ++i) {
// human move
cout << "input x y (negative to pass): ";
cin >> x >> y;
if (x < 0 || y < 0) {
if (tree.pass()) // pass !
break; // double pass !
}
if (tree.place(x, y)) {
error("illegal move!");
}
cout << "step " << i << " ";
tree.disp_board();
}
cout << "game over!" << "\n\n";
tree.solve_end();
if (tree.winner() == Who::BLACK) {
cout << "black wins!";
cout << " (score: " << 0.5*tree.score2() << ")\n\n";
}
else if (tree.winner() == Who::WHITE) {
cout << "white wins!";
cout << " (score: " << 0.5*tree.score2() << ")\n\n";
}
else { // draw
cout << "draw!\n\n";
}
tree.writeSGF("record.sgf");
getchar();
getchar();
}