-
Notifications
You must be signed in to change notification settings - Fork 0
/
Match.cc
88 lines (73 loc) · 1.73 KB
/
Match.cc
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
/** @file Match.cc
@brief Código de la clase Match
*/
#include "Match.hh"
Match::Match(const std::string& input, int left_pos, int right_pos){
this -> left_pos = left_pos;
this -> right_pos = right_pos;
this -> input = input;
read_match();
}
Match::Match(int only) {
left_pos = only;
b_winner = true;
empty = true;
}
void Match::read_set(set& s, int& i) {
s.first = input[i] - '0';
left_games += s.first;
s.second = input[i + 2] - '0';
right_games += s.second;
i += 4;
}
void Match::read_match() {
set s;
bool invalid = false;
int i = 0;
while (left_sets != 2 and right_sets != 2) {
if (i + 2 < input.size())
read_set(s, i);
if (s.first == 1 and s.second == 0) {
left_sets = 2;
invalid = true;
}
else if (s.first == 0 and s.second == 1) {
right_sets = 2;
invalid = true;
}
else if (s.first > s.second) ++left_sets;
else ++right_sets;
}
b_winner = left_sets > right_sets;
if (invalid) {
left_games = 0;
right_games = 0;
left_sets = 0;
right_sets = 0;
}
}
int Match::get_winner() const{
if (b_winner) return left_pos;
else return right_pos;
}
int Match::get_sets(bool left) const {
if (left) return left_sets;
else return right_sets;
}
int Match::get_games(bool left) const {
if (left) return left_games;
else return right_games;
}
int Match::get_pos(bool left) const {
if (left) return left_pos;
else return right_pos;
}
bool Match::get_bool() const {
return b_winner;
}
std::string Match::get_result() const {
return input;
}
bool Match::is_empty() const {
return empty;
}