Subject Computer Science C-Family Programming

Question

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 Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse 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);
}...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor

Related Homework Solutions

Craps Game in Programming Language C
Homework Solution
$35.00
Programming
C
Craps
Game Development
Coding
Algorithms
Dice
Numbers
Players
Statements
Variables
Bet
Results
Money
Win
Lose
Functions
Bank Roll
Associative Arrays in C++
Homework Solution
$75.00
Programming
C++
Associative Arrays
Computer Science
Hash Tables
Chaining
Static Arrays
Game of Life
Records
Strings
Integers
Objects
Functions
Copying
Applet
Sequences
Lists
Prime Numbers
Simulations
Coding Using Pipes
Homework Solution
$30.00
Computer Science
Programming
Algorithms
Pipes
File Management
Command Line
Communication
Utility Program
Display Results
Numbers
Input
Output
Characters
Errors
Attributes & Methods in C++
Homework Solution
$10.00
Programming
C++
Computer Science
Attributes
Methods
Students
People
Inheritance
Employees
Salaries
Job Titles
Classes
Statements
Variables
C Code Errors Minireport
Homework Solution
$25.00
Error
C
Code
Message
Compiler
Common
Friendly
Computer Science
C-Family Programming
Sorting Algorithms in C++
Homework Solution
$40.00
Programming
Computer Science
C++
Sorting Algorithms
Quicksort
Mergesort
Insertion sort
Subarrays
Arrays
Expected Time
Running Time
Random Numbers
Pair of Values
Get help from a qualified tutor
Live Chats