12
12
#include " alphabeta_cutoff_player.hpp"
13
13
#include " minmax_player.hpp"
14
14
#include " mcts_player.hpp"
15
+ #include " mcts_eval_multithread_player.hpp"
15
16
#include " mcts_multithread_player.hpp"
16
17
#include " mcts_multithread_threadpool_player.hpp"
17
18
@@ -27,7 +28,7 @@ using namespace utility;
27
28
28
29
string ask_for_player_type (int player_idx) {
29
30
string pt;
30
- cout << " Select player" << player_idx << " (AlphaBeta AlphaBetaCutOff MCTS MCTSMT MinMax): " ;
31
+ cout << " Select player" << player_idx << " (AlphaBeta AlphaBetaCutOff MCTS MCTSEMT MCTSMT MinMax): " ;
31
32
cin >> pt;
32
33
transform (pt.begin (), pt.end (), pt.begin (), ::toupper);
33
34
return pt;
@@ -36,7 +37,21 @@ string ask_for_player_type(int player_idx) {
36
37
int ask_for_n (const string& p, int player_idx) {
37
38
if (p == " ALPHABETA" || p == " MINMAX" )
38
39
return 0 ;
39
- cout << " Player" << player_idx <<" -the number of simulations/The depth to cutoff: " ;
40
+ string s;
41
+ if (p == " ALPHABETACUTOFF" ) {
42
+ s = " The depth to cutoff" ;
43
+ }
44
+ else {
45
+ s = " The number of simulations" ;
46
+ }
47
+ cout << " (Player" << player_idx <<" )" + s + " : " ;
48
+ int n;
49
+ cin >> n;
50
+ return n;
51
+ }
52
+
53
+ int ask_for_experiments () {
54
+ cout << " Number of experiments: " ;
40
55
int n;
41
56
cin >> n;
42
57
return n;
@@ -51,33 +66,44 @@ unique_ptr<Player> create_player(const string& s, Piece p, int n) {
51
66
return make_unique<MCTSPlayer>(p, n);
52
67
if (s == " MCTSMT" )
53
68
return make_unique<MCTSMultiThreadPlayer>(p, n);
69
+ if (s == " MCTSEMT" )
70
+ return make_unique<MCTSEvaluationMultiThreadPlayer>(p, n);
54
71
if (s == " MCTSMTTP" )
55
72
return make_unique<MCTSMultiThreadThreadPoolPlayer>(p, n);
56
73
if (s == " MINMAX" )
57
74
return make_unique<MinMaxPlayer>(p);
58
75
throw invalid_argument (" Invalid player type: " + s);
59
76
}
60
77
78
+ void print_win_rate (const Game& g, const string& p_type, const Player* p) {
79
+ cout << get_piece_color (p->get_piece ()) << " (" << p_type
80
+ << " ) win rate: " << g.compute_win_rate (p->get_piece ())
81
+ << " \n " ;
82
+ }
83
+
61
84
int main () {
62
85
cout << " Board size: " ;
63
86
size_t n;
64
87
cin >> n;
65
- string p1_type = ask_for_player_type (1 );
66
- string p2_type = ask_for_player_type (2 );
88
+ auto p1_type = ask_for_player_type (1 );
89
+ auto p2_type = ask_for_player_type (2 );
67
90
int n1 = ask_for_n (p1_type, 1 );
68
91
int n2 = ask_for_n (p2_type, 2 );
69
92
70
93
auto p1 = create_player (p1_type, Piece::White, n1);
71
94
auto p2 = create_player (p2_type, Piece::Black, n2);
72
- // int n = 5;
95
+ int n_exps = ask_for_experiments ();
96
+ // int n = 9;
73
97
// string p1_type = "MCTS";
74
98
// string p2_type = "MCTS";
75
- // auto p1 = make_unique<MCTSPlayer >(Piece::White, 100 );
76
- // auto p2 = make_unique<MCTSPlayer >(Piece::Black, 100 );
99
+ // auto p1 = make_unique<MCTSMultiThreadThreadPoolPlayer >(Piece::White, 1000 );
100
+ // auto p2 = make_unique<MCTSMultiThreadThreadPoolPlayer >(Piece::Black, 1000 );
77
101
string description = " Time to run (" + p1_type + " vs " + p2_type +
78
102
" ) on (" + to_string (n) + " x " + to_string (n) + " ) board: " ;
79
103
Game g (make_board (" Hex" , n));
80
- for (auto i = 0 ; i != 10 ; ++i) {
104
+ for (auto i = 0 ; i != n_exps ; ++i) {
81
105
timeit (description, &g, &Game::play, p1.get (), p2.get ());
82
106
}
107
+ print_win_rate (g, p1_type, p1.get ());
108
+ print_win_rate (g, p2_type, p2.get ());
83
109
}
0 commit comments