180 likes | 364 Views
The PokerHand Program. This program will Generate a specified number of poker hands at random.Categorize each hand.ReportThe number of hands in each category.The relative frequency of each category.. The Card Class. Each card has a suit and a face value.Suit is an enumerated type.enum Suit {c
E N D
1. Poker Hand Project 6
Mon, Dec 1, 2003
Due Mon, Dec 8, 2003
2. The PokerHand Program This program will
Generate a specified number of poker hands at random.
Categorize each hand.
Report
The number of hands in each category.
The relative frequency of each category.
3. The Card Class Each card has a suit and a face value.
Suit is an enumerated type.
enum Suit {clubs, diamonds, hearts, spades};
Face is an enumerated type.
enum Face {two, three, four, five, six, seven, eight, nine, ten, jack, queen, king, ace};
4. The Order Relation on Cards The function operator<() is defined to compare Cards
First by Face value,
Then by Suit.
For example,
two of spades < ace of clubs
The two of clubs is the lowest Card.
The ace of spades is the highest Card.
5. The Deck Class A Deck object consists of
An array of 52 Cards.
A RandomInt object, used to shuffle the deck.
6. The Deck Class Internally, in the array, the cards are indexed as 0 through 51.
Externally, through the user interface, they are indexed as 1 through 52.
7. The PokerHand Class A PokerHand object consists of an array of 5 Cards.
The quality of a hand is the type of poker hand that it is.
enum Quality {nothing, onePair, twoPairs, threeOfAKind, straight, aFlush, fullHouse, fourOfAKind, straightFlush, royalFlush};
8. The Deck Class (again) The Deal() function returns a PokerHand object, consisting of 5 Cards dealt from the top of the deck.
This function should “get” cards 1 – 5 from the deck and “set” them in the poker hand.
9. Determining the Type of Hand To facilitate the analysis of the hand, many of the functions should first arrange the cards in order.
That makes it much easier to check for one pair, two pairs, three of a kind, four of a kind, etc.
Use a Sort() function to do this.
10. The sort() Function Use any of the sorting algorithms that we discussed.
When swapping cards, either
Swap the array elements, or
Use GetCard() and SetCard() to move them.
The order imposed on the cards is the order defined by operator<() in the Card class.
11. The hasOnePair() Function
12. Determining the Quality of the Hand Once the hand is sorted, two pairs can occur in only 3 ways.
The possible patterns are
AABBC
AABCC
ABBCC
How many patterns were possible before the hand was sorted?
13. Determining the Quality of the Hand In a sorted hand, what are the possible patterns for
Three of a kind?
Four of a kind?
A full house?
14. Determining the Quality of the Hand Test for a flush by seeing if all the cards have the same suit.
Test for a straight by seeing if each card has a value one greater than the card before it.
A straight flush is both a straight and a flush.
Call hasStraight() and hasFlush().
15. Determining the Quality of the Hand A royal flush is a straight flush in which the high card is an ace.
Call hasStraightFlush() and getHighCard().
16. Determining the Quality of the Hand The quality() function must test for the simpler types first. Otherwise, the function may miscategorize the hand.
For example, if a hand has four of a kind, then the functions hasThreeOfAKind(), hasOnePair(), and hasTwoPairs() will also return true.
17. The main() Function The main() function should generate at random the specified number of PokerHands.
Shuffle the deck every time before dealing a hand.
Each hand should be categorized according to its quality.
A counter for that type of hand should be incremented.
Print the counts and the relative frequencies.
18. The Output The output will be different every time the program is run, even for the same input.
However, the following chart shows what to expect.