In this exercise, let's explore a common and fun game: Bowling!
In particular, we'll take a look at the not so conventional way of keeping score in this game.
Scoring in bowling
In a standard game of bowling, a player gets 10 turns. In each turn, the goal is to knock down the 10 pins located at the end of the lane, by throwing a large ball at them. And the player gets 2 shots per turn.
For example, on her first turn Alice takes 2 shots:
In a simple world, that's all there is to it. At the end of the 10 rounds, you sum the scores and get the final score for the game. And it would make for a very boring exercise.
The scoring rules get more complicated by introducing multipliers. There are 2 kinds of multipliers one can get, and they both involve knocking down the 10 pins.
The Spare
A spare happens when a player knocks down the 10 pins in one round and 2 shots. Any combination that adds up to 10 can be a spare:
Example: If a player scores:
The Strike
A strike happens when a player knocks down the 10 pins in the first shot of any round.
Bonus: If a player scores:
Important note: The final score of a strike round is determine only once the final score of the succeeding round is determined. This can be tricky if you have 2 or more successive strikes.
Reminder: 0 - 10 is not a strike. It's a spare. A strike has to be done in the first shot of the round.
Final round multipliers
What happens if you knock down the 10 pins in the last (10th) round? Well, the rules say you can get more shots with a maximum of 3 shots in the last round. So you can get a spare + 1 shot, or 2 strikes + 1 shots.
If your extra shot is a strike, it's worth only 10 points.
Exercise
Given a space separated series of scores, your goal is to write a program that calculates the total score of a player in a game. For instance:
Your program should be tested against the above examples.
Bonus question
What's the maximal score one can get in Bowling?
10 10 10 10 10 10 10 10 10 10 10 10
In particular, we'll take a look at the not so conventional way of keeping score in this game.
Scoring in bowling
In a standard game of bowling, a player gets 10 turns. In each turn, the goal is to knock down the 10 pins located at the end of the lane, by throwing a large ball at them. And the player gets 2 shots per turn.
For example, on her first turn Alice takes 2 shots:
- The first shot knocks down 6 pins
- The second shot knocks down 2 of the remaining 4 pins
In a simple world, that's all there is to it. At the end of the 10 rounds, you sum the scores and get the final score for the game. And it would make for a very boring exercise.
The scoring rules get more complicated by introducing multipliers. There are 2 kinds of multipliers one can get, and they both involve knocking down the 10 pins.
The Spare
A spare happens when a player knocks down the 10 pins in one round and 2 shots. Any combination that adds up to 10 can be a spare:
- 6-4
- 9-1
- 0-10
Example: If a player scores:
- 6 - 4 - 7 - 2
The Strike
A strike happens when a player knocks down the 10 pins in the first shot of any round.
Bonus: If a player scores:
- 10 - 3 - 2
Important note: The final score of a strike round is determine only once the final score of the succeeding round is determined. This can be tricky if you have 2 or more successive strikes.
- 10 - 10 - 4 - 2
- The 3rd round: 6 points
- The 2nd round: 10 + 6 = 16 points
- The 1st round: 10 + 16 = 26 points
- Total: 26 + 16 + 6 = 48 points in 3 rounds
Reminder: 0 - 10 is not a strike. It's a spare. A strike has to be done in the first shot of the round.
Final round multipliers
What happens if you knock down the 10 pins in the last (10th) round? Well, the rules say you can get more shots with a maximum of 3 shots in the last round. So you can get a spare + 1 shot, or 2 strikes + 1 shots.
If your extra shot is a strike, it's worth only 10 points.
Exercise
Given a space separated series of scores, your goal is to write a program that calculates the total score of a player in a game. For instance:
- 2 3 4 4 6 2 1 0 2 4 5 2 9 0 1 1 3 4 2 2. Total = 57
- 2 3 4 6 6 2 1 0 2 4 5 2 9 0 1 1 3 4 2 2. Total = 65
- 2 3 4 6 10 1 0 2 4 5 2 9 0 1 1 3 4 2 2. Total = 72
- 2 3 4 6 0 10 1 0 2 4 5 2 9 0 1 1 3 4 2 2. Total = 62
Your program should be tested against the above examples.
Bonus question
What's the maximal score one can get in Bowling?
10 10 10 10 10 10 10 10 10 10 10 10