Problem Statement Write a program that plays simplified poker game with the comp
ID: 3676685 • Letter: P
Question
Problem Statement
Write a program that plays simplified poker game with the computer.
Ask the user to input an integer in the range [1, 13], representing a simplified poker card with no suit (1: A, 11: J, 12: Q; 13: K). Then the computer generates four random integers in the same range, together with the user input, as five poker
cards for the user.
The computer generates another set of five random integers as the poker cards for
the computer. Each one is also in the range [1, 13].
Your program should then compare the highest ranking of the 5 hands between user and the computer, then report the one, who has higher ranking of the 5 hands, wins the game. Here is the rule to decide the highest ranking of the 5 hands (from higher to lower ranking) – namely, Four of a Kind(4 of the 5 cards are equal), Full House(three cards are equal of one rank, and two cards are equal of another rank), Three of a Kind(any 3 cards are equal), Pair(any 2 cards are equal), and High Card(no two cards are equal). For example, when 3, 1, 8, 1, 3 are entered, your program should print “Pair(1)”. (Note that 1 is higher than 3 since 1 represents A in the card.) When 2, 11, 7, 3, 5 are entered, it will print “High(11)”. When 10, 7, 10, 7, 7 are entered, it will print “Full House(7)”. (Note if it is a Full House, report the rank of three matching cards instead of the rank of two matching cards). An you don’t need to consider other rankings such as Straight or Flush. When the user and the computer have the same kind of the 5 hands, then the higher value of the card has the higher ranking. For example, if both have Full House, then “Full House(12)” is higher than “Full House(11)”.
Note the real poker game contains 52 cards in a deck, divided into four suits of 13 ranks each, so that it can never happen that five cards are equal. However, since your program uses the random number generator to generate five cards (no suite), five can be equal. In order to avoid this case (five cards happen to be the same), your program should generate four cards first, then while generating the fifth card, it needs to check whether the fifth card has already been in the hand four times. If it is the case, then generate a different card.
The following is a sample output from running your program:
In order to keep your program's window from closing, instead of calling system("pause"); before returning from main, now we can call the following function right before the return statement in the main function. Remember to declare the function before you can call the function.
void pause_215(bool have_newline) {
if (have_newline) {
// Ignore the newline after the user's previous input.
cin.ignore(256, ' '); }
// Prompt for the user to press ENTER, then wait for a newline.
cout << endl << "Press ENTER to continue." << endl;
cin.ignore(256, ' '); }
Your program must compile and execute without any errors or warnings. Think about the following questions:
Does the user have strategies to win the game? Should you always choose the higher value card for yourself?
To make the game fun to play, is it good enough to let your program just generate pseudorandom numbers? Or is it necessary to call srand to set where rand starts? Try both methods and check the result.
How to generate the different testing cases considering each case is controlled by the random number generator?
Explanation / Answer
public class Card_pkr
{
private short ranks_pkr_pkr, suits_pkr;
private static String[] suits_pkr = { "hearts", "spades", "diamonds", "clubs" };
private static String[] ranks_pkr_pkr = { "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King" };
public static String rankAsString( int __rank ) {
return ranks_pkr_pkr[__rank];
}
Card_pkr(short suit, short rank)
{
this.ranks_pkr_pkr=rank;
this.suits_pkr=suit;
}
public @Override String toString()
{
return ranks_pkr_pkr[rank] + " of " + suits_pkr[suit];
}
public short getRanks_pkr_pkr() {
return ranks_pkr_pkr;
}
public short getSuit() {
return suit;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.