x.Hm/title>Introdution: Assignment is to write a video blackjack program. The co
ID: 3618122 • Letter: X
Question
x.Hm/title>Introdution:Assignment is to write a video blackjack program.
The conventional game is played between two players as follows.
Each player takes three cards from the deck. They then add up
the points in their respective hands. The point value of a card
whose denomination is between two and ten is simply the denomination
of the card. For example, the point value of the ‘four of clubs’
is four points. The point value of a face card (i.e., Jack, Queen or King)
is ten points, and the point value of an Ace is eleven points.
The player whose point total is closest to 21 without going over is the winner.
If both players exceed 21 points or if they have the same point value, there is no winner.
In addition, if exactly one of the players exceeds 21, the other player is the winner.
We will change the rules a bit. In our version -- there exist 1 dealer
and 1 player in the game. The dealer draws one card and shows it to the player.
The player draws two cards. Then, the player can choose to hit (take another card)
or stand (finish the turn). The goal is to come as close to 21 (summing the card values)
as possible without going over. Once the player stands, the dealer draws cards.
The dealer automatically hits if the sum of his/her hand is less than or equal to 16 and
stands at 17 or above. Once the dealer stands, dealer and player compare the sums of their hands.
The one with the larger sum wins. If there is a tie, nobody wins (no money gained/lost).
So you are writing a computer program to behave as the dealer.
The person using the program will be the player.
This is a one player game against a computer dealer.
The input/output is open ended on this problem, but it should have
the following features:
When the program loads, first ask the player to enter a dollar amount
(this represents the player's total cash)
Then, draw a random card for the dealer and show it to the user (and keep track of it)
Draw two cards for the player, display them and print the sum.
Ask the player to HIT or STAND (repeat if necessary)
If the player's total ever goes above 21, player loses
If the player STANDs at any point, you should draw cards for the dealer as described above.
The dealer loses if the total goes over 21. Otherwise, compare the totals of the user and player.
The one with the bigger total wins.
Assume a player bets $5 each time.
So a loss costs the player $5 while a win gains $5
Allow the player to keep playing (loop).
Working example should look something 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 forget that.
I want your implementation to create and use the following functions:
void displayCard(appropriate args) This method displays the calling card in the traditional way,
for example, ‘ace of hearts’, ‘two of diamonds’, etc.
void fillDeck( Card * const wDeck, const char * wFace[],
const char * wSuit[] ) This method fills the deck.
void shuffle(Card * const wDeck ) This method shuffles the calling deck.
void takeACard(Card * const wDeck) This method causes the calling player to take one card from the top of the deck d and insert the card at position numOfCards in his or her hand. The value of numOfCards is then updated.
int computePoints(appropriate args)This method causes the calling player to
compute and return the point value of his or her hand.
void showHand(appropriate args) This method will cause the calling player
to print out his or her hand and the point value of the hand.
void discardHand(appropriate args) This method causes the calling player
to discard his or her hand.
int whoWins(Player p1, Player p2) This method decides whether player 1 or
player 2 has won the game. The method returns 1 if player 1 wins and returns 2 if player 2 wins. Otherwise, it returns 3 (in case of a tie or if both players are over 21).
Remember to use the code that we have already developed.
----------Use the following skeleton for the main program:-----------------------
#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 <=
Explanation / Answer
please rate - thanks more to follow #include #include #include #include void deal(int,int,int*); void deal2(int,int,int*,int*); int getbet(int); int main() { int totdealer,totplayer; int money,bet,aces,i,win; char *person[]={"Dealer","player"}; char hit[]="HIT"; char yesno='Y'; int again; srand(time(0)); printf("How much money do you have? "); scanf("%d",&money); while(money>0&&yesno=='Y') {bet=getbet(money); totdealer=0; deal(0,1,&totdealer); printf(" total is %d ",totdealer); aces=0; totplayer=0; deal2(1,2,&aces,&totplayer); printf(" total is %d ",totplayer); again=0; while(totdealermoney) {printf("You cannot bet more then youhave!!! "); printf("You have $%d enter your bet:",money); scanf("%d",&bet); } while(fgetc( stdin ) != ' '); return bet; }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.