The card game “War” is played by the following rules (you may have learned different rules. Use these): - Each player gets half of the deck of cards (in our case, a set of random integers with value 1-13) - The game itself is played in a series of “rounds”. In each round: o Both players draw a card, putting it into the “reward pile” (and removing it from their hand). o If one player’s card is higher than another, they gain all cards in the reward pile (and add it to their hand) o If there is a tie, both players add an additional card to the reward pile (which is not compared - I call this a “penalty card” in my sample run below), and then we begin a new round with a larger reward pile. The next round’s winner will win the entire reward pile (though it is possible to have multiple consecutive ties, leading to a much larger reward pile) - The game ends when a player needs to draw a card and cannot. That player loses. Your task is to implement this game with the player’s hands and the reward pile as bags of integers. You should allow the user to specify the size of the initial hands (I used 5 card hands to test my program, since half of an official card deck is 26 cards, and simulating 26 card decks runs for a long time). Each round, you should display: - The current round - The values of each player’s hands (by outputting the values of the bag’s to_vector function) - The cads drawn in the current round, and who won. Of course, you will have to finish the Bag lab to be able to do this. Your main program should only use Bags to manage the cards. (So no vectors, strings, or anything like that). You should implement the game using the Bag member functions. My only exception was that I used the “to_vector” Bag function to get the cards in a hand so I could write a Print_Vector function. But generally: - Cards go into the hand and reward pile using insert - Specific cards leave the hand and reward pile using remove - The card that gets played from the hand gets selected using (the random version of) choose

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter6: Looping
Section: Chapter Questions
Problem 5GZ
icon
Related questions
icon
Concept explainers
Question

The card game “War” is played by the following rules (you may have learned different rules. Use these):

- Each player gets half of the deck of cards (in our case, a set of random integers with value 1-13)

- The game itself is played in a series of “rounds”. In each round: o Both players draw a card, putting it into the “reward pile” (and removing it from their hand). o If one player’s card is higher than another, they gain all cards in the reward pile (and add it to their hand) o If there is a tie, both players add an additional card to the reward pile (which is not compared

- I call this a “penalty card” in my sample run below), and then we begin a new round with a larger reward pile. The next round’s winner will win the entire reward pile (though it is possible to have multiple consecutive ties, leading to a much larger reward pile)

- The game ends when a player needs to draw a card and cannot. That player loses.

Your task is to implement this game with the player’s hands and the reward pile as bags of integers. You should allow the user to specify the size of the initial hands (I used 5 card hands to test my program, since half of an official card deck is 26 cards, and simulating 26 card decks runs for a long time).

Each round, you should display: - The current round - The values of each player’s hands (by outputting the values of the bag’s to_vector function)

- The cads drawn in the current round, and who won. Of course, you will have to finish the Bag lab to be able to do this. Your main program should only use Bags to manage the cards. (So no vectors, strings, or anything like that). You should implement the game using the Bag member functions. My only exception was that I used the “to_vector” Bag function to get the cards in a hand so I could write a Print_Vector function. But generally:

- Cards go into the hand and reward pile using insert

- Specific cards leave the hand and reward pile using remove

- The card that gets played from the hand gets selected using (the random version of) choose

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Control Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT