-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
106 lines (100 loc) · 3.31 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
#include "Game.h"
#include "Player.h"
#include <iostream>
#include <string>
using namespace std;
bool addStandardShips(Game& g)
{
return g.addShip(5, 'A', "aircraft carrier") &&
g.addShip(4, 'B', "battleship") &&
g.addShip(3, 'D', "destroyer") &&
g.addShip(3, 'S', "submarine") &&
g.addShip(2, 'P', "patrol boat");
}
int main()
{
const int NTRIALS = 100;
cout << "Select one of these choices for an example of the game:" << endl;
cout << " 1. A mini-game between two mediocre players" << endl;
cout << " 2. A mediocre player against a human player" << endl;
cout << " 3. A " << NTRIALS
<< "-game match between a mediocre and an awful player, with no pauses"
<< endl;
cout << " 4. A " << NTRIALS
<< "-game match between a mediocre and a good player, with no pauses"
<< endl;
cout << "Enter your choice: ";
string line;
getline(cin,line);
if (line.empty())
{
cout << "You did not enter a choice" << endl;
}
else if (line[0] == '1')
{
Game g(2, 3);
g.addShip(2, 'R', "rowboat");
Player* p1 = createPlayer("mediocre", "Popeye", g);
Player* p2 = createPlayer("mediocre", "Bluto", g);
cout << "This mini-game has one ship, a 2-segment rowboat." << endl;
g.play(p1, p2);
delete p1;
delete p2;
}
else if (line[0] == '2')
{
Game g(10, 10);
addStandardShips(g);
Player* p1 = createPlayer("mediocre", "Mediocre Midori", g);
Player* p2 = createPlayer("human", "Shuman the Human", g);
g.play(p1, p2);
delete p1;
delete p2;
}
else if (line[0] == '3')
{
int nMediocreWins = 0;
for (int k = 1; k <= NTRIALS; k++)
{
cout << "============================= Game " << k
<< " =============================" << endl;
Game g(10, 10);
addStandardShips(g);
Player* p1 = createPlayer("awful", "Awful Audrey", g);
Player* p2 = createPlayer("mediocre", "Mediocre Mimi", g);
Player* winner = (k % 2 == 1 ?
g.play(p1, p2, false) : g.play(p2, p1, false));
if (winner == p2)
nMediocreWins++;
delete p1;
delete p2;
}
cout << "The mediocre player won " << nMediocreWins << " out of "
<< NTRIALS << " games." << endl;
}
else if (line[0] == '4')
{
int nMediocreWins = 0;
for (int k = 1; k <= NTRIALS; k++)
{
cout << "============================= Game " << k
<< " =============================" << endl;
Game g(10, 10);
addStandardShips(g);
Player* p1 = createPlayer("mediocre", "Mediocre Mimi", g);
Player* p2 = createPlayer("good", "Good Gary", g);
Player* winner = (k % 2 == 1 ?
g.play(p1, p2, false) : g.play(p2, p1, false));
if (winner == p2)
nMediocreWins++;
delete p1;
delete p2;
}
cout << "The good player won " << nMediocreWins << " out of "
<< NTRIALS << " games." << endl;
}
else
{
cout << "That's not one of the choices." << endl;
}
}