Ruby-Poker: A Poker library for Ruby

In my never ending quest for 100% completion of Project Euler I came to Problem 54 which required determining the winner in 1000 hands of 5 card poker. At first I thought this would be no big deal. Determining whether one hand is greater than another in poker? There’s got to be a library for doing that right? Unfortunately, it looks like someone was about to do one on RubyForge called libpoker but the project was abandoned right after it was started.

So… there’s no Ruby library. Guess I’m doing it myself. The solution was longer than I excepted, just over 200 lines, which is my longest ProjectEuler solution thus far. After finishing I extracted the poker logic into its own RubyGem to make it easy for other people who wanted to make a simple poker game or whatever else they might need it for.

Creating the RubyForge project and the RubyGem for ruby-poker was more time consuming than I had anticipated having never done it before but overall a pretty smooth process and worked out in the end.

Ruby-Poker installation is a snap. If you have RubyGems installed it’s as simple as:

gem install ruby-poker

Update 01/21/08: I wrote a guide for using ruby-poker.

Comments

3 Responses to “Ruby-Poker: A Poker library for Ruby”

  1. Aidan Finn on January 13th, 2008 9:27 pm

    Hi Rob,

    There was a ruby quiz on this topic a while ago.

    http://www.rubyquiz.com/quiz24.html

    Is this similar to what ruby-poker does?

  2. Rob on January 14th, 2008 5:04 am

    Aidan- The ruby quiz is different because it plays games of Texas-Holdem which has 7 cards in a hand instead of 5. So currently ruby-poker is unable to solve Ruby Quiz #24 however I plan on adding functionality to handle hands with greater than 5 cards in the near future.

    Update: See below

  3. Rob on January 22nd, 2008 9:38 pm

    Aidan- With the release of 0.2.0 ruby-poker supports hands with >5 cards so it is now capable of solving Ruby Quiz 24. In fact, I refactored ruby-poker using much of Patrick’s solution.

Leave a Reply