-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.cpp
More file actions
48 lines (38 loc) · 882 Bytes
/
Copy pathgame.cpp
File metadata and controls
48 lines (38 loc) · 882 Bytes
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
#include <iostream>
#include <vector>
#include <cassert>
#include "board.hpp"
//right now ai is X
//and X usally has to go first
Coor make_move(Board);
int main() {
Board b;
//note to self:
//please rewrite this entire main function,
while (true) {
int w = b.check_for_win();
if (b.check_for_tie() && !w)
break;
if (w) {
std::cout << (w == AI ? 'X' : 'O') << " won" << std::endl;
b.print_board();
exit(0);
}
int row, col;
b.print_board();
std::cout << std::endl;
printf("%c's turn: ", b.get_cur_player() == AI ? 'X' : 'O');
if (b.get_cur_player() == AI) {
std::cout << std::endl;
Coor c = make_move(b);
b.place_move(c.i, c.j);
} else {
std::cin.clear();
std::cin >> row >> col;
if (!b.place_move(row, col))
std::cout << "move invalid" << std::endl;
}
}
b.print_board();
std::cout << "Tied" << std::endl;
}