Back to the catalog

Games & scoring · Project entry

Bowling Scoring

A compact rules-engine problem where a roll can affect the score of later frames, and the final frame deliberately breaks the ordinary pattern.

Origin
Udacity CS212 final exam · Peter Norvig
Core ideas
Rule modeling · sequence processing
Interface
Named functions and assertions
Status
Working evidence; canonical version unresolved

00 · Problem background

A final-exam exercise built around deceptively compact rules.

This project began with Unit 1 of Peter Norvig's Udacity CS212 final exam. The supplied interface takes a sequence of pins knocked down by each roll and returns the integer score for a complete ten-pin game.

The exercise supplied the rules that drive the design: ten frames, ordinary two-roll frames, one-roll strikes, next-roll and next-two-roll bonuses, special tenth-frame bonus rolls, and a twelve-strike perfect game scoring 300.

01 · Problem

A frame is not an isolated score.

Open frames can be totaled immediately, but a spare depends on the next roll and a strike depends on the next two. The tenth frame adds bonus rolls while still representing a single scoring frame.

02 · Approach

Separate roll parsing from bonus accounting.

A

Read the rolls

Recognize complete frames while preserving the extra rolls required by the tenth frame.

B

Classify each frame

Distinguish open frames, spares, and strikes so each rule is explicit.

C

Apply look-ahead

Use following rolls as bonuses without scoring those rolls twice as frames.

  • Python
  • standard library
  • rules engine
  • sequence processing
  • assertion tests

03 · Lessons

Edge cases reveal the real model.

  • Input structure and scoring structure differ.Bonus rolls belong to the tenth frame even though they resemble later frames in the roll stream.
  • Readable rule names reduce mistakes.Named frame cases make the scoring logic easier to verify than a single dense loop.
  • Examples are executable documentation.Perfect games, all-spare games, and mixed sequences provide high-value regression cases.

04 · Future demonstration

Show where every bonus comes from.

A roll-entry playground could render all ten frames and draw bonus connections forward, revealing why each frame total changes as new rolls arrive.

Verification boundary: the exercise origin is confirmed as Peter Norvig's Udacity CS212 final exam. The two historical variants have not been fully compared, so bowling_main.py remains a provisional entry point, and neither variant was executed during inventory.