The Dice Game Kata

Hello and welcome to this programming kata.

This kata consists of several parts where you should solve one part before you look at the next.

While you could speed through this kata by just implementing the requirements as quickly as possible, the intention of this kata is to practice Test Driven Development and as such you're recommended to think about this as production code and write proper tests for your implementation.

Where appropriate, an example will be shown to better explain the problem. These examples are perfect for an initial test case. I do recommend that you write more tests than just based on the example though, the aim, after all, is to drive development by passing tests.

Good luck!
/Raniz

Your task in this kata is to implement a dice game. The game will start out simple but will progressively become more complex. It will be an interactive application, but you are free to choose whichever language and interface type you want.

Step 1

Implement a simple dice game

Implement a dice game with three dice. The game consists of 10 throws, a player's score is the sum of all dice values thrown.

Step 2

Saving dice

The game now consist of 10 rounds. Each round consists of three throws where the player may choose to save one or more dice and only rethrow the other dice. The score for each round is the sum of the final dice values after three throws. The total score is the sum of all round scores.

Step 3

Log

After every game, print a list of all rounds and the final dice values.

Step 4

5 dice

The game now uses five dice instead of three.

Step 5

Targets

Instead of just counting values we will now try to match specific targets. In each game, the player aims to complete a list of targets. Each target can only be completed once and if the dice cannot be combined in a way that satisfies a target, the player has to choose a target to cross out and gets zero points in that round.

The different targets are:

  • One Pair: Two dice showing the same number. Score: Sum of those two dice.
  • Two Pairs: Two different pairs of dice. Score: Sum of dice in those two pairs.
  • Three of a Kind: Three dice showing the same number. Score: Sum of those three dice.
  • Four of a Kind: Four dice with the same number. Score: Sum of those four dice.
  • Small Straight: The combination 1-2-3-4-5. Score: 15 points (sum of all the dice).
  • Large Straight: The combination 2-3-4-5-6. Score: 20 points (sum of all the dice).
  • Full House: Any set of three combined with a different pair. Score: Sum of all the dice.

Step 6

Yatzy

Implement Yatzy.

In addition to the previous targets the following targets are now available:

  • Ones:The sum of all dice showing the number 1.
  • Twos:The sum of all dice showing the number 2.
  • Threes:The sum of all dice showing the number 3.
  • Fours:The sum of all dice showing the number 4.
  • Fives:The sum of all dice showing the number 5.
  • Sixes:The sum of all dice showing the number 6.
  • Chance: Any combination of dice. Score: Sum of all the dice.
  • Yatzy: All five dice with the same number. Score: 50 points.
If the player's total score for the value targets (ones through sixes) is greater than 63 the player gets a bonus score of 50.

Step 7

Scorecard

Instead of the log, print a Yatzy scorecard with dice values and score.

====================================
| Ones            | 1 3 5 1 1 |  3 |
| Twos            | 2 3 2 1 1 |  4 |
| Threes          | 3 3 3 3 4 | 12 |
| Fours           | 4 4 6 4 3 | 12 |
| Fives           | 6 5 6 5 5 | 15 |
| Sixes           | 6 3 2 6 6 | 18 |
| Total           |             64 |
| Bonus           |             50 |
====================================
| A Pair          | 1 4 5 5 1 | 10 |
| Two Pairs       | 2 6 6 1 2 | 16 |
| Three of a kind | 4 5 4 4 1 | 12 |
| Four of a kind  | 1 1 1 6 1 |  4 |
| Small straight  | 1 5 3 4 2 | 15 |
| Large straight  | 6 2 3 4 5 | 20 |
| Full house      | 1 1 5 5 3 |  - |
| Chance          | 2 3 6 5 5 | 21 |
| Yatzy           | 3 3 5 3 3 |  - |
====================================
| Total                       |  - |
                    

Step 8

Mega Yatzy

The player can now choose if they want to play regular Yatzy or Mega Yatzy.

Mega yatzy is played with 6 dice and 4 throws. In addition to the targets for regular yatzy, the following new targets become available:

  • Two Three of a kinds: Two different three of a kinds of dice. Score: Sum of all dice.
  • Poker: The combination 1-2-3-4-5-6. Score: 21 points (sum of all the dice).
  • Fuller house:Any pair and a four of a kind. Score: sum of all dice.
  • Mega Yatzy: All six dice with the same number. Score: 100 points.
Getting a bonus now requires the sum of all value targets to be greater than 84.

Step 9

Multiplayer

Add support for multiple players.