Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Black-Jack Assignment For this last assignment, we will be writing a program that two people can use to play a game of BlackJack! NOTE: There

Black-Jack Assignment

For this last assignment, we will be writing a program that two people can use to play a game of BlackJack!

NOTE: There should be THREE players. Two regular players AND the dealer, as the dealer also gets dealt a hand in Black-Jack.

You should create the following structs:

STRUCTS

dealer struct: represents the card dealer in a game of black-jack

members:

deck_of_cards array that can be used to store values representing different cards (there are 52 cards in a deck of cards)

cards_used another array used to represent whether or not a particular card in the deck has been handed to a player (you could use the value 0 to indicate that a particular card is still available and 1 to indicate that it has already been handed out)

remaining_cards a single numeric value representing how many cards are still available to be handed out in the deck

player struct pointer since the dealer is also a player, this struct represents the dealers cards

player struct: represents a single player in a game of black-jack

members:

hand an array representing all of the cards that a player is holding in their hand

how_many a single numeric value representing how many cards this player has in their hand

FUNCTIONS

shuffle resets remaining_cards to the whole deck and cards_used to all 0s, and resets each players hand info (including the dealer) so that they have no cards.

parameter: player struct pointer, player struct pointer, dealer struct pointer

initial_deal pass out first 2 cards to each player and the dealer

parameters: player struct pointer, player struct pointer, dealer struct pointer

should give 1 card at a time to each player until all cards have been handed out

To give a single card to a player or the dealer, you should:

randomly pick a # between 0 and 51,

then check to see if that card has been handed out yet

if not,

hand it to a player,

update cards_used

update remaining_cards

update players hand

update how many cards player is holding

if so, keep checking until you find a card that hasnt been given out yet

hit gives one card to a player

parameters: player struct pointer, dealer struct pointer

To give a player a card:

check to see if there are cards remaining

if so:

randomly pick a # between 0 and 51

check to see if card has been handed out

if not

hand it to player,

update dealer cards_used

update dealer remaining_cards

update players hand

update how many cards player is holding

if so, keep checking until you find a card that hasnt been given out yet

blackjack checks a players hand to see if hit 21

parameter: player struct pointer

To check if a players hand is equal to 21:

Add up the value of all of the cards in their hand (remember that an ace could be a 1 or an 11. You should check for both to see if the value of all of the cards add up to 21.

returns true if 21, false otherwise

bust checks to see if players hand is over 21

parameter: player struct pointer

Similar to above, except checking to see if combined values of cards if over 21. Remember that an ace can be 1 or 11. If the combined value of their cards is under 21 when ace is counted as 1, but over 21 when ace is counted as 11, then this function should return false (it is NOT a bust if their cards are not over 21).

returns true if total value of all cards in players hand is over 21 , false otherwise

display_hand displays cards in players hand

parameter: player struct pointer

prints the cards that the player is holding to the screen

main plays game by initializing two players and dealer, and calling appropriate functions

After passing out the initial set of cards (the initial deal), first check to see if any of the players hit blackjack (21). If so, that player won the game. Display a message indicating as much and ask if they want to play another game.

If no one wins after the initial deal, starting with player1, display that players hand to them and prompt them to see if they want to hit or stay. Each time a player wants another card (hit me), give them a card, then check for blackjack or check to see if they busted (cards cumulative value is over 21). If either is true, you should either state they won or they lost. If that player chooses to stay (no more cards) move to the next player and repeat it.

If no one has won or lost yet and the second player chooses to stay. Repeat the process for the dealer.

If no one has won or lost yet, and the dealer chooses to stay, compare the values of all of the hands (the cards in the hands of the dealer, and player one, and player two) and declare a winner (whoever is closer to 21).

After a winner is declared, prompt the user(s) to see if theyd like to play again. If they would, reset the deck and start the game over.

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_2

Step: 3

blur-text-image_3

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

What is helping you move forward?

Answered: 1 week ago