-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplayer.cpp
More file actions
56 lines (51 loc) · 1.53 KB
/
player.cpp
File metadata and controls
56 lines (51 loc) · 1.53 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
#include <string>
#include <list>
#include <map>
#include <vector>
#include <cmath>
#include <algorithm>
#include "territory.h"
#include "card.h"
typedef std::map<char, std::pair<char, char>> CONTINENT_DATA;
char Player::getContinentIncome(CONTINENT_DATA cd) const {
char troop_bonus = 0;
std::vector<char> continent_count{0,0,0,0,0,0};
std::list<Territory*>::const_iterator itr = territories.begin();
for (; itr != territories.end(); ++itr) {
continent_count[(*itr)->getContinent()]++;
}
CONTINENT_DATA::iterator cd_itr;
cd_itr = cd.begin();
for (int j = 0; j < 6; j++) {
if (continent_count[j] == cd_itr->second.first) {
troop_bonus += cd_itr->second.second;
}
++cd_itr;
}
return troop_bonus;
}
short Player::getIncome(CONTINENT_DATA cd) const {
return std::max(3, (int)floor(num_territories/3)) + getContinentIncome(cd);
}
bool Player::playCards(const Card& c1, const Card& c2, const Card& c3) {
std::list<Card>::iterator c1_itr = find(cards.begin(), cards.end(), c1);
std::list<Card>::iterator c2_itr = find(cards.begin(), cards.end(), c2);
std::list<Card>::iterator c3_itr = find(cards.begin(), cards.end(), c3);
if (c1_itr != cards.end() && c2_itr != cards.end() && c3_itr != cards.end()) {
cards.erase(c1_itr);
cards.erase(c2_itr);
cards.erase(c3_itr);
return true;
}
return false;
}
void Player::removeTerritory(Territory* t) {
std::list<Territory*>::iterator itr = territories.begin();
for (; itr != territories.end(); itr++) {
if (*itr == t) {
territories.erase(itr);
num_territories--;
return;
}
}
}