Giter Club home page Giter Club logo

onsdigital.onse-bowling-game's Introduction

TDD Demo - Bowling Game Kata

This repository forms part of the ONS Software Development Practices engineering training sessions. It contains a base project to run the bowling game kata from.

Branches

  • master an empty project which can be used to practice/demonstrate the kata
  • completed a branch with the completed code and a commit history detailing each step.

Bowling Game Kata

The bowling game kata is a well know code kata. The aim is to use TDD to implement a class which calculates the score of a 10 pin bowling game. The class should have the following interface:

class BowlingGame:
    def roll(self, pins):
        """
        Call this each time a ball is rolled passing in the number of pins that
        were knocked down.
        """

    def score(self):
        """
        Call this at the end of the game to get the final score.
        """

Rules of 10 Pin Bowling

  • A game has 10 frames
  • A player has 2 rolls per frame to try and knock down all 10 pins
  • If a player knocks down all 10 pins in a frame then they score a spare:
    • The score for a spare is the 10 pins plus the next roll as a bonus
  • If a player knocks down all 10 pins in the first roll of a frame then they score a strike:
    • If a strike is scored then there is no second roll in the frame
    • The score for a strike is the 10 pins plus the next 2 rolls as a bonus
    • If a strike is scored in the last frame then 2 bonus rolls are added to the frame
  • A perfect game is 12 successive strikes and scores 300 points

Exceptions & Edge Cases

For a real implementation of this you would want to check for errors, including the following:

  • Negative number of pins passed to roll
  • More than 10 pins passed to roll
  • Score called before the game is completed
  • Roll called too many times

However, for this demonstration we are only focussing on the happy path.

onsdigital.onse-bowling-game's People

Contributors

tomphp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.