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.
Read the rolls
Recognize complete frames while preserving the extra rolls required by the tenth frame.
Classify each frame
Distinguish open frames, spares, and strikes so each rule is explicit.
Apply look-ahead
Use following rolls as bonuses without scoring those rolls twice as frames.
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.