-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbowling_orig.py
46 lines (44 loc) · 1.33 KB
/
bowling_orig.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
def score(game):
result = 0
frame = 1
in_first_half = True
for i in range(len(game)):
if game[i] == '/':
result += 10 - last
else:
result += get_value(game[i])
# if not in_first_half:
# frame += 1
if frame < 10 and get_value(game[i]) == 10:
if game[i] == '/':
result += get_value(game[i+1])
elif game[i] == 'X' or game[i] == 'x':
result += get_value(game[i+1])
if game[i+2] == '/':
result += 10 - get_value(game[i+1])
else:
result += get_value(game[i+2])
last = get_value(game[i])
if not in_first_half:
frame += 1
if in_first_half == True:
in_first_half = False
else:
in_first_half = True
if game[i] == 'X' or game[i] == 'x':
in_first_half = True
frame += 1
return result
def get_value(char):
if char == '1' or char == '2' or char == '3' or \
char == '4' or char == '5' or char == '6' or \
char == '7' or char == '8' or char == '9':
return int(char)
elif char == 'X' or char == 'x':
return 10
elif char == '/':
return 10
elif char == '-':
return 0
else:
raise ValueError()