-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBagChecker.cpp
More file actions
61 lines (47 loc) · 1.79 KB
/
BagChecker.cpp
File metadata and controls
61 lines (47 loc) · 1.79 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
#include "headerFiles/BagChecker.h"
#include "headerFiles/SeaChecker.h"
#include "headerFiles/SeaCheckerFactory.h"
#include "headerFiles/SeaCreature.h"
#include <vector>
#include <unordered_map>
bool BagChecker::canKeepBag(std::vector<SeaCreature*> bag){
std::unordered_map<int, int> fishPerSpecie;
std::unordered_map<int, int> bagLimitPerSpecie;
std::unordered_map<int, int> fishPerGroup;
std::unordered_map<int, int> bagLimitPerGroup;
for (SeaCreature* s : bag) {
SeaChecker* checker = SeaCheckerFactory::create(s);
auto [result, creature] = checker->canKeep(s);
if(result){
if(fishPerSpecie.count(creature->id) > 0){
fishPerSpecie[creature->id] = fishPerSpecie[creature->id] + 1;
}else{
fishPerSpecie[creature->id] = 1;
}
if(creature->group_id != -1){
if(fishPerGroup.count(creature->group_id) > 0){
fishPerGroup[creature->group_id] = fishPerGroup[creature->group_id] + 1;
}else{
fishPerGroup[creature->group_id] = 1;
}
}
if(bagLimitPerSpecie.count(creature->id) <= 0){
bagLimitPerSpecie[creature->id] = creature->bag_limit == -1 ? 20 : creature->bag_limit;
}
}else{
return false;
}
}
for (const auto& [id, count] : fishPerSpecie) {
if(count > bagLimitPerSpecie[id]) return false;
}
for (const auto& c : data.groups){
if(bagLimitPerGroup.count(c.id) <= 0){
bagLimitPerGroup[c.id] = c.group_bag_limit;
}
}
for (const auto& [id, count] : fishPerGroup) {
if(count > bagLimitPerGroup[id]) return false;
}
return true;
}