Kata baby steps
The Poker Game kata started a little like climbing a sheer cliff - where do you start. But after that first simple test, I'm now off and climbing.
However, I must resist the urge to go too fast. It's tempting to just start banging on the keyboard and cranking out some code, but I want to take a more measured approach. This time, I'm just re-implementing the PokerGame class to not simply return the expected string, but to actually do a little bit of work.
The full implementation is on GitHub, but briefly, we have a field where we store the players and the cards that they can see (i.e. both their hole cards and the community cards):
private Map<String, List<String>> playersAndTheirCards = new HashMap<String, List<String>>();
The deal methods simply update this map, for example:
public PokerGame dealRiver(String card) {
for (List<String> cards : playersAndTheirCards.values())
cards.add(card);
return this;
}
And the results method simply prints out all the players and their cards from this map - still hard-coding the 'Winner' text against each player.
This is really little improvement on the previous version. Although now I have tried to implement the API I made up for the PokerGame class, I realise a few more questions have arisen:
- The interface has two related methods, 'deal' and 'holeCards' which mean having to keep track of the 'last player' in an instance variable.
- Could make this interface better.
- Hard-coding of the winner text.
- Repetitive code for the dealTurn, dealRiver implementations.
- The community cards are added to each players list of cards. Is the model correct? Perhaps we need to add the concept of a 'deal'.
- No ability to support a player 'folding'.
These are listed in the issues.txt file in the root of the project, which is where I'll keep adding and removing items as they come up during the test driven development cycle.
That's all for now. I will now take a short pause to consider if I should tackle any of these points or move onto another test. I have to be mindful that I don't want to go off designing a complete solution on the basis of one test!
More Poker fun next time.
