-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLostAndFound.cpp
43 lines (36 loc) · 908 Bytes
/
LostAndFound.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
#include "LostAndFound.h"
#include <map>
using namespace std;
bool LostAndFound::play(vector<Player>& players) {
// vector<Card> playCards;
static map <int, Player&> playPlayers;
for (Player &p: players) {
// draw a card
int size = p.getCardSize();
if (p.getCardSize() > 0) {
Card current = p.remove();
cards.push_back(current);
playPlayers.insert(pair<int, Player&>(current.getValue(), p));
}
}
int maxValue = 0;
Player *winner;
map <int, Player&>:: iterator it;
for (it = playPlayers.begin(); it != playPlayers.end(); it++) {
int value = it->first;
if (value > maxValue) {
maxValue = value;
winner = &it->second;
} else if (value == maxValue) {
return true;
}
}
winner->addBattlesWon();
for (Card c: cards) {
winner->add(c);
}
for (Player &p: players) {
p.addBattlesPlayed();
}
return false;
}