View Full Version : Programming - Ranking Hands (C#)

08-05-2005, 10:39 AM
Not sure if this is the correct forum for this...or if one even exists, but figure I'll ask anyway. I'm a programmer and I've given thought recently to writing some poker software. I typically use C#.NET, so if anyone can answer this with that syntax, it might save time.

I'm looking for an extremely efficient method of ranking both 5 and 7 card hands. 5 cards alone would be a good start. I don't really want to reinvent the wheel and spend time coding something that's readily available/efficient.

I found this: http://www.codeproject.com/csharp/PokerLibraryAndBotChallan.asp and I downloaded the libraries and can load cards in, but for some reason it doesn't seem to want to rank them. I've read the article several times and the concepts are well documented, but the function usage doesn't seem to be. The method he uses for hand ranking seems extremely efficient. Anyone have a solution out there that works?

08-05-2005, 11:28 AM
The function

private void EvaluateHand(Hand h)

in PokerGames5Cards.cs appears to be the relevant one, it takes a hand object as an argument and sets the type property to one of the type enums.

Nothing too earth-shattering about the approach, just works down from Royal Flush to High Card stopping at the first match. It looks like the hand object can hold more than five cards, but the way of selecting the best 5-card hand from them is rubbish - it just tries every combination.

08-05-2005, 11:44 AM
Yeah, I found the appropriate method, it seems very unorganized and illogically named. Why he didn't just implement a Hand.Rank() property directly, without having to create an instance of that class is beyond me.

Determining what category each hand falls into is pretty elementary...I just found the bit shifting aspect interesting for determining a numerical rank for a given hand.

08-05-2005, 02:02 PM
Yeah, I don't understand why he returns an arraylist of all combinations, then sorts them out to return your best hand. If he tweaked it a little, he'd be able to determine kickers, if two players held the same hand.