Project 4 – Blackjack

Due: April 15th, 2005

 

 

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.

 

Example Run

 

Welcome to Jon’s Casino!

Please enter your name: Jonathan

 

The dealer:

? + 10

 

You:

4 + 10 = 14

 

Would you like to “hit” or “stand”? hit

 

The dealer:

? + 10

 

You:

14  + 10 = 24 BUSTED!

 

You busted. Dealer wins.

 

 


Requirements

 

For this assignment you need to do the following:

·        Write a program that plays Blackjack

 

·        Have the program use at least 3 methods:

1.   For the Dealer

2.   For the Player

3.   To deal a card

 

·        Have the program intelligently determine if an Ace should be interpreted as a 1 or an 11. You need to be able to also handle multiple aces. If there are any aces in the hand, and the total exceeds 21, change the 11 to a 1 (i.e. subtract 10) until there are no more aces in the hand or the total is below 21. (Hint: keep a counter that says how many aces have been dealt so far to a player.)

 

·        Deal from a real deck of 52 cards.  You need to ensure that no card is dealt twice in a given game.  You will need an array to keep track of previously dealt cards.  For simplicity, you can consider each game to occur after a new shuffle.