Determining Poker Hands

Started by
2 comments, last by GamerAlan 20 years, 10 months ago
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 =)
-GamerAlan
Advertisement
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.
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.
-GamerAlan
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.

This topic is closed to new replies.

Advertisement