MC said:
Hi guys
Been trawling for ages now!!
Anyone seen any code for working out the best 5 card hand from 7 cards as in
Limit/No-Limit Poker.
You mean "as in Texas Hold 'em"
I am doing a project for myself to teach me .NET and struggling.
Thought i'd cheat a bit.
OK, so no complete answers from me
First, how are you modelling cards? I suggest a class or structure with
Suit and Rank methods that return values from Enums you define.
Check for each type of hand in turn, from best to worst - stop checking
when you get a match (a hand containing a three of a kind also contains
a pair, but we only care about the *best* match).
A lot of the hand checking is made easier by sorting the cards by rank.
To check for a straight, check for differences of one in appropriate
places.
If you find a straight, check the suits for a straight flush.
Checking for four of a kind is easy if the cards are rank sorted.
It might be useful to count the incidences of ranks. eg AAKQJJ7, count
the ranks, get an array like this:
(1): 2
(2): 0
....
(7): 1
....
(11): 2
(12): 1
(13): 2
With such an array, checking for FH / 3s / 2x2s / 2s is easy. A similar
suit-counting array makes checking for a flush very easy.
And that's it, really
