This repository has been archived by the owner on Jul 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatch.cpp
63 lines (53 loc) · 2.03 KB
/
match.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
#include "match.h"
using namespace std;
Match::Match(Team* home, Team* away, int number)
: first_leg(home, away), second_leg(away, home), match_number(number), first_team(home), second_team(away) {
winner = NULL;
}
void Match::simulate() {
first_leg.simulate();
second_leg.simulate();
}
void Match::determine_winner() {
if (first_leg.get_home_goals() + second_leg.get_away_goals() > second_leg.get_home_goals() + first_leg.get_away_goals()) {
second_team->set_participation_status(false);
winner = first_team;
}
else if (first_leg.get_home_goals() + second_leg.get_away_goals() < second_leg.get_home_goals() + first_leg.get_away_goals()) {
first_team->set_participation_status(false);
winner = second_team;
}
else if (first_leg.get_home_goals() > second_leg.get_home_goals()) {
second_team->set_participation_status(false);
winner = first_team;
}
else if (first_leg.get_home_goals() < second_leg.get_home_goals()) {
first_team->set_participation_status(false);
winner = second_team;
}
else
penalty_time();
}
void Match::penalty_time() {
int first_team_fans_impact = second_team->get_fans_impact(first_team);
int second_team_fans_impact = second_team->get_fans_impact();
float prob1 = ((float)first_team->get_attack_power() + first_team_fans_impact) / (second_team->get_goalkeeper_power());
float prob2 = ((float)second_team->get_attack_power() + second_team_fans_impact) / (first_team->get_goalkeeper_power());
if (prob1 > prob2) {
second_team->set_participation_status(false);
winner = first_team;
}
else {
first_team->set_participation_status(false);
winner = second_team;
}
}
void Match::print_match() {
cout << match_number << ":" << endl;
first_leg.print_leg();
second_leg.print_leg();
cout << '\t' << "=> winner: " << winner->get_name() << endl;
}
bool Match::contains(Team* team) {
return (team == first_team) or (team == second_team);
}