We will change the rules a bit. In our version -- there exist 1dealer and 1 play
ID: 3618363 • Letter: W
Question
We will change the rules a bit. In our version -- there exist 1dealer and 1 player in the game. The dealer draws one card andshows it to the player. The player draws two cards. Then, theplayer can choose to hit (take another card) orstand (finish the turn). The goal is to come asclose to 21 (summing the card values) as possible without goingover. Once the player stands, the dealer draws cards. The dealerautomatically hits if the sum of his/her hand is less than or equalto 16 and stands at 17 or above. Once the dealer stands, dealer andplayer compare the sums of their hands. The one with the larger sumwins. If there is a tie, nobody wins (no money gained/lost).
So you are writing a computer program to behave as thedealer. The person using the program will be the player. This is aone player game against a computer dealer.
The input/output is open ended on this problem, but it shouldhave the following features:
When the program loads, first ask the player to enter a dollaramount (this represents the player's total cash)Then, draw a randomcard for the dealer and show it to the user (and keep track ofit) Draw two cards for the player, display them and print thesum. Ask the player to HIT or STAND (repeat if necessary). Ifthe player's total ever goes above 21, player loses. If theplayer STANDs at any point, you should draw cards for the dealer asdescribed above. The dealer loses if the total goes over 21.Otherwise, compare the totals of the user and player. The one withthe bigger total wins. Assume a player bets $5 each time. Soa loss costs the player $5 while a win gains. Allow theplayer to keep playing (loop). Working example should looksomething like this:
? How much money are you bringing: 85?
? Dealer has 8, (make sure you display the card)
? ?Player has 4, (make sure you display the card)
? ?HIT or STAND: HIT?
? Player has 10, (make sure you display the card)
? ?HIT or STAND: HIT
? ?Player has 20, (make sure you display the card)
? ?HIT or STAND: STAND
? ?Dealer has 12?, (make sure you display the card)
? Dealer has 18, (make sure you display the card) ?
? Player wins! ($90 total)
Above, anything after a colon was entered by the player. Also,the first "Player has" line must have drawn TWO cards. Don't forgetthat.
I want your implementation to create and use the followingfunctions:
void displayCard(appropriate args) This method displays thecalling card in the traditional way, for example, ‘ace ofhearts’, ‘two of diamonds’, etc.
void fillDeck( Card * const wDeck, const char * wFace[],
const char * wSuit[] ) This method fills thedeck.
void shuffle(Card * const wDeck ) This method shuffles thecalling deck.
void takeACard(Card * const wDeck) This method causes thecalling player to take one card from the top of the deck d andinsert the card at position numOfCards in his or her hand. Thevalue of numOfCards is then updated.
int computePoints(appropriate args)This method causes thecalling player to compute and return the point value of his or herhand.
void showHand(appropriate args) This method will cause thecalling player to print out his or her hand and the point value ofthe hand.
void discardHand(appropriate args) This method causes thecalling player to discard his or her hand.
int whoWins(Player p1, Player p2) This method decides whetherplayer 1 or player 2 has won the game. The method returns 1 ifplayer 1 wins and returns 2 if player 2 wins. Otherwise, it returns3 (in case of a tie or if both players are over 21).
Remember to use the code that we have already developed.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/* card structure definition*/
struct card{
const char *face; /* define pointer face */
const char *suit; /* define pointer suit */
}; /* end structure card*/
typedef struct card Card; /* new type name for struct card*/
/* prototypes */
void fillDeck( Card * const wDeck, const char * wFace[],
const char * wSuit[] );
void shuffle( Card * const wDeck );
int main()
{
Card deck[ 52 ]; /* define array of Cards */
/* initialize array of pointers */
const char *face[] = { "Ace", "Deuce", "Three","Four", "Five",
"Six", "Seven", "Eight", "Nine","Ten",
"Jack", "Queen", "King"};
/* initialize array of pointers */
const char *suit[] = { "Hearts", "Diamonds","Clubs", "Spades"};
srand( time( NULL ) ); /* randomize */
fillDeck( deck, face, suit );
shuffle( deck );
return 0;
}
void fillDeck( Card * const wDeck, const char * wFace[],
const char * wSuit[] )
{
int i; /* counter */
/* loop through wDeck */
for ( i = 0; i <= 51; i++ ) {
wDeck[ i ].face = wFace[ i % 13];
wDeck[ i ].suit = wSuit[ i / 13];
} /* end for */
} /* end function fillDeck */
void shuffle( Card * const wDeck )
{
int i; /* counter */
int j; /* variable to holdrandom value between 0 - 51 */
Card temp; /* define temporary structure forswapping Cards */
/* loop through wDeck randomly swapping Cards*/
for ( i = 0; i <= 51; i++ ) {
j = rand() % 52;
temp = wDeck[ i];
wDeck[ i ] = wDeck[ j ];
wDeck[ j ] =temp;
} /* end for */
} /* end function shuffle */
Explanation / Answer
please rate- thanks #include #include #include #include void deal(int,int,int*,int*,int[][2]); void deal2(int,int,int*,int*,int*,int[][2]); void filldeck(int[][2]); void shuffle(int[][2]); void getcard(int,int*,int*,int[][2]); int whoWins(int,int); int main() { int totdealer,totplayer,deck[52][2]; int money,bet=5,aces,i,win; char *person[]={"Dealer","player"}; char hit[]="HIT"; int yesno='Y'; int again,upto=0; srand(time(0)); printf("How much money do you have? "); scanf("%d",&money); while(money>0&&yesno=='Y') {totdealer=0; filldeck(deck); shuffle(deck); deal(0,1,&totdealer,&upto,deck); printf(" total is %d ",totdealer); aces=0; totplayer=0; deal2(1,2,&aces,&totplayer,&upto,deck); printf(" total is %d ",totplayer); again=0; while(totdealer21) return 0; else if(totdealerRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.