-
Notifications
You must be signed in to change notification settings - Fork 12
/
Demo1.cpp
155 lines (113 loc) · 5.82 KB
/
Demo1.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/**
* Demo program for Pandemic exercise - OperationsExpert role
*
* Author: Erel Segal-Halevi
* Since : 2021-04
*/
#include "Board.hpp"
#include "City.hpp"
#include "Color.hpp"
#include "OperationsExpert.hpp"
using namespace pandemic;
#include <iostream>
#include <stdexcept>
using namespace std;
int main() {
Board board; // Initialize an empty board (with 0 disease cubes in any city).
board[City::Kinshasa] = 3; // put 3 yellow disease cubes in Kinshasa.
board[City::Kinshasa] = 2; // change number of disease cubes in Kinshasa to 2.
board[City::MexicoCity] = 3; // put 3 yellow disease cubes in MexicoCity
board[City::HoChiMinhCity] = 1; // put 1 red disease cube in HoChiMinhCity
board[City::Chicago] = 1; // put 1 blue disease cube in Chicago
OperationsExpert player {board, City::Atlanta}; // initialize an "operations expert" player on the given board, in Atlanta.
player.take_card(City::Johannesburg)
.take_card(City::Khartoum)
.take_card(City::SaoPaulo)
.take_card(City::BuenosAires)
.take_card(City::HoChiMinhCity);
/* build action */
player.build(); // legal action: you build a research station in Atlanta.
// NOTE: you do not have the Atlanta card, so for other roles this would throw an exception.
// But for the OperationsExpert it is legal, since he may build a research station without a card.
/* drive action */
player.drive(City::Washington); // legal action: you drive from Atlanta to a connected city.
try {
player.drive(City::Madrid); // illegal action: Madrid is not connected to Washington.
} catch (const exception& ex) {
cout << " caught exception: " << ex.what() << endl; // prints a meaningful error message.
}
/* fly_direct action */
player.fly_direct(City::Johannesburg); // legal action: you discard the Johannesburg card and fly to Johannesburg.
try {
player.fly_direct(City::Taipei); // illegal action: you do not have the card of Taipei.
} catch (const exception& ex) {
cout << " caught exception: " << ex.what() << endl; // prints a meaningful error message.
}
/* treat action */
player.drive(City::Kinshasa); // legal action: you move from Johannesburg to a connected city.
cout << board[City::Kinshasa] << endl; // 2
player.treat(City::Kinshasa); // legal action: you remove 1 disease cube from current city (1 cube remains).
cout << board[City::Kinshasa] << endl; // 1
player.treat(City::Kinshasa); // legal action: you remove 1 disease cube from current city (0 cubes remain).
cout << board[City::Kinshasa] << endl; // 0
try {
player.treat(City::Kinshasa); // illegal action: no more cubes remain in Kinshasa.
} catch (const exception& ex) {
cout << " caught exception: " << ex.what() << endl; // prints a meaningful error message.
}
try {
player.treat(City::Washington); // illegal action: you are not in Washington.
} catch (const exception& ex) {
cout << " caught exception: " << ex.what() << endl; // prints a meaningful error message.
}
/* fly_charter action */
player.drive(City::Khartoum)
.fly_charter(City::Sydney); // legal action: you discard the Khartoum card and fly to Sydney.
try {
player.fly_charter(City::Seoul); // illegal action: you do not have the Sydney card (the card of the city you are in).
} catch (const exception& ex) {
cout << " caught exception: " << ex.what() << endl; // prints a meaningful error message.
}
/* build action */
player.drive(City::LosAngeles); // legal action: note that LosAngeles is connected to Sydney.
player.build(); // legal action: build a research station in LosAngeles.
// NOTE: you do not have the LosAngeles card, so for other roles this would throw an exception.
// But for the OperationsExpert it is legal, since he may build a research station without a card.
/* fly_shuttle action */
player.fly_shuttle(City::Atlanta); // legal action: you fly from one research station to another.
player.fly_shuttle(City::LosAngeles); // legal action: you fly from one research station to another.
try {
player.fly_shuttle(City::Chicago); // illegal action: there is no research station in Chicago.
} catch (const exception& ex) {
cout << " caught exception: " << ex.what() << endl; // prints a meaningful error message.
}
/* discover_cure action */
try {
player.discover_cure(Color::Yellow); // illegal action: you only have 2 yellow cards remaining.
} catch (const exception& ex) {
cout << " caught exception: " << ex.what() << endl; // prints a meaningful error message.
}
player.take_card(City::Miami)
.take_card(City::Bogota)
.take_card(City::Lima);
player.discover_cure(Color::Yellow); // legal action: you discard 5 yellow cards and discover a yellow cure.
try {
player.fly_direct(City::Miami); // illegal action: you discarded the Miami card to discover a cure, so you cannot use this card.
} catch (const exception& ex) {
cout << " caught exception: " << ex.what() << endl; // prints a meaningful error message.
}
/* treat action after discovering a cure */
player.drive(City::MexicoCity);
cout << board[City::MexicoCity] << endl; // 3
player.treat(City::MexicoCity); // you now remove ALL disease cubes from MexicoCity, since there is a yelllow cure.
cout << board[City::MexicoCity] << endl; // 0
/* clean the board */
cout << board << endl; // print the board in any reasonable format.
cout << board.is_clean() << endl; // print "0" - the board is not clean.
player.drive(City::Chicago)
.treat(City::Chicago) // remove one disease cube - there is no blue cure yet.
.fly_direct(City::HoChiMinhCity)
.treat(City::HoChiMinhCity); // remove one disease cube - there is no red cure yet.
cout << board << endl; // prints the board in any reasonable format.
cout << board.is_clean() << endl; // prints "1" - the board is clean - congratulations!!! You treated all diseases!!!
}