-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAggressivePlayerStrategy.cpp
77 lines (72 loc) · 2.99 KB
/
AggressivePlayerStrategy.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
//
// Created by Ryan on 2021-12-01.
//
#include "AggressivePlayerStrategy.h"
/**
* Default constructor
* @param player link
*/
AggressivePlayerStrategy::AggressivePlayerStrategy(Player * player) {
this->p = player;
p->setName("Aggressive");
}
/**
* Issue order inherited from PlayerStrategy
*
* @param vPlayersInPlay all the other players in the game
*/
void AggressivePlayerStrategy::issueOrder(vector<Player *> &vPlayersInPlay) {
for (int i = 0; i < toDefend().size(); i++) {
if (toDefend().at(i)->IsAdjacent(*toAttack().at(0))) {
auto * deploy = new Deploy(p->getReinforcements(), *toDefend().at(i));
deploy->setPlayerLink(*p);
p->getOrdersList()->addDeploy(deploy);
int advancingarmies = p->getReinforcements() + toDefend().at(i)->unitsGarrisoned;
auto * advance = new Advance(advancingarmies,*toDefend().at(i) , *toAttack().at(0));
advance->setPlayerLink(*p);
p->getOrdersList()->addAdvance(advance);
i = toDefend().size();
}
}
}
/**
* Displays all adjacent territories to owned territories
*
* @return vector of all adjacent territories
*/
vector<Territory*> AggressivePlayerStrategy::toAttack() {
vector<Territory *> territoriesToAttack;
//loop through player owned territories
for (int i = 0; i < p->getTerritorySize(); i++) {
//loop through the adjacent territories of the owned territories
for (int j = 0; j < p->getVTerritory().at(i)->adjacentTerritories.size(); j++) {
//check if that territory is already owned, if its now owned then add to list
if (this->p->isOwnedTerritory(p->getVTerritory().at(i)->adjacentTerritories.at(j)->id) == nullptr &&
!(p->isTerritoryInList(territoriesToAttack, p->getVTerritory().at(i)->adjacentTerritories.at(j)->id))) {
territoriesToAttack.push_back(p->getVTerritory().at(i)->adjacentTerritories.at(j));
}
}
}
return territoriesToAttack;
}
/**
* Displays territories owned that are adjacent to other unowned territories
*
* @return vector of all adjacent territories
*/
vector<Territory*> AggressivePlayerStrategy::toDefend() {
vector<Territory *> territoriesToDefend;
//loop through player owned territories
for (int i = 0; i < p->getTerritorySize(); i++) {
//loop through the adjacent territories of the owned territories
for (int j = 0; j < p->getVTerritory().at(i)->adjacentTerritories.size(); j++) {
//check if that territory is already owned, if the adjacent territory is not owned
if (this->p->isOwnedTerritory(p->getVTerritory().at(i)->adjacentTerritories.at(j)->id) == nullptr &&
!(p->isTerritoryInList(territoriesToDefend, p->getVTerritory().at(i)->id))) {
territoriesToDefend.push_back(
p->getVTerritory().at(i));//push the territory we own into list of territories to defend
}
}
}
return territoriesToDefend;
}