Giter Site home page Giter Site logo

ten-pin-scoring's Introduction

Ten pin scoring system

Scoring for the classical game of ten pin

Overview

  • Given a list of scores:
    • Validates the input scores
    • Builds the score card

System Requirements

  • jvm
  • clojure

Functionality

  • compute-score-card is the main function. Accepts a list of scores
    • it validates a list of scores and takes care of cases like:
      • Too many scores in the input list
      • Extra turn when the last one is a strike or spare
      • Invalid score combination (i.e > 10) for a given turn
    • For an input like [1 9 2 4 10 10 10 7 1 2 8 7 0 0 0 10 1 9] it gives an output as:
       {:turns
       ({:first-pins 1,
         :second-pins 9,
         :curr-turn-score 12,
         :score 12,
         :turn-type :spare}
        {:first-pins 2,
         :second-pins 4,
         :curr-turn-score 6,
         :score 18,
         :turn-type :open}
        {:first-pins 10,
         :second-pins nil,
         :curr-turn-score 30,
         :score 48,
         :turn-type :strike}
        {:first-pins 10,
         :second-pins nil,
         :curr-turn-score 27,
         :score 75,
         :turn-type :strike}
        {:first-pins 10,
         :second-pins nil,
         :curr-turn-score 18,
         :score 93,
         :turn-type :strike}
        {:first-pins 7,
         :second-pins 1,
         :curr-turn-score 8,
         :score 101,
         :turn-type :open}
        {:first-pins 2,
         :second-pins 8,
         :curr-turn-score 17,
         :score 118,
         :turn-type :spare}
        {:first-pins 7,
         :second-pins 0,
         :curr-turn-score 7,
         :score 125,
         :turn-type :open}
        {:first-pins 0,
         :second-pins 0,
         :curr-turn-score 0,
         :score 125,
         :turn-type :open}
        {:first-pins 10,
         :second-pins 1,
         :curr-turn-score 20,
         :score 145,
         :turn-type :strike,
         :third-pins 9}),
       :status :over}
      
      where turns gives the elaborate score card and status denotes of game has started/ on-going/ over and third-pins only appear in the last turn score if it is a strike or spare

Implementation Details and Todos

  • The function signature accepts a list of scores so frontend has to store minimum data as game state
  • Used minimum clojure features
  • Used recursion where possible
  • Would like to improve the validation function to precisely say why the validation failed
  • Would definitely like to refactor the code to reduce procedural conditions and make more functional

Unit Test

lein test

ten-pin-scoring's People

Contributors

sushovannits avatar

Stargazers

 avatar  avatar

Watchers

 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.