-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
76 lines (62 loc) · 2.36 KB
/
main.cpp
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
#include <iostream>
#include "Reversi.h"
#include "MCTSNode.h"
#include <cstdio>
int main() {
std::cout << "Hello!" << std::endl;
std::cout << "which side do you want to play? 1 for white;-1 for black" << std::endl;
int playerColor;
std::cin >> playerColor;
Reversi r = Reversi();
auto root = std::make_shared<MCTSNode>(nullptr, r, BLACK);
if (playerColor == WHITE) {
auto leaf = selection(root);
std::cerr << "[debug]selection ok" << std::endl;
auto newChild = expansion(leaf);
std::cerr << "[debug]expansion ok" << std::endl;
auto result = simulation(newChild);
std::cerr << "[debug]simulation ok" << std::endl;
backpropagation(result.get(), root->color);
std::cerr << "[debug]backpropagation ok" << std::endl;
root = root->decideNext();
} else if (playerColor == BLACK) {
} else {
std::cout << "wrong color." << std::endl;
return 1;
}
root->boardState.printBoard();
while (!root->boardState.isTerminal()) {
int row = 0, column = 0;
std::cin >> row >> column;
while (!root->boardState.isValid(row, column, root->color)) {
std::cout << "invalid movement!" << std::endl;
std::cin >> row >> column;
}
root = root->selectNext(row, column);
root->boardState.printBoard();
for (int j = 0; j < 1000; ++j) {
// while (!root->isAllExpanded()){
auto leaf = selection(root);
// std::cerr << "[debug]selection ok" << std::endl;
auto newChild = expansion(leaf);
// std::cerr << "[debug]expansion ok" << std::endl;
for (int i = 0; i < 10; ++i) {
auto result = simulation(newChild);
// std::cerr << "[debug]simulation ok" << std::endl;
backpropagation(result.get(), root->color);
// std::cerr << "[debug]backpropagation ok" << std::endl;
}
// std::cerr << "[debug]simulation ok" << std::endl;
// std::cerr << "[debug]backpropagation ok" << std::endl;
// }
}
root = root->decideNext();
root->boardState.printBoard();
}
if (root->boardState.isWin(BLACK)) {
std::cout << "BLACK win" << std::endl;
} else {
std::cout << "WHITE win" << std::endl;
}
return 0;
}