Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ POKERHAND CLASS. I am having difficulty creating a poker hand class that reads, ranks, and determines the suit of a hand. Any help would

C++ POKERHAND CLASS. I am having difficulty creating a poker hand class that reads, ranks, and determines the suit of a hand. Any help would be great! The pokerhand.h file is contained in the link http://www.csee.umbc.edu/courses/undergraduate/202/spring16_marron/projects/proj2/proj2/pokerhand.h The card.h file needed to compile with pokerhand.cpp is http://www.csee.umbc.edu/courses/undergraduate/202/spring16_marron/projects/proj2/proj2/card.h The definition for the file pokerhand.cpp is as follows,

For the PokerHand class, there are some complications. First, it is much easier to determine the rank of a poker hand if the cards are sorted by points. For example, if you want to check if a hand is a Two Pair, there are only 3 possible patterns when the cards are sorted. A Two Pair hand must have a 2-2-1, 2-1-2 or 1-2-2 pattern. The 2-2-1 pattern means the first two cards are a pair with the same point value. The next two cards are a pair with a different (higher) point value. Finally, the last card is by itself and has a point value higher than the second pair. Because the cards are sorted, there are no other patterns possible to make a Two Pair. Since sorting is so useful, it should be done by the constructors. That way, all member functions can assume that the hand is already sorted.

Note that poker ranks are mutually exclusive. A Full House is not a Two Pair, even though there are two pairs in a Full House. Similarly, a Straight Flush is not a Straight and a Royal Flush is not a Straight Flush. Thus, if two poker hands have different ranks, we can quickly determine which hand is better. Your implementation should store the rank of the hand in the data member m_rank after it has been computed for the first time. This way you can avoid having to recompute the rank when the client calls getRank(). Before the rank has been computed, m_rank should hold the value NoRank. That is how you can tell if the rank has been computed previously. The constructors must make sure that m_rank is initialized to NoRank.

If two PokerHand objects have the same rank, your cmp() function should still determine which hand is better according to the rules of poker. A tie is possible, but this is not determined just by the rank. For example, if two hands are both Two Pair, the hand whose higher pair has higher point value wins. If that's a tie, then the hand whose lower pair has higher point value wins. If that's a tie, then the fifth card, the one that is not in any pair, is used to break the tie. If the fifth cards are once again tied,then the two hands are tied. Thus, to determine which of the Two Pair hands is better, we need three values: the point value of the higher pair, the point value of the lower pair and the point value of the last card. These three values can be determined easily when you first discovered that the rank of the hand is two pair. For example, when you check if the hand is a Two Pair with the 2-2-1 pattern, you can do the following:

// Check 2-2-1 if ( m_cards[0].points() == m_cards[1].points() && m_cards[1].points() != m_cards[2].points() && m_cards[2].points() == m_cards[3].points() && m_cards[3].points() != m_cards[4].points() ) { m_firstPairPoints = m_cards[3].points() ; m_secondPairPoints = m_cards[1].points() ; m_lastCardPoints = m_cards[4].points() ; m_rank = TwoPair ; return true ; }

Then, the cmp() function can use the data members m_firstPairPoints, m_secondPairPoints and m_lastCardPoints to determine which of two hands with rank of Two Pair is better.

Overall, we just need five data members to store this "additional information" in order the compare any two poker hands:

m_lastCardPoints m_firstPairPoints m_secondPairPoints m_tripletPoints m_quadrupletPoints

Full explanation for these data members are in pokerhand.h.

Here is a list of the member functions in PokerHand that you must implement:

A default constructor: PokerHand() ;

An alternate constructor: PokerHand(Card c0, Card c1, Card c2, Card c3, Card c4) ;

A comparison function: int cmp(PokerHand &otherHand) ;

Note that cmp() compares the host object versus the otherHand object. The return value being negative, zero or positive indicates whether the host is worse than, tied with or better than otherHand, respectively. The cmp() function should notassume that the cards in the two hands come from the same deck of cards. For example, cmp() may be asked to compare two hands that both have 4 Aces. This is not possible for two competing hands in a poker game. However, the main program in play7.cpp may ask cmp() which of two hands with 4 Aces is better in order to determine which 2 out of 7 cards to drop.

Two print functions: void printRank() ; void printCards() ;

A function to report the rank of the host (and if necessary, compute the rank): pRank getRank() ;

For each rank, a boolean function that says whether the host has that rank: bool isRoyalFlush() ; bool isStraightFlush() ; bool isFourOfAKind() ; bool isFullHouse() ; bool isFlush() ; bool isStraight() ; bool isThreeOfAKind() ; bool isTwoPair() ; bool isOnePair() ; bool isHighCard() ;

Some private helper functions:

void sort() ; bool isAllOneSuit() ; bool isSequence() ; Consult the header file for more documentation for these functions. Note that isAllOneSuit() does not do the same thing as isFlush(), because isAllOneSuit() returns true when the hand is a Royal Flush or a Straight Flush. Similarly,isSequence() is not the same as isStraight().

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design And Implementation

Authors: KROENKE DAVID M.

1st Edition

8120322258, 978-8120322257

More Books

Students also viewed these Databases questions

Question

What impact does a decrease in setup time have on EOQ?

Answered: 1 week ago

Question

7. Be able to distinguish productive from destructive conflict.

Answered: 1 week ago

Question

1. Signs and symbols of the map Briefly by box ?

Answered: 1 week ago

Question

Types of physical Maps?

Answered: 1 week ago

Question

Explain Intermediate term financing in detail.

Answered: 1 week ago