-
Notifications
You must be signed in to change notification settings - Fork 3
/
commentary.py
131 lines (110 loc) · 3.95 KB
/
commentary.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import random
def shout(s: str) -> str:
cleaned = ' '.join(s.split())
return cleaned
# This module contains the commentary notes.
# Wickets
bowled_commentary = [
"bowled, what a beauty! The middle stump is broken",
"bowled. The batter misses, but the ball hits the target.",
"bowled, crashing into the stumps."
]
caught_commentary = [
"caught, that was terrific! The fielder deserves a round of applause...",
"caught, that was a simple catch to the wicketkeeper.",
"caught, in the air... and straight into the hands of a fielder.",
"caught, simple catch to the fielder. That was a soft dismissal."
]
lbw_commentary = [
"LBW, dead plumb! Three reds and no inside edge, the batter has to leave",
"LBW, right in front of the wickets."
]
stumped_commentary = [
"stumped!! The batter is outside the batting crease \
and the wickets are put down!",
"stumped!! That was quick wicketkeeping.",
"stumped!! That's why you shouldn't overstep the \
batting crease unnecessarily."
]
def outCall() -> tuple:
x = random.randint(0, 5)
m = ''
if x == 0 or x == 1:
m = 'bowled'
y = random.choice(bowled_commentary)
elif x == 2 or x == 3:
m = 'caught'
y = random.choice(caught_commentary)
elif x == 4:
m = 'lbw'
y = random.choice(lbw_commentary)
elif x == 5:
m = 'stumped'
y = random.choice(stumped_commentary)
return m, y
# Runs
commentary_6runs = [
", SIX, What a shot! That went too far away from the stadium.",
", SIX, into the stands.",
", SIX, over the fielder and out of the park.",
", SIX, this one went over the roof!",
", SIX, flat six! This one was slammed into the stands"
]
commentary_5runs = [
", 5 runs to the batting side. Just a single... \
but wait! Misfield and four!",
", 5 runs to the batting side. Missed run out becomes \
worse for the fielding side as the ball races to the boundary."
]
commentary_4runs = [
", FOUR! The ball races to the boundary.",
", FOUR! The ball is too fast for the fielders \
as it races away towards the ropes!",
", FOUR! Slammed towards the ropes!",
", FOUR! One bounce, and into the stands.",
", FOUR! Misfield and four runs."
]
commentary_3runs = [
", 3 runs",
", 3 runs. That was quick running between the wickets",
", 3 runs! Brilliant effort by the fielder \
to stop the ball from hitting the ropes. One run saved."
]
commentary_2runs = [
", 2 runs",
", 2 runs. The fielders have saved two runs for their side.",
", 2 runs. Phew! The batters wanted to come back for the second, \
and they made it just in time as the wicketkeeper collected the ball."
]
commentary_1runs = [
", 1 run",
", 1 run. Just a single."
]
commentary_0runs = [
", NO RUN",
", NO RUN. Simple defense.",
", NO RUN. Left alone.",
", NO RUN. Huge shout for LBW, and it's turned down. Not out.",
", NO RUN. The batters wanted to run, but the fielders were too quick.",
]
def scoreRun(score: str, bowler: str, batter: str) -> tuple:
m = score
if score == '6':
c = bowler + " to " + batter + shout(random.choice(commentary_6runs))
elif score == '5':
c = bowler + " to " + batter + shout(random.choice(commentary_5runs))
elif score == '4':
c = bowler + " to " + batter + shout(random.choice(commentary_4runs))
elif score == '3':
c = bowler + " to " + batter + shout(random.choice(commentary_3runs))
elif score == '2':
c = bowler + " to " + batter + shout(random.choice(commentary_2runs))
elif score == '1':
c = bowler + " to " + batter + shout(random.choice(commentary_1runs))
elif score == '0':
c = bowler + " to " + batter + shout(random.choice(commentary_0runs))
elif score == 'W':
m, y = outCall()
c = bowler + " to " + batter + ", OUT, " + shout(y)
print(c)
return m, c