forked from AA789-ai/WarzoneGame-COMP345
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrdersDriver.cpp
More file actions
221 lines (168 loc) · 6.39 KB
/
OrdersDriver.cpp
File metadata and controls
221 lines (168 loc) · 6.39 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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#include "OrdersDriver.h"
#include "Orders.h"
#include "Player.h"
#include "Cards.h"
#include "GameEngine.h"
#include "MapLoader.h"
#include <iostream>
#define LOG(x) std::cout << x << std::endl;
#define DELETE(x) delete x; x = NULL;
void testOrdersLists()
{
// Set up map data
std::cout << std::endl;
LOG("-------- Order Lists Test Setup --------")
std::cout << std::endl;
std::vector<std::string> mapsToLoad = { "./maps/3D.map" };
std::vector<Map*> validMaps;
MapLoader loader(mapsToLoad[0]);
Map* loadedMap = loader.loadMap();
if (loadedMap->isValid()) {
std::cout << "The map was valid" << std::endl;
validMaps.push_back(loadedMap);
}
else {
std::cout << "The map was invalid" << std::endl;
delete loadedMap;
std::cout << "----------------------------------------------------------------------------------" << std::endl;
std::cout << "----------------------------------------------------------------------------------" << std::endl;
return;
}
// Setup Game Engine
GameEngine* gameEngine = new GameEngine();
gameEngine->neutralPlayer = new Player("Neutral Player");
// Setup player data
Player* p1 = new Player("Test_Player01");
Player* p2 = new Player("Test_Player02");
Player* p3 = new Player("NEUTRAL");
gameEngine->players.push_back(p1);
gameEngine->players.push_back(p2);
gameEngine->players.push_back(p3);
Deck* deck1 = new Deck();
const std::vector<Continent*> continents = loadedMap->getContinents();
const std::vector<Territory*> c_territories = continents[0]->getTerritories();
const std::vector<Territory*> t_territories = continents[1]->getTerritories();
int* armies = new int(10);
// Player 1
p1->addTerritory(c_territories[0]);
p1->addTerritory(c_territories[1]);
// Player 2
p2->addTerritory(c_territories[3]);
// Neutral player
p3->addTerritory(c_territories[4]);
p3->addTerritory(c_territories[5]);
p3->addTerritory(c_territories[6]);
LOG("\n Start Test ---- Order COPY Constructors---- \n");
{
Deploy deploy_order2(*dynamic_cast<Deploy*>(p1->getOrdersList().orders[0]));
deploy_order2.print();
Advance advance_order2(*dynamic_cast<Advance*>(p1->getOrdersList().orders[1]));
advance_order2.print();
Airlift airlift_order2(*dynamic_cast<Airlift*>(p1->getOrdersList().orders[2]));
airlift_order2.print();
Bomb bomb_order2(*dynamic_cast<Bomb*>(p1->getOrdersList().orders[3]));
bomb_order2.print();
Blockade blockade_order2(*dynamic_cast<Blockade*>(p1->getOrdersList().orders[4]));
blockade_order2.print();
Negotiate negotiate_order2(*dynamic_cast<Negotiate*>(p1->getOrdersList().orders[5]));
negotiate_order2.print();
LOG("Copies fall out of scope, call deconstructors!\n")
}
LOG("\n Start test ---- OrderList Copy -----\n");
OrdersList ordersList(p1->getOrdersList());
std::cout << "Original OrderList" << std::endl;
int orderList1Size = p1->getOrdersList().orders.size();
for (int i = 0; i < orderList1Size; i++)
{
std::cout << p1->getOrdersList().orders[i]->type << " - " << &p1->getOrdersList().orders[i] << std::endl;
}
std::cout << std::endl;
int orderList2Size = ordersList.orders.size();
std::cout << "Copied OrderList" << std::endl;
for (int i = 0; i < orderList2Size; i++)
{
std::cout << ordersList.orders[i]->type << " - " << &ordersList.orders[i] << std::endl;
}
std::cout << std::endl;
LOG("\n Start Test ---- OrderList Methods ----- \n ----BEFORE MOVE----");
ordersList.print();
LOG("\n ---- AFTER MOVE ----");
ordersList.move(*ordersList.orders[0], 2);
ordersList.print();
LOG("\n ---- AFTER REMOVE ----");
ordersList.remove(*ordersList.orders[0]);
ordersList.print();
/// Clean Players
LOG("\n CLEAN ---- Delete Players / OrderList -----\n");
DELETE(p1);
DELETE(p2);
DELETE(p3);
LOG("\n CLEAN ---- Copy OrderList -----\n");
}
void testOrderExecution()
{
// Set up map data
std::cout << std::endl;
LOG("-------- Order Execution Test Setup --------")
std::cout << std::endl;
std::vector<std::string> mapsToLoad = { "./maps/3D.map" };
std::vector<Map*> validMaps;
MapLoader loader(mapsToLoad[0]);
Map* loadedMap = loader.loadMap();
if (loadedMap->isValid()) {
std::cout << "The map was valid" << std::endl;
validMaps.push_back(loadedMap);
}
else {
std::cout << "The map was invalid" << std::endl;
delete loadedMap;
std::cout << "----------------------------------------------------------------------------------" << std::endl;
std::cout << "----------------------------------------------------------------------------------" << std::endl;
return;
}
// Set up Game Engine
GameEngine* gameEngine = new GameEngine();
gameEngine->neutralPlayer = new Player("Neutral Player");
// Set up player data
Player* p1 = new Player("Test_Player01");
Player* p2 = new Player("Test_Player02");
gameEngine->players.push_back(p1);
gameEngine->players.push_back(p2);
Deck* deck1 = new Deck();
int* armies = new int(10);
int* armies2 = new int(10);
const std::vector<Continent*> continents = loadedMap->getContinents();
const std::vector<Territory*> c_territories = continents[0]->getTerritories();
const std::vector<Territory*> t_territories = continents[1]->getTerritories();
// Player 1
p1->addTerritory(c_territories[0]);
p1->addTerritory(c_territories[1]);
// Player 2
p2->addTerritory(c_territories[2]);
p2->addTerritory(c_territories[3]);
// Execute orders
std::cout << std::endl;
for (size_t i = 0; i < p1->getOrdersList().orders.size(); i++)
{
p1->getOrdersList().orders[i]->execute();
}
// Execute orders
std::cout << std::endl;
for (size_t i = 0; i < p2->getOrdersList().orders.size(); i++)
{
p2->getOrdersList().orders[i]->execute();
}
// Execute orders
std::cout << std::endl;
LOG("-------- Order Execution --------")
std::cout << std::endl;
for (size_t i = 0; i < p1->getOrdersList().orders.size(); i++)
{
p1->getOrdersList().orders[i]->execute();
}
/// Clean Players
DELETE(p1);
DELETE(p2);
DELETE(armies);
DELETE(armies2);
}