Class Kata "Bowling"

Develop a class for counting Bowling games.

A bowling game consists of rolls to clear 10 pins at the end of the bowling lane. This means that 0 to 10 pins can be knocked down with each roll. A player has a maximum of 2 throws per round to clear the 10 pins.

Throws are grouped into frames, each of which is assigned a score. A game consists of 10 rounds or frames.

The number of throws a player may make per round depends on how many pins are thrown with them:

  • If a player's first throw clears all 10 pins (strike), it is the only throw in the round.
  • Otherwise, the frames always contain two throws, each with 0 to 10 pins.
    • Exception: If the 10th frame contains a strike as the first throw or both throws together result in a spare (see below), then a third throw can be made.

There are a few rules for calculating the score of a frame:

  • A frame whose two throws together have broken a maximum of 9 pins receives the sum of the pins as the score.
  • A frame whose two throws together have scored 10 pins (spare) receives a score of 10 + the number of pins of the next throw.
  • A frame with a strike receives a score of 10 + the sum of the pins of the next two throws.

Robert C. Martin provides this description [1] for a game of bowling:

Class Kata Bowling I - Clean Code Developer Akademie

Each frame shows the first and second throw and even the third throw with their pins and the cumulative score. If the box for the second throw is half filled, there is a spare, if it is completely filled, the first throw was a strike.

The class interface should look like this:

class Game {
	void AddRoll(int pins) {...}
	Frame[] Frames() {...}
	int TotalScore() {...}
	bool Over() {...}

class Frame {
	int[] PinsRolled;
	int Score; // Score of this frame only

AddRoll() throws an exception if throws are still to be registered after the end of the game.

The game from the illustration above with Game carried out:

Class Kata Bowling II - Clean Code Developer Akademie


[1] Rober C. Martin, Bowling Game Kata