Code Kata - Texas Hold'Em
Time for another in my Kata series. I enjoy a bit of Poker, especially Texas Hold'Em, so this Ruby Quiz caught my eye. Here's the essence of the problem:
You work for a cable network and the show's producer has come to you for a favor. It seems the play-by-play announcers just can't think very fast. They could certainly flap their jaws well enough, if they just knew what hands the players were holding and which hand won the round. The producer explains what you need to do:
Players hands consist of a simple space-delimited set of pair of characters: each pair representing the face value of the card and the suit.
When a player folds, the hand only consists of the cards until the fold.For example, consider three players, Bob, John, Sue:
Bob: Kc 9s Ks Kd 9d 3c 6d
John: 7s Ts Ks Kd 9d
Sue: 9c Ah Ks Kd 9d 3c 6dThis would mean John would have folded and Bob and Sue were left in the showdown. The required output would show:
Bob: Kc 9s Ks Kd 9d 3c 6d Full House (winner)
John: 7s Ts Ks Kd 9d
Sue: 9c Ah Ks Kd 9d 3c 6d FlushIt would also be nice to also show the cards rearranged to show the 5 cards included in the ranking (i.e. the 5 flush cards Sue had) and also sorted by face value, with any kickers sorted as well.
This is actually a fairly complicated problem for a Kata but I can't resist, so I'm going to forge ahead. I need to pick a language for the Kata. I've done one in C# and Scala and do want to continue my adventures in Scala, but this feels like it may be too big a jump after the simple one I started out with, so I'm going to pick Java. The last decision at this stage is whether I should make use of 3rd party libraries. I think at this stage, I'm going to stick to what comes "out of the box" in JDK 6, but may review that decision later on.
Lastly, I think it will turn out to be too big to simply post all the code here, so will take this opportunity to use one of the newfangled distributed version control systems. The two obvious choices being Git or Mercurial. I'd be tempted to use Mercurial as I've heard it's the more friendly to users of Subversion (which I use daily). However, it seems all the geek love is for Git - especially Github - so will start there.
I do plan on posting code snippets here as I go through the process, focusing on the tests/refactoring decisions I make as I go. This should be a good one!
