-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup.cpp
69 lines (63 loc) · 1.79 KB
/
group.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
#include "group.h"
#include "team.h"
#include <cstdint>
#include <string>
#include <iostream>
#include <random>
#include <vector>
#include <omp.h>
using namespace std;
group::group(group* g){
this->teams.push_back(new team(g->teams[3]));
this->teams.push_back(new team(g->teams[2]));
this->teams.push_back(new team(g->teams[1]));
this->teams.push_back(new team(g->teams[0]));
}
group::group(team* t1,team* t2,team* t3,team* t4)
{
this->teams.push_back(t1);
this->teams.push_back(t2);
this->teams.push_back(t3);
this->teams.push_back(t4);
}
void group::generateMatch(int t1, int t2){
double porcentage = ((this->teams[t1]->rating*100)/(this->teams[t1]->rating+this->teams[t2]->rating))-10;
random_device rd;
mt19937 rng(rd());
uniform_int_distribution<int> uni(0,100);
int random_int = uni(rng);
if (random_int<21){
this->teams[t1]->pts++;
this->teams[t2]->pts++;
}else if(random_int<21+porcentage){
this->teams[t1]->pts = this->teams[t1]->pts + 3;
}else{
this->teams[t2]->pts = this->teams[t2]->pts + 3;
}
}
void group::generateGroupResults(){
generateMatch(0,1);
generateMatch(2,3);
generateMatch(0,3);
generateMatch(2,1);
generateMatch(0,2);
generateMatch(1,3);
sort(this->teams.begin(),this->teams.end(),[](const team* lhs, const team* rhs){return lhs->pts > rhs->pts;});
for(int i = 0; i<4;i++){
this->teams[i]->totalPts = this->teams[i]->pts + this->teams[i]->totalPts;
if(i==0){
this->teams[i]->first++;
}else if(i==1){
this->teams[i]->second++;
}else if(i==2){
this->teams[i]->third++;
}else{
this->teams[i]->fourth++;
}
this->teams[i]->pts = 0;
}
}
group::~group()
{
//dtor
}