PokerStars hand history parser

Submitted by andre on Sun, 2006-10-29 05:12.Geeky | Play | Programming

For some fun, I decided to write a pokerstars hand history parser.

The purpose of the parser is to look at a hand history file and extract meaningful information for each hand it contains. The information is collected in a structured way... i.e. one big honking $hands array.

I collect the table name, game type, pokerstars hand number, tournament number and blind level (if a tournament), player names, seat locations and chip counts, and all action each player takes throughout the hand. Essentially all useful information found in the hand history file for any given hand.

I knew deep down that this would require regex work - but I first started parsing with some string functions. And before I could even fully parse the first line of a hand history file I knew this approach would be far too slow.

So, I was forced to re-instroduce myself to regular expressions. I've used them before, but not too often for tasks requiring complex multi-line processing. For the most part the regex work went well. But, every so often I would bump up against a stupid problem where the pattern I was using 'should have' worked but wasn't returning the results I expected. Such is life in the world of regex debugging.

Eventually I solved all my granular parsing issues as well as the conditional logic problems of parsing hand histories of different types.

For now the result is a parser that chews through hand histories in about 2-3miliseconds. Push come to shove I could probably shave off some more time with some additional refactoring, but I am pretty satisfied with the results.

fun fun fun

andre