You will again use procedural, functional, object-oriented, and generic
programming paradigms in the C++ language and libraries (as of the C++17 standard)
to extend your common and game-specific abstractions for (Partnership Auction)
Pinochle and (Texas hold 'em)
Poker.
To do this, you will add new features to your CardSet class template
to facilitate examining different combinations of cards within each player's hand
(in the Pinochle game) or between each player's hand and the common board of cards
(in the Hold 'Em game). You will then add new enumerations, a nested struct, and
different evaluation functions so that each game will evaluate the players hands
based on those game-specific evaluations.
As you develop your code, please use good modularity: for example, if a function's logic has several separable parts (or is long enough to fill the editor's window) you may want to break it up into other smaller functions.
Note: some details of the assignment again are intentionally slightly under-specified, leaving you some room to choose what you think is the best way to implement them, as long as what you do is reasonable and you explain your design decisions in comments in the code and in your readme file.
qlogin, and (as you did in Studio 0)
confirm that the correct version (8.x) of the g++
compiler is installed in your environment there.
cd into it.
readme.txt),
in which you will record your observations, design decisions, and other information
pertaining to the lab assignment as you develop your solution.
CMakeLists.txt and source (.cpp)
and header (.h) files from your previous lab assignment
into that directory - you will use (and in some cases modify) them along
with additional code you will write, in this lab assignment. If
appropriate, you may want to rename some files and update your
CMakeLists.txt accordingly (e.g., so that lab1.cpp
becomes lab2.cpp as a starting point for this assignment).
Card class template,
add two non-member function templates that are parameterized with rank and suit
types, take two const references to Card objects parameterized with
those type parameters, and return a bool value. The first of those
functions should return true if the first card's rank is less than
the second card's rank, or if they are of the same rank if the first card's suit
is less than the second card's suit; otherwise it should return false.
The second of those functions should return true if the first card's
suit is less than the second card's suit, or if they are of the same suit if the
first card's rank is less than the second card's rank; otherwise it should return
false.
CardSet class template has a public copy constructor that takes a const reference to another CardSet with the same type
parameterization, and performs a deep copy of that object. That is, the
copy constructor should (without modifying the original object from which it
is being constructed) duplicate the cards that are in the original object's
vector within the vector of the object that is being constructed.
If you declare (and define) that copy constructor (rather than using
the one the compiler supplies for you by default), you will need to
ask the compiler explicitly to synthesize a default constructor for that
class template by declaring (but not defining)
a default constructor followed by = default in the class template
declaration in your header file.
In your readme file, please document why you added your own copy constructor if that is what you did, or why you instead are using the one the compiler supplies (i.e., why that one is sufficient).
CardSet class
template, which returns a pointer to the class' protected vector data member. This
static public member function provides a "controlled violation of encapsulation"
that can be used to access, sort, etc. different combinations of cards within the
card set (e.g., to identify melds in the Pinochle game and to rank and compare
hands in the Hold 'Em poker game).
enum class PinochleMelds enumerated type in
the header file where your PinochleGame class is declared,
with monotonically increasing values for the following labels:
dix,
offsuitmarriage,
fortyjacks,
pinochle,
insuitmarriage,
sixtyqueens,
eightykings,
hundredaces,
insuitrun,
doublepinochle,
fourhundredjacks,
sixhundredqueens,
eighthundredkings,
thousandaces, and
insuitdoublerun.
Also declare and initialize a public static member variable of the
PinochleGame class, which associates the following
point values with each of the labels in the PinochleMelds
enumerated type:
dix is worth 10 points,
offsuitmarriage is worth 20 points,
fortyjacks is worth 40 points,
pinochle is worth 40 points,
insuitmarriage is worth 40 points,
sixtyqueens is worth 60 points,
eightykings is worth 80 points,
hundredaces is worth 100 points,
insuitrun is worth 150 points,
doublepinochle is worth 300 points,
fourhundredjacks is worth 400 points,
sixhundredqueens is worth 600 points,
eighthundredkings is worth 800 points,
thousandaces is worth 1000 points, and
insuitdoublerun is worth 1500 points.
One easy way to do this is to exploit the numbering of enum class labels starting at 0 and use them as indices into an array of unsigned integers that has as many positions as there are labels, and initialize the array with the appropriate point values.
operator<<)
that takes a reference to an ostream and a const reference to a
variable of the PinochleMelds enumerated type, which prints
out an appropriate string for the name of the label and the points value
associated with the label as an unsigned decimal integer (with a space in between
them), and then returns a
reference to the ostream that was passed to it.
suit_independent_evaluation member
function in your PinochleGame class, which takes a const reference to
a CardSet parameterized with the PinochleRank and
Suit enumerated types (for that player's hand), and a non-const
reference to a vector parameterized with the
PinochleMelds enumerated type.
The member function should declare a local variable of type
CardSet parameterized with the PinochleRank and
Suit enumerated types and initialize that local variable with the
passed reference to the player's hand (i.e., invoking the copy constructor to
make a deep copy that the function can manipulate as needed without affecting
the original copy of the player's hand - in particular, using the rank and then
suit ordering relation (and possibly the suit and then rank ordering relation)
to sort the cards in the local copy may help to simplify the logic for the
following evaluations.
The member function should check for each of the following combinations of cards in the hand, and for each one that is found (with the exception of the ones that don't count if another higher valued version exists) push back the appropriate enumeration value into the vector to which a reference was passed (note that doing them in the following order may make it easier to write the conditional logic for skipping ones that don't count if a higher valued version exists):
thousandaces for all 8 aces (A♠ A♠ A♥ A♥ A♦ A♦ A♣ A♣)
hundredaces for an ace of each suit (A♠ A♥ A♦ A♣) but not
if the hand has thousandaces
eighthundredkings for all 8 kings (K♠ K♠ K♥ K♥ K♦ K♦ K♣ K♣)
eightykings for a king of each suit (K♠ K♥ K♦ K♣) but not
if the hand has eighthundredkings
sixhundredqueens for all 8 queens (Q♠ Q♠ Q♥ Q♥ Q♦ Q♦ Q♣ Q♣)
sixtyqueens for a queen of each suit (Q♠ Q♥ Q♦ Q♣) but not
if the hand has sixhundredqueens
fourhundredjacks for all 8 jacks (J♠ J♠ J♥ J♥ J♦ J♦ J♣ J♣)
fortyjacks for a jack of each suit (J♠ J♥ J♦ J♣) but not
if the hand has fourhundredjacks
doublepinochle for two jacks of diamonds and two queens
of spades (J♦ J♦ Q♠ Q♠)
pinochle for a jack of diamonds and a queen of spades (J♦ Q♠)
but not if the hand has doublepinochle
play member function of your PinochleGame
class, after it prints out each player's name and hand, it should also declare
an (empty) vector of the PinochleMelds enumerated type
and pass a reference to the player's hand and a reference to that vector into the
suit_independent_evaluation member function to identify all the melds
that are possible with the player's hand. The play member function
should then iterate through the vector and (inserting appropriate line breaks when
needed) use the shift operator to print out the label and value of each meld that
was found. Note that it is essential that melds found in a previous hand
should not be carried over into the next one - the vector must be empty before each
call to the evaluation function.
enum class HoldEmHandRank enumerated type in
the header file where your HoldEmGame class is declared, with
monotonically increasing values for the labels xhigh,
pair, twopair, threeofakind,
straight, flush, fullhouse,
fourofakind, straightflush, and undefined.
Also declare and define a left shift operator (operator<<) that takes
a reference to an ostream and a const reference to a variable of
the enumerated type, shifts an appropriate string for the label into the
passed ostream and returns a reference to the ostream.
holdem_hand_evaluation member
function in your HoldEmGame class, which takes a const reference to
a CardSet parameterized with the HoldEmRank and
Suit enumerated types (for that player's hand) and a return value
of the HoldEmHandRank enumerated type.
The member function should again declare a local CardSet variable
(though this time parameterized with the HoldEmRank and
Suit enumerated types) and should again initialize it with the
passed reference to the player's hand to make a deep copy - here too using
the rank and then suit ordering relation to sort the cards in
the hand may simplify the logic for the following evaluations.
The member function should then check for each of the following combinations of cards in the hand, and return the highest valued one that it finds (for example, a straight flush is also a straight and is also a flush but its ranking is higher than either of the other two):
undefined if there are fewer or more than
five cards in the hand
straightflush if all five cards are of the
same suit and their ranks are consecutive (with the special rule that A 2
3 4 5 of the same suit and 10 J Q K A of the same suit are the lowest and
highest valid straight flushes respectively, but that any hand with cards
ranked K A 2 is not considered a straight flush)
fourofakind if four cards have the same rank
fullhouse if three cards have the same rank
and the other two cards have the same rank
flush if all five cards are of the same suit
straight if the ranks of the cards are
consecutive (with the special rule that A 2 3 4 5 and 10 J Q K A are the
lowest and highest valid straights respectively, but any hand with cards
ranked K A 2 is not considered a straight)
threeofakind if three cards have the same
rank and the other two cards are of different ranks than any other cards in
the hand
twopair if two cards have the same rank and two
other cards share a different rank and the fifth card is of yet another rank
pair if only two cards in the hand have the
same rank, and
xhigh
HoldEmGame class which has (1) a
CardSet that is parameterized with the HoldEmRank and
Suit enumerated types, (2) a variable for the player's name, (3)
a variable of the HoldEmHandRank enumerated type, and (4) a
constructor that takes arguments of those types and uses them to initialize
its member variables (in its base/member initialization list).
The instructions for this nested struct originally had specified that the player name variable in it should be a reference - however, depending on how your code uses those structs it is possible that it may result in one of them being default constructed which will cause a compilation error, in which case it's necessary to declare the variable to be an lvalue instead of an lvalue reference.
In the source and header files for your HoldEmGame class, declare
and define a non-member less than operator (operator<)
that takes const references to two objects of the nested struct type and
returns true if (and only if) the value of the first object's
HoldEmHandRank variable is less than that of the second object's,
or any of the following are true:
pair and the rank of the paired card of the first
object is less than the rank of the paired card of second object, or if those
are the same, if the highest-ranked non-paired card of
the first object is less than that of the second object, or if those are the
same if the second-highest-ranked non-paired card of the first object is
less than that of the second object, or if those are the
same if the third-highest-ranked non-paired card of the first object is
less than that of the second object;
twopair and the rank of the higher pair of
the first object is less than the rank of the higher pair of the second
object, or if those are the same if the rank of the lower pair of
the first object is less than the rank of the lower pair of the second
object, or if those are also the same, if the non-paired card of
the first object is less than that of the second object;
threeofakind and the three cards that have
the same rank in the first object are of lower rank than the three cards
that have the same rank in the second object, or if those are the same
(recall that in Texas hold'em, players can share cards from the common board)
if the rank of the highest non-three-of-a-kind card of the first object is less
than the rank of the highest non-three-of-a-kind card of the second object, or
if those are the same then (apply the same idea to the fifth card);
straight and the highest-ranked card in the first
object is less than the highest-ranked card in the second object;
flush or both are xhigh, and the
highest-ranked card in the first
object is less than the highest-ranked card in the second object, or if those
are the same and the second highest-ranked card in the first object is less
than the second highest-ranked card in the second object, or if those are the
same and the third highest-ranked card in the first object is less than the
third highest-ranked card in the second object, or if those are the same and
the fourth highest-ranked card in the first object is less than the fourth
highest-ranked card in the second object, or if those are the same and the
fifth highest-ranked card in the first object is less than the fifth
highest-ranked card in the second object;
fullhouse and the three cards that have
the same rank in the first object are of lower rank than the three cards
that have the same rank in the second object, or if those are the same
and the paired cards in the first object are of lower rank than the paired
cards in the second object;
fourofakind and the four cards that have
the same rank in the first object are of lower rank than the four cards
that have the same rank in the second object, or if those are the same then
the fifth card in the first object are of lower rank than the fifth card in
the second object; or
straightflush and the highest-ranked card in the
first object is less than the highest card in the second object.
play member function of your HoldEmGame
class, after the first three cards are dealt to the common board of cards
the players share (the flop) declare a vector of the nested struct type, and push
back an instance of that struct with each player's hand and name and the
undefined value.
The play method should then iterate through that vector, and (1) add the three
cards from the common board of cards to the two cards (from the player's hand)
in each element's CardSet and then (2) assign the element's
HoldEmHandRank member variable the result of calling the
holdem_hand_evaluation member function on the element's
CardSet member variable.
The play method should then sort the vector and print out (from the highest ranked to the lowest) each player's name, card set (which includes the player's cards and the cards from the common board of cards), and hand rank at that point in the game.
CMakeLists.txt, and fix any errors or warnings that occur.
Please be sure to note the different kinds of errors or warnings you ran into
(though you don't have to list every instance of each kind) in your readme file.
If you were fortunate enough not to run into any errors or warnings,
please note that instead, where you would have listed errors or warnings in your
readme file.
CMakeLists.txt,
as well as those to your source and header files, before uploading your solution.
CMakeLists.txt you used to compile
your solution; and (3) all your header and source files for your solution (including
any files that you may have copied over unmodified from your previous lab assignment).