Snooker Kata

I’ve been toying with the following TDD Kata. I like it a lot, it provides just enough complexity that it’s interesting, but not so much that the algorithm needs to be complicated.

The idea is to implement a game of Snooker. I’ll assume you either know the rules of snooker, or can find them here.

We need a class that keeps track of a frame of snooker, including which player is at the table, which colour ball they should be targeting, and provides methods that allow us to tell the class what happens with each shot.

The Methods needed are

Hit(colour)
Pot(colour)
Miss(colour)
InOff(colour)
Nominate(colour)

We also need a number of methods that will give us back details about the state of the two players.

int Score(player)
int HighestBreak(player)
int Potted(player, colour)
  1. Implement Hit(Colour)
    Game will keep track of which player is at the table, and whether they should be hitting a red or another color. If the player hits any red when a red is expected, or any colour when a colour is expected, it shall be deemed a valid hit, and play shall switch to the other player.
  2. Wrong Ball Hit
    If a red is expected but a colour is hit, or vice versa, the game shall detect the foul and award the correct number of points to the other player and play shall switch to that player.
  3. Implement Pot(Colour)
    Same logic as above, however the appropriate number of points shall be awarded to the player at the table and play shall remain with that player.
  4. Implement Miss(Colour)
    This method indicates that the player at the table missed the targeted colour. Award the appropriate points to the opponent and switch player.
  5. Implement InOff(Colour)
    This method indicates that the player potted the cue ball while targeting a player of the suggested colour. Award the appropriate points to the opponent and switch player.
  6. Implement Nominate(Colour)
    This method should be used after the player has potted a red, it designates the desired colour that will be targeted. If Nominate is followed by Hit or Pot of a different colour, that is a foul. Award points to opponent and switch player. if Nominate is followed by Hit or Pot of the nominated colour that is valid, award points to the player and he remains at the table.
  7. Change Nominated Ball
    Allow the player to change nominated ball by simply calling Nominate again, the most recent call counts.
  8. Replace Potted Balls
    Colours are replaced on the table after being potted, reds stay off the table when potted.
  9. No Reds Left
    Detect when all reds have been potted, the players must then play for the lowest valued colour. They can not nominate a different colour. When colours are potted at this stage of the game they remain off the table.
  10. End Of Frame
    Play ends when the table is cleared.
  11. Statistics
    The following statistics should be available for each player at any time during or on completion of a frame:
    Score
    Highest Break
    Number of pots for each ball colour

Switch to our mobile site