Monday, February 11, 2013

A Simple Code Kata

Hello CtJ nation!

Yes, it's been a long time, but we're still here at CtJ HQ, reading, if not exactly writing. Hopefully, more to come on that front in the coming weeks.

For now, this post is in support of an upcoming session at the PEI Developers Meetup. We'll be implementing a simple Code Kata and possibly extending it in interesting ways.

The Kata

The idea is a simple card game. Ignoring the rules of Rack-O, check out its deck of cards: numbers, but no suits.

The game is described as follows:

Begin with the deck of cards numbered 1 to N.

Shuffle and deal cards evenly to P players and a "kitty". That is: partition N cards (face-down) into (P + 1) sets.

Gameplay for a round:

  • Show a card, face-up, from the kitty.
  • Players all submit a hidden card as a bid.
  • Once all bids are made, the cards are revealed.
  • Highest bid wins the card from the kitty, and its value is awarded as points to the player. 
The winner is decided by most points at the end of the game.  


I like this kata for many reasons. First, it scales nicely: we could write code for a single round, and eventually ramp up to a game server with concurrent players.

Also, it combines simplicity and variation: it is easy to write an algorithm that satisfies the rules; yet a winning strategy can be dynamic and surprisingly complex. (Thanks to Alex Stangl for an email conversation on this, some years back.)

Finally, we can imagine a "robot wars" scenario where solutions compete against one another. Neat-o.


For PEI Devs, think about this problem for the upcoming meeting.

For all, I'm looking for name suggestions (since it is not the game Rack-O). The best I have is Frak-O...