Write a program that plays the casino game blackjack, or 21. Blackjack is a competition between the dealer and player(s) to see who can get closest to 21 points without going over (busting).

Implementation Notes

  • The player is dealt two cards face up, and the dealer (computer) initially only show one of his cards face up.
  • The player has the choice to take a card (hit) or to stay with what he has.
  • A hands present total is calculated by simply adding the face value of the cards.
  • In blackjack, the cards are valued as follows:
    • An Ace (A) can count as either 1 or 11 (the Ace value only becomes 1 if the player would otherwise have bust).
    • The cards from 2 through 10 are valued as indicated.
    • The J, Q, and K are all valued at 10.
  • The suits of the cards do not have any meaning in the game.
  • The player may keep taking cards until he chooses to stay, or until his cards total more than 21.
  • If this happens the player is deemed to have bust and losses the hand. The hand is then over.
  • If the player has stayed on 21 or less it is the dealers turn to take cards.
  • The dealer must follow very fixed rules and keep taking cards until he has at least 17, and he must stop when he gets 17 or more.
  • If through taking cards the dealers total exceeds 21 he too busts. If the dealer busts and the player remains, then the player wins the hand.
  • If the dealer does not bust the winner of the hand is the person with the highest total, whether that be the dealer or the player.
  • If the totals are identical a push results and the hand is deemed a draw (tie).
  • The best hand in the game is called blackjack- this consists of an Ace and any card valued at 10, in any order. If the dealer gets blackjack he automatically wins the hand unless the player also has a blackjack in which case a push (draw) results.
  • A standard deck of cards is used- no jokers.

Modifications to above:

  • Create a menu at the start of the game that allows the user to:
    • Input values from keyboard (like above)- demo mode
    • Input values from a randomly generated values (default)- game mode
Do you wish to play in (e)-Demo or (g)-Game mode? e
  • Use a string to enter the players name via the keyboard.
Enter player name: James
  • A prompt for intra-round commands must show which commands are currently available for the player (lower case letters). Note not all commands are always available.
(h)-Hit (s)-Stand (d)-Double Down (p)-Split (i)-Insurance (q)-Quit
  • Have the dealer (computer) initially only show one of his cards face up. Example:
Dealer’s cards: [?] XX QS
Here the value of the hand is unknown. Once the player has finished his turn he will reveal his
other card. Then ask user to play again.
Dealer’s cards: [?] XX QS Your cards: [11] 6S 5H
(h)-Hit (s)-Stand (d)-Double Down (q)-Quit? h
You drew: [17] 6H
(h)-Hit (s)-Stand? s
Dealer’s cards: [20] QC QS
Your cards: [17] 6S 5H 6H
Dealer wins. Game over.
Play again (Y/N)? n
  • Reshuffling cards- This program feature detects when 52 cards have been dealt, and continues play uninterrupted by restarting dealing with a new shuffled deck of 52 cards. Whenever reshuffling is needed, it happens automatically. The user is informed when reshuffling happens with the output of the message "Reshuffling ...". After the message, play continues where it left off.
  • Betting Rules:
    • Only the player can place a bet and must be made before any cards are dealt. An initial value of $1000 is given.
    • The minimum bet must be $10 and a maximum bet of $1000, and the player can only bet in $10 increments. Output the initial bet, bet amounts, and error check.
    • The game should quit automatically when the player runs out of money.
    • When a hand is finished, the players total winnings are printed.
    • The following table defines how winnings are computed for a hand:

Hand Outcomes Win/Loss Amount
player wins regular handbet
dealer wins regular hand-bet
player wins with blackjack hand1.5 * bet
player and dealer tie0
player wins doubled down hand2 * bet
player wins doubled down hand with blackjack3 * bet
player wins both split hands2 * bet
player loses both split hands-2 * bet
player wins one, loses one split hands0
player win one, ties one split handsbet
player loses one, ties one split hands-bet

Other features to be included- applicable only to the player:

  • Insurance- When the dealers face up card is an ace, a side bet of up to half of the original bet that the dealers face down card is a ten (point) card, thus a blackjack for the house. If the dealers card is a ten card, it is turned up, and the player who made the insurance bet wins and paid double the amount of their half bet- 2 to 1 payoff. If the player has blackjack as well- it is a stand-off (tie).
  • Doubling Down. Another option open to the player is doubling his bet when the original two cards dealt total 9, 10, or 11. When the player's turn comes, he places a bet equal to the original bet, and the dealer gives him just one card, which is placed face down and is not turned up until the bets are settled at the end of the hand. With two fives, the player may split a pair, double down, or just play the hand in the regular way.
  • Surrender or Quit. This only available as first decision of a hand. When the player surrenders, the house takes half the player's bet and returns the other half to the player; this terminates the player's interest in the hand.
  • Splitting Pairs. When the player has a hand with two of the same cards, the player may choose to split the hands into two separate hands. This command is only available as the first player command in a hand. That is, splitting can only happen immediately after the hand is dealt, and the hand has two cards of the same value. Splitting is allowed on hands with two different face cards, i.e., a Jack and a Queen, since these both have a value of 10. Play on the separate hands proceeds individually, in the same way as for a single hand. The first hand is played to conclusion, then the second hand, then the dealers hand if necessary. The precise play of the hand goes like this:
    • If the first hand busts, the message "Player busts." is output, and play proceeds to the second player hand.
    • if the second hand also busts, the message "Player busts." is output again, and play concludes by printing all three hands, with the dealers hidden card revealed
    • If one or both player hands does not bust, then the dealer plays, and two messages are output indicating the conclusion of each of the split hands.

Use user-defined functions/methods in your program. Do not use break or continue statements. For C++ use the string class; otherwise, use any data structure of your choice. Output should by user friendly.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.