Archived

This topic is now archived and is closed to further replies.

Determining Poker Hands

This topic is 5309 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m making a little dos poker game. I''m running into a problem with the function that determines if the hand is a winning hand or not, and what kind of win it is. My card class has data members that hold which suit and value the card is, so how do I make a function that will determine which kind of hand the player has. (IE: Royal Flush, Straight Flush, Four of a Kind, Full House, Flush, Straight, Three of a Kind, Two Pair, Pair) I can check for the suits being equal to eachother easy enough, but when I try to find a way to determine how many seperate pairs there are, or how many of the same card are in each hand, I get some problems. Any help for this is appreciated =)

Share this post


Link to post
Share on other sites
A particular hand consists of one or more combinations. Search from high to low, using a different function to check for each combination. The first function that returns true, along with the "rank" of the hand (the number of the highest card involved in the combination). If it finds the combo, use it. If it doesn''t, go to the next checking function. Nota bene: Royal flushes do not require a checker; they''re simply straight flushes to the ace.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
Yes, I understand the order and such to call those functions, but the problem is coming up with the algorithm that will detect pairs or the three/four of a kind.

Share this post


Link to post
Share on other sites
Sort the cards by rank, high to low. Iterate through them, keeping in mind what the last card you saw was. if the current card matches, that''s a pair.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites