-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.cpp
164 lines (147 loc) · 3.78 KB
/
player.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include "player.hpp"
Player::Player(string name_, string post_, bool red_card_, int yellow_card_, vector<float> scores_,
vector<bool> injured_, int price_, vector<int> num_goals_,
vector<int> num_assists_) {
{
name = name_;
post = post_;
vector<bool> red(NUM_WEEK, false);
red_card = red;
vector<bool> yellow(NUM_WEEK, false);
yellow_card = yellow;
is_playing = yellow;
scores = scores_;
injured = injured_;
selected_week = 0;
price = price_;
clean_sheet=0;
// num_assists = num_assists_;
// num_goals = num_goals_;
vector<int> goals(NUM_WEEK, 0);
vector<int> assist(NUM_WEEK, 0);
num_goals = goals;
num_assists = assist;
num_own_goals=goals;
location= vector<string> (NUM_WEEK, "");
}
}
bool Player::isAvailable(int week) {
if (week >= 2)
if (red_card[week - 2] || (calc_yellow() != 0 && calc_yellow() % 3 == 0) || isInjured(week)) {
for (int i = 0; i < week; ++i) {
yellow_card[i] = false;
}
return false;
}
return true;
}
bool Player::isInjured(int week) {
if (week < 4)
return false;
return (injured[week - 2] && injured[week - 3] && injured[week - 4]);
}
float Player::avg_score() {
float total = 0;
float num = 0;
for (auto score: scores) {
total += score;
if (score != 0)
num++;
}
if (num != 0)
return total / num;
return 0.0;
}
float Player::totalScore() {
float total = 0;
for (auto score: scores)
total += score;
return total;
}
int Player::calc_yellow() {
int yellows = 0;
for (auto yellow: yellow_card)
if (yellow)
yellows++;
return yellows;
}
float Player::cal_player_score_base_match(int num_week, int GF, int GA) {
float score = 0;
if (num_own_goals[num_week] > 0)
{
score -= (3 * num_own_goals[num_week]) ;
}
if (post == "goal_keeper") {
score = GoalkeeperScore(GA, score);
} else if (post == "deafender") {
score = defenderScore(num_week, GA, score);
} else if (post == "midfielder") {
score = midfielderScore(num_week, GA, score);
} else if (post == "forward") {
score = forwardScore(num_week, GF, score);
}
return score;
}
int Player::forwardScore(int num_week, int GF, int score) {
if (GF == 0) {
score += -1;
}
score += (num_goals[num_week] * 3);
score += (num_assists[num_week] * 1);
return score;
}
int Player::midfielderScore(int num_week, int GA, int score) {
if (GA == 0) {
score += 1;
clean_sheet++;
}
score += (num_goals[num_week] * 3);
score += (num_assists[num_week] * 2);
return score;
}
int Player::defenderScore(int num_week, int GA, int score) {
score+=1;
if (GA == 0) {
score += 2;
clean_sheet++;
}
score += (num_goals[num_week] * 4);
score += (num_assists[num_week] * 3);
return score;
}
int Player::GoalkeeperScore(int GA, int score) {
score+=3;
if (GA == 0) {
score += 5;
clean_sheet++;
} else {
score -= (GA * 1);
}
return score;
}
float Player::convertRawScore(int raw_score) {
float score = -raw_score / 6.0;
score = exp(score);
score += 1;
score = 1 / score;
score *= 10;
return score;
}
int Player::get_total_goals(int week) {
int sum=0;
for(auto goal:num_goals)
sum+=goal;
return sum;
}
int Player::get_total_assist(int week) {
int sum=0;
for(auto assist:num_assists)
sum+=assist;
return sum;
}
float Player::get_total_score() {\
float sum=0;
for(auto score:scores)
sum+=score;
return sum;
}