-
Notifications
You must be signed in to change notification settings - Fork 0
/
tiebreak_long.py
78 lines (77 loc) · 3.15 KB
/
tiebreak_long.py
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
def comp101_tiebreaker(points, server):
score1 = 0
score2 = 0
i = 0
rem = []
for a in points:
if a == 0:
score1 = score1 + 1
elif a == 1:
score2 = score2 + 1
else:
print('Error in input')
return
i = i + 1
if (score1 >= 7 or score2 >= 7) and abs(score1 - score2) >= 2:
rem = points[i:]
break
# once score 1 or score2 hits 7, remainder index changes the points
# so it follows tiebreaker rule
t = 7
# presents score with server 0 score first
if server == 0:
if score1 > 7:
if (score1 - score2) > 2:
# score presented in order of (game score, winner, remainder)
return '{}-{}'.format(score1, score2), 0, rem
elif (score1 - score2) == 2:
return '{}-{}'.format(score1, score2), 0, rem
if (score1 - score2) < 2:
return '{}-{}'.format(score1, score2), None, rem
elif score1 == 7:
if (score1 - score2) >= 2:
return '{}-{}'.format(score1, score2), 0, rem
else:
return '{}-{}'.format(score1, score2), None, rem
elif score2 > 7:
if (score2 - score1) > 2:
return '{}-{}'.format(score1, score2), 1, rem
elif (score2 - score1) == 2:
return '{}-{}'.format(score1, score2), 1, rem
if (score2 - score1) < 2:
return '{}-{}'.format(score1, score2), None, rem
elif score2 == 7:
if (score2 - score1) >= 2:
return '{}-{}'.format(score1, score2), 0, rem
else:
return '{}-{}'.format(score1, score2), None, rem
elif score1 < 7 or score2 < 7:
return '{}-{}'.format(score1, score2), None, rem
# presents server 1 score first
if server == 1:
if score1 > 7:
if (score1 - score2) > 2:
return '{}-{}'.format(score2, score1), 0, rem
elif (score1 - score2) == 2:
return '{}-{}'.format(score2, score1), 0, rem
if (score1 - score2) < 2:
return '{}-{}'.format(score2, score1), None, rem
elif score1 == 7:
if (score1 - score2) >= 2:
return '{}-{}'.format(score2, score1), 0, rem
else:
return '{}-{}'.format(score2, score1), None, rem
elif score2 > 7:
if (score2 - score1) > 2:
return '{}-{}'.format(score2, score1), 1, rem
elif (score2 - score1) == 2:
return '{}-{}'.format(score2, score1), 1, rem
elif (score2 - score1) < 2:
return '{}-{}'.format(score2, score1), None, rem
elif score2 == 7:
if (score2 - score1) >= 2:
return '{}-{}'.format(score2, score1), 0, rem
else:
return '{}-{}'.format(score2, score1), None, rem
elif score1 < 7 or score2 < 7:
return '{}-{}'.format(score2, score1), None, rem