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],
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 dont 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:
Let us start to play the game (Press Q to quit) Enter your card number (in the range of [1,13]): a Invalid card number!
Let us start to play the game (Press Q to quit) Enter your card number (in the range of [1,13]): k Invalid card number!
Let us start to play the game (Press Q to quit) Enter your card number (in the range of [1,13]): 18 Invalid range!
Let us start to play the game (Press Q to quit) Enter your card number (in the range of [1,13]): -7 Invalid range!
Let us start to play the game (Press Q to quit) Enter your card number (in the range of [1,13]): 7
Your five cards are 7 1 9 10 6
My five cards are 6 4 5 12 3
The ranking of your poker cards is: High Card(1)
The ranking of my poker cards is: High Card(12) Congratulations, you won the game!
Let us start to play the game (Press Q to quit) Enter your card number (in the range of [1,13]): 5
Your five cards are 5 10 10 1 8 My five cards are 11 5 2 13 11 The ranking of your poker cards is: Pair(10)
The ranking of my poker cards is: Pair(11) Sorry, you lost the game!
Let us start to play the game (Press Q to quit) Enter your card number (in the range of [1,13]): 13
Your five cards are 13 7 6 7 6
My five cards are 1 12 2 6 13
The ranking of your poker cards is: Pair(7)
The ranking of my poker cards is: High Card(1) Congratulations, you won the game!
Let us start to play the game (Press Q to quit) Enter your card number (in the range of [1,13]): 7
Your five cards are 7 11 3 7 3
My five cards are 12 4 7 7 6
The ranking of your poker cards is: Pair(7)
The ranking of my poker cards is: Pair(7) We tied!
Let us start to play the game (Press Q to quit) Enter your card number (in the range of [1,13]): 4
Your five cards are 4 4 13 4 6
My five cards are 7 12 7 11 6
The ranking of your poker cards is: Three of a kind(4)
The ranking of my poker cards is: Pair(7) Congratulations, you won the game!
Let us start to play the game (Press Q to quit) Enter your card number (in the range of [1,13]): 4
Your five cards are 4 8 8 7 8 My five cards are 3 2 5 5 5 The ranking of your poker cards is: Three of a kind(8)
The ranking of my poker cards is: Three of a kind(5) Congratulations, you won the game!
Let us start to play the game (Press Q to quit) Enter your card number (in the range of [1,13]): 1
Your five cards are 1 11 3 8 7
My five cards are 7 9 9 9 9
The ranking of your poker cards is: High Card(1)
The ranking of my poker cards is: Four of a kind(9) Sorry, you lost the game!
Let us start to play the game (Press Q to quit) Enter your card number (in the range of [1,13]): 1
Your five cards are 1 10 1 10 1
My five cards are 9 8 9 10 4
The ranking of your poker cards is: Full House(1)
The ranking of my poker cards is: Pair(9) Congratulations, you won the game!
Let us start to play the game (Press Q to quit) Enter your card number (in the range of [1,13]): q Thank you for playing this game!
Press ENTER to continue.
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?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
