- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtennisScore.py
More file actions
Latest commit
62 lines (47 loc) · 2.08 KB
/
Copy pathtennisScore.py
File metadata and controls
62 lines (47 loc) · 2.08 KB
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
importos
POINTSDICT= {0: 'love', 1: 15, 2: 30, 3: 40, 4: '40+adv', 5: '40+adv+adv'}
MIN_POINTS_REQ_TO_WIN=4
MIN_DIFF_REQ=2
MIN_GAMES_REQ_TO_WIN=6
PLAYER_A='A'
PLAYER_B='B'
defupdateScores(points, scores, player1, player2):
scores[player1] =POINTSDICT[points[player1]]
scores[player2] =POINTSDICT[points[player2]]
returnscores
defupdateSetWin(games, sets, player1, player2):
if (games[player1] >MIN_GAMES_REQ_TO_WINandgames[player2] ==MIN_GAMES_REQ_TO_WIN) orgames[player1]-games[player2] >=MIN_DIFF_REQ:
sets[player1] +=1
games[player1] =games[player2] =0
returngames, sets
defupdateGameWin(points, games, sets, player1, player2):
ifpoints[player1] ==MIN_POINTS_REQ_TO_WINandpoints[player2] ==MIN_POINTS_REQ_TO_WIN:
points[player1] =points[player2] =MIN_POINTS_REQ_TO_WIN-1
ifpoints[player1]-points[player2] >=MIN_DIFF_REQ:
games[player1] +=1
ifgames[player1] >=MIN_GAMES_REQ_TO_WIN:
games, sets=updateSetWin(games, sets, player1, player2)
points[player1] =points[player2] =0
returnpoints, games
defupdatePoints(points, games, sets, player1, player2):
points[player1] +=1
ifpoints[player1] >=MIN_POINTS_REQ_TO_WIN:
returnupdateGameWin(points, games, sets, player1, player2)
returnpoints, games
deftennis_match(s):
points= [0, 0]
scores= [0, 0]
games= [0, 0]
sets= [0, 0]
currentPlayerIndex=0
forplayerins:
currentPlayerIndex=0ifplayer==PLAYER_Aelse1
points, games=updatePoints(
points, games, sets, currentPlayerIndex, abs(currentPlayerIndex-1))
scores=updateScores(points, scores,
currentPlayerIndex, abs(currentPlayerIndex-1))
return"Players : A B"+"\nSets : "+str(sets)+"\nGames : "+str(games)+"\nPoints : "+str(scores)
deftennis_match_graph():
os.system("dot -T png -o tennisGameGraph.png tennisGameGraph.dot")
print(tennis_match('ABABABABAAA'))
tennis_match_graph()