Help with Poker Hand Evaluation.

  • Thread starter Thread starter teejayem
  • Start date Start date
T

teejayem

I am looking for some help!

I am currently developing a new game for an online community. The
game is called Pokino which ishalf bingo and half poker. Wierd eh?!

Anyway...

The final part of the program needs to evaluate two 5 card poker hands
and determine which one out of the two hands wins. I thought rather
than create a new class of my own I would see if there was anything
already available. I have searched high and low but can't find
anything!!

I am using Cards.dll so each card is represented by an integer value
ranging from 0-51.

If anybody knows of any resources that may help me or can come up with
a quick and easy way to do this it would be much appreciated.

Thanks in advance,

Tom Miller.
IT Development Analyst.
 
Did you develop Cards.dll? I know when I was designing my own
Cards.dll I created the cards in two parts: Card Value and Card
Suit. When I had to do a War application for class I could simply
take the card value against the other card value and determine the
winner. For that particular assignment our professor also had one
suit beating another so I could just take the value of the suit (Spade
= 1, Heart = 2, Club = 3, Diamond = 4) and pit them against each
other.

All that being said I would define a Card object and simply shuffle
those around in an array to build your deck.
 
Did you develop Cards.dll?  I know when I was designing my own
Cards.dll I created the cards in two parts:  Card Value and Card
Suit.  When I had to do a War application for class I could simply
take the card value against the other card value and determine the
winner.  For that particular assignment our professor also had one
suit beating another so I could just take the value of the suit (Spade
= 1, Heart = 2, Club = 3, Diamond = 4) and pit them against each
other.

All that being said I would define a Card object and simply shuffle
those around in an array to build your deck.

I use cards.dll that is part of Windows. The same dll that is used in
Solitaire and such like....

enum rank
ace
two
three
etc etc...
end enum

enum suit
heart
spades
clubs
diamonds
end enum

The cards are represented as follows:-
card = rank + suit * 4
 
I use cards.dll that is part of Windows. The same dll that is used in
Solitaire and such like....

enum rank
ace
two
three
etc etc...
end enum

enum suit
heart
spades
clubs
diamonds
end enum

The cards are represented as follows:-
card = rank + suit * 4

You would be better served to extend that class and add a method that
returns the split up rank and suit for a poker-style game, since ranking
poker hands is easier that way. Also what if you want to add Jokers to the
deck or handle wild cards? The OP didn't specify, but doesn't sound
possible with cards.dll.
 
You would be better served to extend that class and add a method that
returns the split up rank and suit for a poker-style game, since ranking
poker hands is easier that way. Also what if you want to add Jokers to the
deck or handle wild cards?  The OP didn't specify, but doesn't sound
possible with cards.dll.- Hide quoted text -

- Show quoted text -

I decided at the outset that I wasn't going to add functionality to
deal with jokers/wild cards.
So create a method that would determine both rank and suit as seperate
objects/variables and use those to determine the poker hand?
 
It doesn't seem like a difficult thing to write the code for evaluating hands,
if you like programming. :)

I would not worry about speed, and do it in a very methodical way. For instance,
you could have a separate procedure for each kind of hand: IsFlush, IsStraight,
IsFour, IsFullHouse, IsThree, etc. The first thing when comparing two hands is
to see if one is a higher rank of hand than the other.

If they are the same rank, i.e. both are TwoPair, then you need to compare card
values in each hand. I would use a separate procedure for comparing two flushes,
two straights, two TwoPair hands, etc.

If you break it down, you can write very clean tests for each possibility, and
get a very reliable evaluator. No matter how elaborate the code looks, it will
be very fast in use, so don't worry about that.

Thanks mate!
 
Steve Gerrard said:
It doesn't seem like a difficult thing to write the code for evaluating
hands, if you like programming. :)

I would not worry about speed, and do it in a very methodical way. For
instance, you could have a separate procedure for each kind of hand:
IsFlush, IsStraight, IsFour, IsFullHouse, IsThree, etc. The first thing
when comparing two hands is to see if one is a higher rank of hand than
the other.

If they are the same rank, i.e. both are TwoPair, then you need to compare
card values in each hand. I would use a separate procedure for comparing
two flushes, two straights, two TwoPair hands, etc.

If you break it down, you can write very clean tests for each possibility,
and get a very reliable evaluator. No matter how elaborate the code looks,
it will be very fast in use, so don't worry about that.

I would advise going even a small step further and creating a generic
GetHandScore routine to call all of those hands and assign a rank to each
hand. So a Royal Flush would be worth 10,000 points, Straight Flush = 9,000
points, Four of a Kind = 8,000 points, and so on down the line. You could
also add a GetHighCard routine to determine the high card in your straight,
flush, full house, etc., in case two players both have a straight or full
house. Then determining who won is simply a matter of comparing the scores
returned by GetHandScore, and comparing GetHighCard in case of a
GetHandScore tie. Like Steve pointed out, this isn't that difficult. The
lower level comparisons you need to do would be easier if you split up the
rank and value of each card, which was why I mentioned that before.
 
Back
Top