Write a basic bowling game scoring calculator, which accepts individual rolls and provides the correct score for them.
A bowling game is broken down into multiple attempts to knock down 10 pins with your ball. Each turn you get two attemps to knock down all 10 pins. Each turn is called a frame during scoring.
If you do not knock down all 10 pins in a frame, it is considered open.
The score of the frame is simply the number of pins knocked down total.
If you knock down all 10 pins using both rolls of a frame, you get a spare.
A spare earns 10 points, plus the number of pins knocked down in your next roll.
If you knock down all 10 pins in a single roll, you get a strike.
Strikes earn 10 points, plus the sum of your next two rolls.
Scoring the 10th frame works slightly differently
- If you roll a strike on the first attempt, the pins are reset you get two more rolls
- If you roll a spare in the first two appempts, the pins are reset and you get 1 additional roll
- If you roll an open frame, the your turn is over
There are no modifiers applied to the 10th frame, the score is the number of pins knocked down.
A number of tests have been written for you, with all but the first commented out.
Work through each test until you get it passing, and then uncomment the next. Repeat this, ensuring that previously passing tests don't regress, until you have a fully green suite.
It should be noted that these tests do not account for every possible scenario in bowling, but you should limit the scope of your efforts here to the conditions they do set up for you!
- when a spare is scored
- in:
3, 7, 5, 0
- out:
20
- in:
- when a strike is scored
- in:
10, 5, 4
- out:
28
- in:
- when adjacent pair equals 10 but in different frames
- in:
3, 3, 7, 2
- out:
15
- in:
- when a strike precedes a spare
- in:
10, 3, 7, 5, 0
- out:
40
- in:
- perfect game
- in:
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10
- out:
300
- in: