-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemo2.cpp
115 lines (98 loc) · 3.62 KB
/
Demo2.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
/**
* Demo program for Pandemic exercise - compares the different roles.
*
* Author: Erel Segal-Halevi
* Since : 2021-04
*/
#include "sources/Board.hpp"
#include "sources/City.hpp"
#include "sources/Color.hpp"
#include "sources/Player.hpp"
#include "sources/Researcher.hpp"
#include "sources/Scientist.hpp"
#include "sources/FieldDoctor.hpp"
#include "sources/GeneSplicer.hpp"
#include "sources/OperationsExpert.hpp"
#include "sources/Dispatcher.hpp"
#include "sources/Medic.hpp"
#include "sources/Virologist.hpp"
using namespace pandemic;
#include <vector>
#include <iostream>
#include <stdexcept>
using namespace std;
// Give some four red cards to the given player, to initialize an example.
void take_four_red_cards(Player& player) {
player.take_card(City::Sydney)
.take_card(City::HoChiMinhCity)
.take_card(City::HongKong)
.take_card(City::Bangkok);
}
// Checks if the given player can discover a cure.
bool can_discover_cure(Board& board, Player& player, Color color) {
board.remove_cures();
try {
player.discover_cure(color);
return true;
} catch (const exception& ex) {
return false;
}
}
// Check the conditions in which the given player can discover a cure.
void check_cure_discovery(Board& board, Player& player) {
cout << "Checking a " << player.role() << ": " << endl;
take_four_red_cards(player);
cout << " Four red cards, no research station: " << can_discover_cure(board, player, Color::Red) << endl;
take_four_red_cards(player);
player.drive(City::Atlanta);
cout << " Four red cards, in a research station: " << can_discover_cure(board, player, Color::Red) << endl;
take_four_red_cards(player);
player.take_card(City::Cairo);
cout << " Four red cards and one black card, in a research station: " << can_discover_cure(board, player, Color::Red) << endl;
take_four_red_cards(player);
player.take_card(City::Beijing);
player.drive(City::Washington);
cout << " Five red cards, no research station: " << can_discover_cure(board, player, Color::Red) << endl;
take_four_red_cards(player);
player.take_card(City::Beijing);
player.drive(City::Atlanta);
cout << " Five red cards, in a research station: " << can_discover_cure(board, player, Color::Red) << endl;
}
int main() {
cout << boolalpha;
Board board;
OperationsExpert builder {board, City::Atlanta};
builder.build(); // Build a research station in Atlanta, to prepare the board for the tests.
{
FieldDoctor player(board, City::Washington);
check_cure_discovery(board, player); // should print: false false false false true
}
{
Virologist player(board, City::Washington);
check_cure_discovery(board, player); // should print: false false false false true
}
{
OperationsExpert player(board, City::Washington);
check_cure_discovery(board, player); // should print: false false false false true
}
{
Medic player(board, City::Washington);
check_cure_discovery(board, player); // should print: false false false false true
}
{
Dispatcher player(board, City::Washington);
check_cure_discovery(board, player); // should print: false false false false true
}
{
GeneSplicer player(board, City::Washington);
check_cure_discovery(board, player); // should print: false false ***true*** false true [can find a cure with 4 red and 1 black card]
}
{
Researcher player(board, City::Washington);
check_cure_discovery(board, player); // should print: false false false ***true*** true [can find a cure without a research station]
}
{
Scientist player(board, City::Washington, 4);
check_cure_discovery(board, player); // should print: false ***true*** ***true*** false true [can find a cure with only 4 red cards]
}
}