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 pathcup.cpp
85 lines (72 loc) · 2.38 KB
/
cup.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
#include "cup.h"
using namespace std;
void Cup::add_team(string team_name, string stadium_name, int capacity, float impact, map<string, int> fans_in_stadium) {
teams.push_back(new Team(team_name, stadium_name, capacity, impact, fans_in_stadium));
}
void Cup::add_player(string team_name, string player_name, int player_power, string player_post) {
int index = get_team_index(team_name);
if (index == NOT_FOUND)
abort();
teams[index]->add_player(player_name, player_power, player_post);
}
int Cup::get_team_index(string team_name) {
for (int i = 0; i < teams.size(); i++)
if (teams[i]->get_name() == team_name)
return i;
return NOT_FOUND;
}
void Cup::simulate(){
check_teams();
vector<Team*> in_cup_teams = get_in_cup_teams();
if(validate_number_of_teams(in_cup_teams)){
int round_number = 1;
while(in_cup_teams.size() != 1){
Round new_round(in_cup_teams, round_number);
new_round.simulate();
rounds.push_back(new_round);
in_cup_teams = get_in_cup_teams();
round_number++;
}
}
}
vector<Team*> Cup::get_in_cup_teams() {
vector<Team*> in_cup_teams;
for (int i = 0; i < teams.size(); i++)
if (teams[i]->is_participating())
in_cup_teams.push_back(teams[i]);
return in_cup_teams;
}
void Cup::check_teams() {
for (int i = 0; i < teams.size() ; i++ ) {
if (!teams[i]->is_valid()) {
teams[i]->set_participation_status(false);
cout << "Inadequate players in " << teams[i]->get_name() << endl;
}
else
teams[i]->generate_squad();
}
}
bool Cup::validate_number_of_teams(vector<Team*> in_cup_teams) {
int n = 0;
for (int i = 0; i < teams.size() ; i++ )
if (teams[i]->is_valid())
n++;
if ((n == 0) or ((n & (n-1)) != 0)) {
cout << "Inadequate teams" << endl;
return false;
}
return true;
}
void Cup::print_tournament_results() {
for (int i = 0; i < rounds.size(); i++)
rounds[i].print_round();
}
void Cup::print_round_results(int round_number) {
if (rounds.size() >= round_number)
rounds[round_number-1].print_round();
}
void Cup::print_team_results(string team_name) {
Team* team = teams[get_team_index(team_name)];
for (int i = 0; i < rounds.size(); i++)
rounds[i].print_team_result(team);
}