QuestionQuestion

Blackjack Implementation
Blackjack (also known as 21) is a multiplayer card game, with fairly simple rules.
For this assignment, you will be implementing a simplified version where a user can play against the computer who acts as dealer.
Two cards are dealt to each player.
The dealer shows one card face up, and the other is face down.
The player gets to see both of his or her cards and the total of them is added.
Face cards (Kings, Queens, and Jacks) are worth 10 points, Aces are worth 1 or 11 points, and all other cards are worth their face value.
The goal of the game is to get as close to 21 (“blackjack”) without going over (called “busting”).
The human player goes first, making his or her decisions based on the single dealer card showing.
The player has two choices: Hit or Stand. Hit means to take another card.
Stand means that the player wishes no more cards, and ends the turn, allowing for the dealer to play.
The dealer must hit if their card total is less than 17, and must stand if it is 17 or higher.
Whichever player gets closest to 21 without exceeding it, wins.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

// constant values
#define CARD_NUM 13
#define HAND_CARD 2
#define HAND_CARD_EXTRA 3
#define BLACK_JACK 21
#define DEALER_STOP_VAL 17
#define HEAD_VAL 10
#define ACE_HIGH_VAL 11
#define ACE_LOW_VAL 11

/**
* initialize all cell to 0
* @param hand
*/
void initHand(int hand[]);

/**
* draw a card
* @return a card worth
*/
int draw();

/**
* draw 2 card and show them
* @param dealer dealer's hand
* @param player player's hand
*/
void firstStep(int dealer[], int player[]);

/**
* calculate worth of hand
* @param hand
* @return worth
*/
int handVal(int hand[]);

/**
* calculate best worth of hand
* @param hand
* @return best worth
*/
int bestHandVal(int hand[]);

/**
* print dealer's hand
* @param hand
*/
void printDealer(int hand[]);

/**
* print player's hand
* @param hand
*/
void printPlayer(int hand[]);

/**
* print both hands
* @param dealer
* @param player
*/
void printHands(int dealer[], int player[]);

/**
* ask for action, apply the action
* @param dealer
* @param player
*/
void secondStep(int dealer[], int player[]);

/**
* decide the winer
* @param dealer
* @param player
*/
void thirdStep(int dealer[], int player[]);

int main(int argc, char** argv) {

    int dealer[HAND_CARD_EXTRA];
    int player[HAND_CARD_EXTRA];

    srand((unsigned int) time(NULL));

    firstStep(dealer, player);
    secondStep(dealer, player);
    thirdStep(dealer, player);
    return (EXIT_SUCCESS);
}...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

50% discount

Hours
Minutes
Seconds
$11.04 $5.52
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats