Question: Write a program in C++ that simulates a simplified version of the card game of War. In this game, one player competes against the computer
Write a program in C++ that simulates a simplified version of the card game of War. In this game, one player competes against the computer for the most points. The game starts with a shuffled deck of cards. One card is then dealt to the player, and one card is dealt to the computer. The value of both cards are compared and whichever player has the higher card wins the battle and receives two points. If both cards have the same value, the battle is a tie and both players get one point. Play continues until all cards have been dealt. The winner of the War is the player with the most points.
To implement this program, you will be required to use the following:
A struct that represents a card:
struct Card { string suit; string name;
int value; };
A vector of 52 Cards, used to simulate a deck of cards. Use a constant to represent the number of cards in a deck. Use an integer variable called nextCard to keep track of the index value representing the next undealt card in the deck (when the game starts, no cards have been dealt yet so nextCard is 0, representing the first card in the deck).
const int NUMCARDS = 52; vector Deck(NUMCARDS); int nextCard = 0;
Void functions to carry out each of the following tasks:
Initialize the deck of cards. A deck of cards consists of 13 cards in each suit clubs, diamonds, hearts, spades. The 13 cards have values ranging from 1 to 13, where the value 1 is called an Ace, the value 2 is called a Deuce, the value 11 is called a Jack, the value 12 is called a Queen, and the value 13 is called a King.
Shuffle the deck of cards. This function should randomly rearrange the cards in the deck. One possible algorithm is to iterate through the entire vector, swapping each card with another randomly selected card.
Display a single card (e.g., Ace of Spades)
Display the entire deck of cards
Other variables as needed to track the players score, computers score, players card, computers card, etc.
Do not use global variables or constants.
Provide comments at the beginning of your program describing what your program does.
Provide a comment before each function header that identifies what the function does, and the purpose of each parameter.
Provide blank lines throughout your program for readability, and use meaningful variable names and function names. Use proper indentation throughout.
Make your output professional, with proper spelling, capitalization, and punctuation. Use blank lines in your output for readability
Your programs main function should follow the general algorithm below. (pseudocode)
Seed the random number generator
Display card game info
Initialize the deck of cards and display it
Shuffle the deck and display it again
Set nextCard to 0
Set players score and computers score to 0
Ask the user whether or not they want to play or quit
While the user wants to play AND nextCard is <= NUMCARDS - 2:
Ask the user to press Enter to continue
Set players card equal to Deck.at(nextCard)
Increment nextCard
Display the players card
Set computers card equal to Deck.at(nextCard)
Increment nextCard
Display the computers card
If the value of players card > the value of computers card then
add 2 to players score and display that player won the battle
Else if the value of computers card > value of players card then
add 2 to computers score, display that computer won the battle
Else
add 1 to each score and display that the battle was a tie
Display the two scores
Determine who won the War (who had most points) and display the results
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
