-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
119 lines (103 loc) · 2.75 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
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
114
115
116
117
118
119
/**
*main file for assigment 7
*Author Erel Segal-Halevi
*From https://github.com/erelsgl/ariel-cpp-5778/tree/master/week06-inheritance/homework
*Version 1.0
**/
//libraries
#include "TicTacToe.h"
#include "DummyPlayers.h"
#include "Champion.h"
void printResults(const TicTacToe& game) {
cout << endl << "The final board is " << endl << game.board();
cout << "And the winner is " << game.winner().name()
<< ", playing as " << game.winner().getChar() << "!" << endl;
}
void playAndPrintResults(TicTacToe& game, Player& xPlayer, Player& oPlayer) {
game.play(xPlayer, oPlayer);
printResults(game);
}
void playAndPrintWinner(TicTacToe& game, Player& xPlayer, Player& oPlayer) {
game.play(xPlayer, oPlayer);
cout << "The winner is " << game.winner().name()
<< ", playing as " << game.winner().getChar() << "!" << endl;
}
int main() {
TicTacToe game(4); // Initializes a game on a 4x4 board
XYPlayer player1;
YXPlayer player2;
IllegalPlayer player3;
ExceptionPlayer player4;
playAndPrintResults(game, player1, player2);
/*
The final board is
XXXX
O...
O...
O...
And the winner is XYPlayer, playing as X!
*/
playAndPrintResults(game, player2, player1);
/*
The final board is
XOOO
X...
X...
X...
And the winner is YXPlayer, playing as X!
*/
playAndPrintResults(game, player1, player3);
/*
The final board is
X...
....
....
....
And the winner is XYPlayer, playing as X!
*/
playAndPrintResults(game, player3, player1);
/*
The final board is
XO..
....
....
....
And the winner is XYPlayer, playing as O!
*/
playAndPrintResults(game, player2, player4);
/*
The final board is
X...
....
....
....
And the winner is YXPlayer, playing as X!
*/
playAndPrintResults(game, player4, player2);
/*
The final board is
....
....
....
....
And the winner is YXPlayer, playing as O!
*/
Champion champion;
playAndPrintWinner(game, champion, player1);
// The winner is <your name>, playing as X!
playAndPrintWinner(game, player1, champion);
// The winner is <your name>, playing as O!
playAndPrintWinner(game, champion, player2);
// The winner is <your name>, playing as X!
playAndPrintWinner(game, player2, champion);
// The winner is <your name>, playing as O!
playAndPrintWinner(game, champion, player3);
// The winner is <your name>, playing as X!
playAndPrintWinner(game, player3, champion);
// The winner is <your name>, playing as O!
playAndPrintWinner(game, champion, player4);
// The winner is <your name>, playing as X!
playAndPrintWinner(game, player4, champion);
// The winner is <your name>, playing as O!
return 0;
}