Code Monkey home page Code Monkey logo

tennis_tournament's Introduction

Scoring system for a tennis tournament

The scoring system for tennis works like this:

  • A game is won by the first player to have won at least four points in total and at least two points more than the opponent.

  • The running score of each game is described in a manner peculiar to tennis: scores from zero to three points are described as 0, 15, 30, 40, respectively

  • If at least three points have been scored by each player, and the scores are equal, the score is "deuce".

  • If at least three points have been scored by each side and a player has one more point than his opponent, the score of the game is "advantage" for the player in the lead.

Constraints

  • We're just worried about one game, don't worry about sets, tie breakers, etc
  • Don't worry about validation, assume the client passes in correct data

For example:

The interface will look something like this in Ruby:

  game = Game.new("player 1", "player 2")
  game.point_won_by("player 1")
  game.point_won_by("player 2")
  // this will return "15-15"
  game.score

  game.point_won_by("player 1")
  game.point_won_by("player 1")
  // this will return "40-15"
  game.score

  game.point_won_by("player 2")
  game.point_won_by("player 2")
  // this will return "Deuce"
  game.score

  game.point_won_by("player 1")
  // this will return "Advantage player 1"
  game.score

  game.point_won_by("player 1")
  // this will return "Player 1 wins"
  game.score

tennis_tournament's People

Contributors

skateonrails avatar

Watchers

 avatar James Cloos 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.