Tennis

We need to write the logic which outputs the correct score as a string for display on the scoreboard. You can read more about Tennis scores here which is summarized below:

Court

  • There are two “players” facing each other.
  • The “players” can be made up of one or two members
  • Each “player” has the same number of members
  • Each “player” starts with 0 points, 0 sets and 0 games

Game

  • 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 “Love”, “Fifteen”, “Thirty”, and “Forty” 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

Set

  • A player wins a set by winning at least six games and at least two games more than the opponent.
  • If one player has won six games and the opponent five, an additional game is played
  • If the leading player wins that game, the player wins the set 7–5
  • If the trailing player wins the game (tying the set 6–6) a tie-break is played
  • A tie-break, played under a separate set of rules, allows one player to win one more game and thus the set, to give a final set score of 7–6

Match

  • A match consists of a sequence of sets. The outcome is determined through a best of three sets system
  • The first player to win two sets in a best-of-three, wins the match