-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
113 lines (109 loc) · 2.24 KB
/
Copy pathmain.cpp
File metadata and controls
113 lines (109 loc) · 2.24 KB
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
#include<iostream>
#include<string>
#include "Board.h"
#include"PlayerHuman.h"
#include"PlayerRandom.h"
//#include"AI.h"
#include<iostream>
using namespace std;
void initialMenu() {
cout << "Welcome to Tic Tac Toe \n";
cout << "Please choose an option: \n";
cout << "1) Human vs Human \n";
cout << "2) Human vs Computer \n";
cout << "3) Computer vs Computer \n";
cout << "4) AI implementation \n";
};
int main() {
int choice;
initialMenu();
cin >> choice;
switch(choice) {
case 1: { //Human vs Human
PlayerHuman p1 = PlayerHuman("x");
PlayerHuman p2 = PlayerHuman("o");
Board b = Board();
b.printBoard();
while (!b.checkTie()) {
p1.nextMove(b);
if (b.checkWinner()) {
cout << "\n P1 Won \n";
exit(-1);
}
else {
p2.nextMove(b);
if (b.checkWinner()) {
cout << "\n P2 Won \n";
exit(-1);
}
}
}
break;
}
case 2: { //Human vs Computer
PlayerHuman ph = PlayerHuman("x");
PlayerRandom pr = PlayerRandom();
Board b = Board();
b.printBoard();
while (!b.checkTie()) {
ph.nextMove(b);
if (b.checkWinner()) {
cout << "Human Won" << endl;
exit(-1);
}
else {
pr.nextMove(b);
if (b.checkWinner()) {
cout << "Random spotter won" << endl;
exit(-1);
}
}
}
break;}
case 3: { //Computer vs Computer
PlayerRandom p1 = PlayerRandom("x");
PlayerRandom p2 = PlayerRandom("o");
Board b = Board();
b.placeSymbol("x",0,0);
b.printBoard();
while (!b.checkTie()) {
p2.nextMove(b);
if (b.checkWinner()) {
cout << "P1 Won" << endl;
exit(-1);
}
else {
p1.nextMove(b);
if (b.checkWinner()) {
cout << "P2 won" << endl;
exit(-1);
}
}
}
break;}
case 4: {
PlayerHuman ph = PlayerHuman("o");
PlayerRandom pr = PlayerRandom("x");
Board b = Board();
b.placeSymbol("x",0,0);
b.printBoard();
while (!b.checkTie()) {
ph.nextMove(b);
if (b.checkWinner()) {
cout << "Human Won" << endl;
exit(-1);
}
else {
pr.nextMove(b);
if (b.checkWinner()) {
cout << "Random spotter won" << endl;
exit(-1);
}
}
}
break;}
default:
cout << "\n Wrong choice \n";
break;
}
}