Darts

Darts

A game of 501.

Darts is a game for two players. The objective of the game is to reach a score of exactly zero, starting from 501. In each turn a player throws up to three darts. Each dart can score 0-20, a double 1-20, a triple 1-20, a 25 or 50.

Make


Write a program to simulate the scoring for the game of darts.

If the total of the darts thrown in a turn when subtracted from the player's remaining score equals one, or less than zero then the player scores zero and their turn is over.


If the total of one or more darts thrown in a turn would result in a score of exactly zero when subtracted from the remaining score, and the last dart thrown is a double, the player wins. 50 counts as double 25.


In all other cases the total of the three darts thrown is subtracted from the score remaining and the other player then takes their turn.

Use this boilerplate code as a starting point:

Success Criteria

Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.

Complete the subprogram called `is_dart_valid` that:

  1. Returns True if the score of a single dart is valid, or False if it is not. A valid dart is...
  2. ...any score between zero and twenty.
  3. ...twenty five or fifty.
  4. ...a double. A double can be any dart scoring forty or less that is an even number.
  5. ...a triple. A triple can be any dart scoring sixty or less that is divisible by three.

Complete the subprogram called `play_game` that:

  1. Outputs whose turn it is and their current score.
  2. Allows the user to input up to three darts in a turn, validating each dart.
  3. Checks if the dart thrown causes the player to win.
  4. Updates the player score by deducting the total of the three darts from their score if that results in a score of more than one.
  5. Plays the game until a player wins.
  6. Outputs the winner.

Complete the `main program` so that:

  1. The scores of the two players are stored in a list called `score` and both start at 501 (for testing start at 101).
  2. Calls the play_game procedure.

Typical inputs and outputs from the program would be:

Player 1 it's your turn. Your score is: 501

Dart 1

Enter score: 60

Treble 20

Dart 2

Enter score: 60

Treble 20

Dart 3

Enter score: 20

140 scored.


Player 2 it's your turn. Your score is: 501

Dart 1

Enter score: 20

Dart 2

Enter score: 57

Treble 19

Dart 3

Enter score: 19

96 scored.


Player 1 it's your turn. Your score is: 361

Dart 1

Enter score: 60

Treble 20

Dart 2

Enter score: 15

Dart 3

Enter score: 20

95 scored.


Player 2 it's your turn. Your score is: 405

Dart 1

Enter score: 60

Treble 20

Dart 2

Enter score: 20

Dart 3

Enter score: 1

81 scored.


Player 1 it's your turn. Your score is: 266

Dart 1

Enter score: 60

Treble 20

Dart 2

Enter score: 57

Treble 19

Dart 3

Enter score: 57

Treble 19

174 scored.


Player 2 it's your turn. Your score is: 324

Dart 1

Enter score: 20

Dart 2

Enter score: 20

Dart 3

Enter score: 20

60 scored.


Player 1 it's your turn. Your score is: 92

Dart 1

Enter score: 60

Treble 20

Dart 2

Enter score: 32

Double 16

92 scored.

Player 1 wins the leg.

Knowledge Organiser

Use these resources as a reference to help you meet the success criteria.

Programming guide:

Evaluate


There are 301, 701, 901, 1101 and 1501 variants of darts. For the purposes of testing, set the game to 101.

Run the unit tests below to check that your program has met the success criteria.

Player 1 it's your turn. Your score is: 101

Dart 1

Enter score: 51

Treble 17

Dart 2

Enter score: 50

Shot!

101 scored.


Player 1 wins the leg.

Player 1 it's your turn. Your score is: 101

Dart 1

Enter score: 60

Treble 20

Dart 2

Enter score: 39

Treble 13

Dart 3

Enter score: 0

99 scored.

Player 1 it's your turn. Your score is: 101

Dart 1

Enter score: 60

Treble 20

Dart 2

Enter score: 40

Double 20

Bust!

0 scored.

Player 1 it's your turn. Your score is: 101

Dart 1

Enter score: 60

Treble 20

Dart 2

Enter score: 39

Treble 13

Dart 3

Enter score: 2

101 scored.


Player 1 wins the leg.

Player 1 it's your turn. Your score is: 101

Dart 1

Enter score: 20

Dart 2

Enter score: 20

Dart 3

Enter score: 20

60 scored.


Player 2 it's your turn. Your score is: 101

Dart 1

Enter score: 15

Dart 2

Enter score: 60

Treble 20

Dart 3

Enter score: 1

76 scored.


Player 1 it's your turn. Your score is: 41

Dart 1

Enter score: 9

Dart 2

Enter score: 16

Dart 3

Enter score: 8

33 scored.


Player 2 it's your turn. Your score is: 25

Dart 1

Enter score: 1

Dart 2

Enter score: 24

Double 12

25 scored.


Player 2 wins the leg.

Check that you have:

  • Used comments within the code to describe the purpose of subprograms, conditions and iterations.
  • Used meaningful identifier names. That means the names of subprograms and variables indicate what they are for.