Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is War War is a card game using a standard 52 card deck. The rules are pretty simple*: THE GOAL: To be the first

This is War War is a card game using a standard 52 card deck. The rules are pretty simple*:

THE GOAL: To be the first player to win all 52 cards

DEALING: The deck is divided evenly, with each player receiving 26 cards, dealt one at a time, face down. Anyone may deal first. Each player places his stack of cards face down, in front of him/her.

THE PLAY: Each player turns up a card at the same time and the player with the higher card takes both cards and puts them, face down, on the bottom of his stack. If the cards are the same rank, it is War. Each player turns up one card face down and one card face up. The player with the higher cards takes both piles (six cards). If the turned-up cards are again the same rank, each player places another card face down and turns another card face up. The player with the higher card takes all 10 cards, and so on. HOW TO KEEP SCORE The game ends when one player has won all the cards. *Instructions Taken from http://www.bicyclecards.com/how-to-play/war/

-------------------------------------- The assignment is as follows: implement this card game. I expect the console to display every rounds outcome. An example is shown below:

[Player 1]: Ace

[Player 2]: 4

Player 1 wins the round!

----------

[Player 1]: Queen

[Player 2]: King

Player 2 wins (2) cards for this round!

----------

[Player 1]: 2

[Player 2]: 2

This is War!

[Player 1]: 7

[Player 2]: 8

Player 2 wins (6) cards for this round!

I expect at the end there to be an indication of who won the game and some statistics of the game. Note that each time you run this game it will be different. It might be in your best interest totest on smaller problems. You may assume: Jacks = 11, Queens = 12, Kings = 13, Ace = 14. You must however display the word Jack, Queen, King, or Ace on the screen when showing who won a round. If a player gets in war and cant play the two required cards (one face down and one face up), that player loses the game. If using a queue, when someone wins a round, add those cards to the bottom of the deck. If using a stack, when someone wins a round, add those cards to a separate pile.Once your deck runs out, use that separate pile as your deck.

This is my code and its not working and i dont know how to fix it.

#include #include #include #include

#define ncards 52

int deck[ncards]; int deckLast = -1; int face;

///adding cards to a main queue void enqueue(int * queue, int * queueLast, int item){ *queueLast += 1; queue[*queueLast] = item; }

void shuffle(int * array, int n){ if (n > 1){ int i; for (i = 0; i < n - 1; i++){ /// get random element in the listplayer1Hand[26] = 2; int j = i + rand() / (RAND_MAX / (n - i) + 1);

///swap these two elements int temp = array[j]; array[j] = array[i]; array[i] = temp; } } }

void addToPlayerHand(int * array, int i) { int playerHand[26]; int index=0; playerHand[index+26] = deck[i+26]; index++; } //adds new card to deck at given index void addToDealerHand(int * array, int i) { int dealerHand[26]; int index=0; dealerHand[index+26] = deck[i]; index++; }

int getComparison (int *firstCard, int *secndCard) { int a,b, i; for(i = 0; i < 26; i++){ a=firstCard[i]; b=secndCard[i]; if (b>a) return 0; else if (a>b) return 1; else return 2; } }

int main() { srand(time(NULL));

///make deck int i, j; for(i = 0; i < 13; i++){ for(j = 0; j < 4; j++){ enqueue(deck, &deckLast, i + 2); } }

int dealerHand[26]; int playerHand[26];

shuffle(deck, ncards); addToPlayerHand(deck, ncards); addToDealerHand(deck, ncards);

for (i = 1; i < 26; i++) { printf("Player 1: %d ", playerHand[i]); printf("Player 2: %d ", dealerHand[i]); printf("Winning card: %d ", getComparison(playerHand, dealerHand)); }

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design And Implementation

Authors: David M. Kroenke

5th Edition

B000CSIH5A, 978-0023668814

More Books

Students also viewed these Databases questions