Let’s Go Bowling – An Entire Game!

In last month’s Exercise, the assignment was to craft a single frame in a game of bowling. This time, you need to stitch together 10 frames to simulate bowling an entire game.

As a review, a single frame in bowling involves several parts: Up to two balls can be rolled to knock down 10 pins. When you knock down all ten the first time, you get a strike, represented by the letter X. If you fail to knock down all ten, you roll a second ball. Knock down all ten pins with that ball and you get a spare, represented by the / symbol.

Last month you had to score only a single frame. In a true game, the scoring works differently:

  • A strike scores 10 points plus the total of the next two balls rolled.
  • A spare scores 10 points plus the total of the next ball rolled.
  • For neither a spare nor strike, the frame’s score is the sum of the two balls rolled.

Due to the way a spare and strike are scored, the 10th (final) frame provides the opportunity for up to two more balls to be rolled: If you bowl a strike in frame 10, you get two extra balls. If you bowl a spare, you get another ball. That condition makes the tenth frame special, which is something to consider when scoring an entire game.

Your assignment is to simulate a full game of bowling, all 10 frames.

The code should output the game similar to what’s shown in Figure 1, although your code doesn’t have to match that output exactly.

Figure 1. Bowling simulation, 10 frames.

Figure 1. Bowling simulation, 10 frames.

This is a tricky exercise, so give yourself plenty of time for trials and errors. Click here to view my solution. Please attempt the Exercise on your own before looking to see what I’ve done.

Leave a Reply