This program is for extra credit. Students must have a completed program in order to receive any credit for this program. Unfortunately, I did have a student submit just their name in a header and expected full points for “comments”. This isn’t how this will work. Do NOT submit a weak attempt at this extra credit hoping for points. That will just take time from my TAs.
The TAs have been instructed to give fewer hints and less help for this lab. This is your time to shine! Please do not harass my TAs if you get frustrated that they’re not being as helpful as usual.
This program WILL be run through a plagiarism checker. Please note that we do have accounts to Stackoverflow, Chegg, and other commonly used “cheater” sites. Please, please, please, do not cheat. This is extra credit! It can only help you…unless you cheat. Cheating on this program violates the plagiarism/cheating policy.
You will write a program that plays the card game, Blackjack, with a player. You will have exactly two players, the player him/herself and the dealer. Both will work off of the same deck of 52 cards, so no cards will be duplicated between the dealer and player.
For purposes of this program, the Blackjack rules will be simplified.
Each card has a value and a suit:
1
2
Values: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King
Suits: Hearts, Diamonds, Spades, Clubs
Examples: Ace of Hearts, Ace of Clubs, Ace of Spades, Ace of Diamonds King of Hearts, …, and so on.
For purposes of this program, the card value and suit will be abbreviated as:
1
2
3
4
5
AH = "Ace of Hearts"
AC = "Ace of Clubs"
AD = "Ace of Diamonds"
AS = "Ace of Spades"
2H, 3C, 4D,..., JD, QC, KH, and so on.
The point of the game is to get to the value 21 without going over. You have two “responses”, hit or stand. Hit means the dealer will provide you an extra card. Stand means you’ll take the score of all of the cards you currently have. You should prompt the user for a response again if an invalid input is provided. If your score is above 21, it is called a “bust”, and you lose. If your score is 21, you automatically win without the dealer having a chance to play. After you stand, the dealer plays the game and tries to get above your score.
For purposes of your programmed dealer, it will keep “hitting” until it has a card value greater than or equal to the value 18. If the value is 18 or higher, the dealer will always stand. If the dealer goes above 21, then it will automatically lose, and the player will win.
If the player and dealer have not gone above 21, then the scores are compared. Whomever has the higher score wins. If both have the same score, they tie in a “draw”.
The output is in “Examples” below. The only formatting requirement is that all of the cards must be in a left-justified field, 20 characters wide.
1
2
3
4
5
6
7
8
9
10
Dealer has cards: KD 3S (13)
You have cards : QD AS (11)
Hit or stand ? hit
Dealer has cards: KD 3S (13)
You have cards : QD AS 6D (17)
Hit or stand ? stand
Dealer hits : KD 3S KS (23)
Dealer busts, player wins!
1
2
3
4
5
6
7
Dealer has cards: 4S 8D (12)
You have cards : 9D 10H (19)
Hit or stand ? hit
Dealer has cards: 4S 8D (12)
You have cards : 9D 10H 10C (29)
Player busts, dealer wins!
1
2
3
4
5
6
7
Dealer has cards: KS 9D (19)
You have cards : 9D 10H (19)
Hit or stand ? stand
Dealer has cards: KS 9D (19)
You have cards : 9D 10H (19)
Player and dealer draw.
1
2
3
4
5
6
7
8
9
10
Dealer has cards: 2S 9D (11)
You have cards : 10D 9H (19)
Hit or stand ? stand
Dealer hits : 2S 9D 9S (20)
Dealer stands : 2S 9D 9S (20)
Dealer has cards: 2S 9D 9S (20)
You have cards : 10D 9H (19)
Dealer wins!
You must write prototypes, definitions, and calls for functions that perform the following operations: (1) deal a single card to player or dealer, (2) return a random number between a minimum and maximum value, (3) initialize the cards, (4) score the player and/or dealer’s hands. NOTE: Even though you can initialize your array when you declare it, we want you to pass your array to a function to initialize it.
Write a function called DealCard, which will take an array of 52 cards and a player to deal a card to. The function will randomly choose an undealt card and assign it to the given player. The function will then return which card it dealt to the player.
Write a function called GetRandom, which will take a minimum and maximum value. This function will return a random number between [min, max] (inclusively). You must include <cstdlib>
to write this function - view c++ reference to understand how to use rand(). Link is HERE
Write a function called InitializeCards, where you pass your array to initialize.
Write a function called ScoreHand, which will take an array of 52 cards and a player whose hand to score. The function will return the final score. To score the hand, each face card (Jack, Queen, King) will be 10 points. The numeric cards will be their numeric value, and aces will be 1 point. The suit of the card is not part of the point value calculation.
Additionally,
The 52 cards must be in a single array. The array will have 52 elements, and it will store which player has which card. The player and dealer will receive exactly two cards at the beginning of the game.
You must use arithmetic to determine which card fits each array index (0 - 51). You must not use a branch construct, such as any if statements or switch statements. For this, you might need an array to store each suit ‘D’,’C’, ‘H’, ‘S’, and another to store the values A, 2, 3, …, Q, K.
You can submit the extra credit lab with #1-6 restrictions only above. However, you may implement one or more of these below for more extra credit. The TAs will not assist with implementation of the extra credit.
(10 points) The actual blackjack game allows the player to decide whether an ace is 1 point or 11 points when scoring the winning hand. Your program will allow the player to decide as well, but will automatically give the best hand to the dealer. In this relaxed version, an ace is only 1 point. For extra credit, have your program select 1 or 11 depending on which is more beneficial to the dealer, and give the option to the player. Also, this means the dealer must determine whether to hit or stand based on this new allowance. For example, if the dealer gets an 8 and an ace, they could have 9 or 19. The dealer must take the lesser value (1 point) unless they have a hand of 20 or 21 points. The player and dealer’s best hands win.
(15 points) In Blackjack, if the player is dealt two cards with the same value, they can “split”, meaning now they play using two hands. This doubles their chance to beat the dealer. However, the dealer can split as well and play two hands. For extra credit, give the player the option to split their hand and essentially play two hands. The dealer’s AI needs to split only when the dealer gets aces or eights.
WARNING: If #7 and 8 cause your original lab to fail certain test cases, you will not be spared point deductions! Therefore, it is best to save your original solution just in case you cannot complete #7 and 8.
Please remember that all labs are to be completed individually and are subject to the plagiarism policy on the course syllabus.
Submit blackjack.cpp. Your code must be properly formatted and commented. If your code does not compile, it will not be graded.