### CPSC 120 Assignment #4 Blackjack with Classes Part I Due, Friday November 21, 2008 by 4 p.m.

In this assignment you will write a program that plays the game of Blackjack. The main idea of Blackjack is to get a hand of cards that adds up as close as possible to 21 without going over. We will use the following rules:

• There are two players. One is called the dealer and has very strict rules for how to play; the other we'll call the player.

• At the beginning of the game, each player gets two cards. The player gets to see both of his or her cards. One of the dealer's cards (called the top card) is shown.

• The value of a hand, called the "count", is the sum of the face values of the cards. Face cards (Jack, Queen, King) have a value of 10. The ace can have a point value of 11 or 1. Generally it is an 11 unless that makes the total count go over 21. When the count includes an ace that has been counted as an 11 the count is called soft. If a new card is dealt that puts the count over 21 and if the current count is soft 10 points are deducted (in other words the ace counts only 1) adn the count is no longer soft. In most games the dealer always uses a soft count; that is, the ace is always valued at 11.

• After the hands are dealt, the player goes first. If the player was dealt blackjack (an ace and a card valued at 10 points) but the dealer was not, the player wins and the game is over. If both the dealer and the player are dealt blackjack, the game is a tie. Otherwise, the player gets to decide whether to hit or stick (some people say "stand" and some say "stay"). Hit means get another card; stick means to stop taking cards. The player can keep taking cards (hitting) until he/she decides to stay or busts (goes over 21 points).

• If the player busts, he/she loses and the game is over.

• If the player does not bust, it is the dealer's turn.

• The dealer has strict rules that determine when to hit and when to stick. If the current count (total value of the hand) is 16 or less, the dealer hits. On a count of 17 or more, the dealer sticks. If the dealer busts, the player wins. If the dealer does not bust, the two hand counts are compared and the highest one wins. If the counts are the same it is a tie.

Your basic program for Part I of the assignment will play the game between a human player and a dealer. It should ask for the name of the player, then have a loop that lets the player keep playing games against the dealer. It should clearly indicate what is happening as the game is played (it must show the initial cards for the human player, it must display the "top" card for the dealer, and each time a player hits it should display the new card and the new point total).

Sample output:

```     Welcome to the Blackjack Casino!
===============================

Please enter the player's name: Bozo

Dealing Bozo's hand...
Cards are 3 of Diamonds and 5 of Hearts
Count is 8

Dealing Dealer's hand...
Top card is 10 of Clubs

Bozo's turn...
Do you want to hit or stick (h or s)? h

New card is 6 of Clubs
Count is 14
Do you want to hit or stick (h or s)? h

New card is Ace of Spades
Count is 15

Do you want to hit or stick (h or s)? h

New card is 4 of Hearts
Count is 19

Do you want to hit or stick (h or s)? s

Dealer's turn...
Bottom card is 4 of Diamonds
Count is 14

Dealer hits...

New card is 3 of Spades
Count is 17

Dealer sticks...

Bozo's count is 19
Dealer's count is 17

Bozo wins!

Play again?

....
```