-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
45 lines (36 loc) · 1.16 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
#include "board.h"
#include "utils.h"
#include "players.h"
player_f* ask_for_player_type() {
std::cout << " h - human, m - minmax, a - alpha-beta, c - mcts" << std::endl;
switch (ask("hmac")) {
case 'h': return human_player;
case 'm': return minmax_player;
case 'a': return alphabeta_player;
case 'c': return mcts_player;
}
}
int main(int argc, char *argv[])
{
Board b;
player_f *player_1, *player_2;
std::cout << "Player 1 (O)?";
player_1 = ask_for_player_type();
std::cout << "Player 2 (X)?";
player_2 = ask_for_player_type();
std::cout << b << std::endl;
while (!b.is_win() && !b.is_full()) {
int col = b.max_play() ? player_1(b) : player_2(b);
b.do_move(col);
std::cout << b;
for (int i = 0; i < col; ++i) std::cout << ' ';
std::cout << '^' << std::endl;
}
if (b.is_win())
std::cout << b.who_play_recent() << " wins!" << std::endl;
else
std::cout << " draw!";
std::cout << "q to quit" << std::endl;
ask("");
return 0;
}