Git Product home page Git Product logo

bowler's Introduction

Bowler

A simple browser-based system for scoring a game of bowling.

A simple browser-based system for scoring a game of bowling

Rules of the game

  • A game consists of 10 frames.
  • In general each frame has 2 rolls.
  • In general a player scores the number of pins knocked down.
  • If the player knocks down all 10 pins on the first roll it’s a strike. The player scores 10 plus the number of pins knocked down in the next two rolls.
  • If the player knocks down all 10 pins in two rolls it’s a spare. The player scores 10 plus the number of pins knocked down in the next roll.

Further details about the way bowling is scored can be sought here.

Solution

To achieve this, I have opted to use an array of frames that behave like a crude singly linked list. The following diagrams attempt to explain the implementation:

Each frame (bar the last) has a reference to the next frame in the list

  1. Each frame (bar the last) has a reference to the next frame in the list.

Each roll is passed through the list of frames

  1. Each roll is passed through the list of frames.

The roll continues through the list until it reaches the active (or "current") frame

  1. The roll continues through the list until it reaches the active (or "current") frame. The score is then added to this frame, and the frame decides whether it is still active.

If the frame decides it is no longer active (all pins have been knocked down or there have been 2 rolls) it then moves the active state to the next frame in the list.

Through this process, the game progresses through each frame until the last. The final frame is then responsible for communicating that the game has finished.

  1. As each roll is passed through all frames preceding the active one, frames which need to add subsequent rolls to their score (in the case of a strike or a spare) are able to do so.

Disadvantages of this approach

There are a number of disadvantages to this approach, some of which are:

  • All frames must be created and linked to their neighbour at the beginning of the game
  • The last frame is responsible for communicating game completion, which should ideally be a responsibility of the game class itself
  • The list must be traversed in order to calculate the total score as the game progresses

Setup

To get started, you will need to install the dependencies with npm:

npm install

If you don't have gulp installed globally, you will also need to do so:

npm install -g gulp

Once installed, you can generate the needed assets with gulp:

gulp build

Or run the unit tests (which will also perform a build):

gulp test

For development, I recommend use of the watch task (gulp watch). It will build and re-run tests whenever you make changes to the source Javascript files (tests included).

Some areas for improvement

  • Rendering: The current implementation of rendering is super crude. It redraws the entire list of frames after each move which leaves much room for improvement
  • Cumulative scoring: At present, each frame only renders its own score. Typically, bowling scorers show a cumulative total in each frame
  • Functional tests

License

MIT. Use as you please!

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.