-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.h
113 lines (93 loc) · 2.41 KB
/
player.h
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
#ifndef PLAYER_H
#define PLAYER_H
#include <string>
#include <unordered_map>
#include <functional>
#include <vector>
enum class position {G,DC,DCG,DCD,DG,DD,MDC,MC,MCD,MCG,MOC,MG,MD,AG,AD,BU,BUD,BUG};
namespace std{
template<>
struct hash<position>{
std::size_t operator()(const position& p) const
{
return (hash<int>()(static_cast<int>(p)));
}
};
}
namespace std{
template<>
struct hash<pair<string,string>>{
size_t operator()(const pair<string,string> & p) const{
auto h1 = hash<string>()(p.first);
auto h2 = hash<string>()(p.second);
return h1^(h2<<1);
}
};
}
class player
{
private :
std::string first_name;
std::string last_name;
std::unordered_map<position,int> values;
using synergyMap = std::unordered_map<std::pair<std::string,std::string>,double>;
synergyMap player_synergies;
public:
player(std::string, std::string);
virtual ~player();
void set_first_name(std::string new_first_name)
{
first_name = new_first_name;
}
void set_last_name(std::string new_last_name)
{
last_name = new_last_name;
}
std::string getFirstName() const
{
return first_name;
}
std::string getLastName() const
{
return last_name;
}
synergyMap getPlayerSynergies() const
{
return player_synergies;
}
void add_positions(std::vector<std::pair<position,int>> possiblePositions)
{
for(auto it=possiblePositions.begin();it!=possiblePositions.end();++it)
{
add_position(it->first,it->second);
}
}
void add_position(position p, int value)
{
values.insert(std::pair<position,int> (p,value));
}
void add_synergy(player & p ,double d)
{
std::pair<std::string,std::string> id (p.getFirstName(),p.getLastName());
player_synergies.insert(std::pair<std::pair<std::string,std::string>,double>(id,d));
}
bool operator == (const player &other) const
{
return first_name == other.first_name &&last_name ==other.last_name;
}
std::unordered_map<position,int> getValues() const
{
return values;
}
bool canPlay(position) const;
std::vector<position> getPositions()
{
std::vector<position> positions;
for(auto & el : values)
{
positions.push_back(el.first);
}
return positions;
}
};
#endif // PLAYER_H