A new Coding Dojo Kata: Poker Dice

I was invited to give an introductory class on python to the students of UENP and had the idea of organizing a coding dojo there. I wanted to find a kata that wouldn't be trivial but wouldn't be too hard for someone who had just had their first contact with python either.

At first I thought the Poker Hands Kata was a good choice. Dealing with a "virtual card deck", shuffling, it had a good potential as an Object Oriented Programming exercise, but I still wanted something slightly simpler. Having to deal with the different card suits seemed to add unnecessary complexity for a beginner's exercise.

That was when I came across "poker dice", a variation of Poker that is played with dice instead of a standard card deck. It made it much simpler since we didn't have to deal with suits or mixed letters and numbers when computing the ranking of a hand. We could then pay more attention to the data structures involved and the mechanisms python provides us when dealing with those structures, no unnecessary complexity is imposed by the rules of the game itself.

I think this Kata is of great value for both experienced and novice programmers. Of course you're not restricted to python although I had a specific goal to achieve with the exercise, given the contents of my class.

So here is the kata: the goal was to just "compare hands", but implementing the full rules of the game is not that hard

If you use it in your own Coding Dojo, please leave a comment to let me know it was useful

Implement dice, “hands” and comparison between two poker dice “hands” in python

Description

Poker Dice is a simple, straight-forward and fun dice game.

Players

2 or more players, best with 2 to 5 players.

Equipment

Five standard six-sided dice.

Goal

To roll the best Poker hand.

Gameplay

Each player has three rolls. On the first roll, she rolls all five dice. She may then set aside any number of dice (including zero) and re-roll the remainder. After the second roll, she may once again set aside any number of dice and re-roll the remainder.

Once dice are set aside, they may not be re-rolled. A player is not required to make a second or third roll.

Hand Ranks

The possible hands are ranked as follows:

  • Five of a kind, e.g. 4-4-4-4-4
  • Four of a kind, e.g. 2-2-2-2-6
  • Full house, e.g. 6-6-6-1-1
  • Three of a kind, e.g. 5-5-5-2-1
  • Two pairs, e.g. 3-3-2-2-4
  • One pair, e.g. 4-4-5-3-1
  • High card, e.g. 6-5-4-3-2

Straights do not count in this game.

If two players claim the same hand, ties are broken in the same manner as in Poker.

Winning

The player with the best Poker hand wins.

Comente de volta!