# Lab4_Summer2016_description.html

ECE 2036                                                                                                                    Summer
2016

Lab
3: Vegas Blackjack

Assigned: June 21, 2016                                                                                     Due: July 5, 2016

In this lab we will be writing a text-based computer game
based upon a card game, casino blackjack.

Description
and Rules of Blackjack

You can find many descriptions of blackjack online.  There are several variants of the
game.  The rules we will use are
similar to those used in most American casinos.  Your program must adhere to the rules as
described below.

Your program will have only a single player (the person
running the program) and the dealer, whose actions will be determined by the
program.  The player is playing
against the dealer.  Blackjack is
played in rounds.  The cards held by
the player during a round are called the playerÕs hand.  The playerÕs objective in each round is
to obtain a hand value higher than the dealerÕs hand value, without exceeding
21.  The value of each card is as
follows:

 Card 2 3 4 5 6 7 8 9 10 Jack Queen King Ace Value 2 3 4 5 6 7 8 9 10 10 10 10 11 or 1

(Cards also have ÔsuitsÕ: Spades, Clubs, Hearts, or
Diamonds, but this is irrelevant to this game.)

The hand value is the sum of the card values in the
hand.  For example, if the player
has a hand consisting of a 6 and a Queen, the playerÕs hand value is 16.  An Ace can have a value of 11 or 1,
depending on which value is better for the person holding the hand.  For example, if the player or dealer has
a hand consisting of a 7 and an Ace, the hand value is 18.  However, if the player or dealer has a
hand consisting of a 7, an Ace, and a 6, the hand value is 14, because if the
AceÕs value were 11 the hand value would exceed 21, which is undesirable.

A round of blackjack is played as follows.  Two cards are given (dealt) to the
player and two cards to the dealer.
The player is shown all of the cards in their hand, but only shown one
of the dealerÕs cards.  If the
playerÕs hand value at this point equals 21, the player has blackjack, and the
player automatically wins the round unless the dealer also has blackjack, which
results in a tie (known as a push).
If the player does not have blackjack, the player may choose to ÔhitÕ or
ÔstandÕ.  Choosing to hit means one
card is added to the playerÕs hand.
The player may continue to hit as many times as they wish, as long as
their hand value does not equal or exceed 21.  If the playerÕs hand value exceeds 21,
the player has busted, and automatically loses the round regardless of the
dealerÕs hand.  When the player no
longer wishes to hit, or has a hand value equal to 21, the player stands, which
transfers play to the dealer.

From this point forward, the player is shown all of the
dealerÕs cards.  The dealerÕs hand
is similar to the playerÕs, but the dealer has no choices to make.  If the dealerÕs hand value is 21 with only
two cards, the dealer has blackjack, and the player loses (unless the player
also has blackjack, as described above).
If the dealer does not have blackjack, the dealer must continue to hit
as long as the dealerÕs hand value is less than 17, and must stand if the
dealerÕs hand value is equal to or greater than 17.  The dealerÕs Aces are always taken to
have a value of 11 unless doing so would cause the dealerÕs hand value to exceed
21 (in casino lingo, we require the dealer to stand on a soft 17).  If the dealerÕs hand value exceeds 21,
the dealer has busted, and the player wins unless the player has also busted
(in which case the player loses).

After both player and dealer are done, the hand values are
compared.  The winning hand has the
highest value without exceeding 21.
If the hand values are equal, the player and dealer push (tie).  As described above, a blackjack (a hand
value of 21 with only two cards in the hand) beats any other hand, including a
hand with more than two cards whose value is 21.

The player places a monetary bet before each round of
blackjack.  If the player wins the
round with a blackjack, they receive money equal to 1.5 times their bet.  If the player wins the round with any
hand other than a blackjack, they receive money equal to their bet.  If the player pushes with the dealer, no
money is received or lost.  If the
player loses the round, they lose money equal to their bet.  For this program, the player will start
with 300 dollars, and will be allowed to bet and play rounds until they run out
of money or quit the game.  Quitting
the game will be indicated by the player placing a bet of 0 dollars.  Players should not be allowed to place a
bet larger than the amount of money they have!

We will assume that the hands are dealt from an infinite
deck of cards, so that any card is equally likely to be dealt at any time.  (In the real world, some players use
Ôcard countingÕ and exploit the finite size of the deck to determine the
relative probability of certain cards being dealt.  Casinos often ban players suspected of
doing this.)  When adding a card to
a hand, your program should randomly select a number from 1 to 13, and add the
card corresponding to the number selected.

Extra
credit

1.      5 points of extra credit will be awarded for
correctly implementing Ôdouble downÕ.
Doubling down is a choice a player may make which is similar to asking
for a hit, but with the following conditions:

á      doubling
down can only be done when the playerÕs hand has only two cards (right after
dealing and checking for blackjacks)

á      the
playerÕs bet on the round is doubled

á      a
single card is added to the playerÕs hand and then the player is required to
stand (the player is not allowed to hit more than once after doubling down).

2.      5 points of extra credit will be awarded
for correctly implementing a ÔsplitÕ.
The player may split if they are dealt two cards of the same value.  The player chooses to separate the cards
to effectively have two separate hands, and places an identical bet on the
second hand.  More details on this
may be found online.

You may choose to implement a
more realistic finite-sized card deck from which the hands are dealt.  However, you will not receive extra
credit for doing so.

Detailed
Lab Programming Requirements

Your code must use the classes ÔCardÕ, ÔHandÕ, and
ÔBlackjackÕ described in Card.h, Hand.h
and Blackjack.h files provided by the
instructor.  The instructor will
also provide the main.cpp file.

http://users.ece.gatech.edu/~bk91/2036/Lab4_Summer2016/Card.h

http://users.ece.gatech.edu/~bk91/2036/Lab4_Summer2016/Hand.h

http://users.ece.gatech.edu/~bk91/2036/Lab4_Summer2016/Blackjack.h

http://users.ece.gatech.edu/~bk91/2036/Lab4_Summer2016/main.cpp

of these files.  Your final code
must use all of the above files with no modifications whatsoever, with one
exception: you may make additions to Blackjack.h in
order to accomplish the extra credit tasks, if you choose to do them.  However, you are welcome to modify these
files if desired during the coding and debugging process.  You must write three files:  Card.cpp, Hand.cpp, and Blackjack.cpp,
which will contain all of the member function implementations that youÕve
written.

My suggestion is that you perform tasks in the following
order:

1.     Write
implementations for the Card member functions, and write a small main-card.cpp
file to test this class alone. Do not proceed to step 2 until Card class is
working.

2.     Write
implementations for the Hand member functions, and write a small main-hand.cpp
file to test class Hand and Card.

3.     Finally,
write implementations for the Blackjack member functions.

Sample
output from completed code

bash-3.2\$ ./a.out

Player starts with 300 dollars

Round 1

Enter bet in dollars, 0 to quit: 20

Dealer’s first card is: Queen

Player’s hand is: Six  Jack

Player’s hand value is 16

What would you like to do?  Enter (h)it or (s)tand:
h

Player’s hand is: Six  Jack  Four

Player’s hand value is 20

What would you like to do?  Enter (h)it or (s)tand:
s

Dealer’s hand is: Queen  Five

Dealer’s hand value is 15

Dealer’s hand is: Queen  Five  Queen

Dealer’s hand value is 25

Dealer’s hand is bust.
Player wins!

Player has 320 dollars

Round 2

Enter bet in dollars, 0 to quit: 30

Dealer’s first card is: Eight

Player’s hand is: Six  Ten

Player’s hand value is 16

What would you like to do?  Enter (h)it or (s)tand:
h

Player’s hand is: Six  Ten  Jack

Player’s hand value is 26

Dealer’s hand is: Eight  Four

Dealer’s hand value is 12

Dealer’s hand is: Eight  Four  Jack

Dealer’s hand value is 22

Player’s hand is bust.

Player has 290 dollars

Round 3

Enter bet in dollars, 0 to quit: 300

You don’t have that much money!  Enter a lower bet.

Enter bet in dollars, 0 to quit: 50

Dealer’s first card is: Queen

Player’s hand is: Nine  Ace

Player’s hand value is 20

What would you like to do?  Enter (h)it or (s)tand:
h

Player’s hand is: Nine  Ace  Five

Player’s hand value is 15

What would you like to do?  Enter (h)it or (s)tand:
h

Player’s hand is: Nine  Ace  Five  Seven

Player’s hand value is 22

Dealer’s hand is: Queen  Four

Dealer’s hand value is 14

Dealer’s hand is: Queen  Four  Queen

Dealer’s hand value is 24

Player’s hand is bust.

Player has 240 dollars

Round 4

Enter bet in dollars, 0 to quit: 100

Dealer’s first card is: Six

Player’s hand is: Five  King

Player’s hand value is 15

What would you like to do?  Enter (h)it or (s)tand:
h

Player’s hand is: Five  King  Five

Player’s hand value is 20

What would you like to do?  Enter (h)it or (s)tand:
s

Dealer’s hand is: Six  Six

Dealer’s hand value is 12

Dealer’s hand is: Six  Six  King

Dealer’s hand value is 22

Dealer’s hand is bust.
Player wins!

Player has 340 dollars

Round 5

Enter bet in dollars, 0 to quit: 200

Dealer’s first card is: King

Player’s hand is: Queen  Seven

Player’s hand value is 17

What would you like to do?  Enter (h)it or (s)tand:
s

Dealer’s hand is: King  Queen

Dealer’s hand value is 20

Dealer wins.

Player has 140 dollars

Round 6

Enter bet in dollars, 0 to quit: 100

Dealer’s first card is: Six

Player’s hand is: Five  Eight

Player’s hand value is 13

What would you like to do?  Enter (h)it or (s)tand:

h

Player’s hand is: Five  Eight  Queen

Player’s hand value is 23

Dealer’s hand is: Six  Nine

Dealer’s hand value is 15

Dealer’s hand is: Six  Nine  Four

Dealer’s hand value is 19

Player’s hand is bust.

Player has 40 dollars

Round 7

Enter bet in dollars, 0 to quit: 50

You don’t have that much money!  Enter a lower bet.

Enter bet in dollars, 0 to quit: 20

Dealer’s first card is: Six

Player’s hand is: Four  Two

Player’s hand value is 6

What would you like to do?  Enter (h)it or (s)tand:
h

Player’s hand is: Four  Two  Eight

Player’s hand value is 14

What would you like to do?  Enter (h)it or (s)tand:
h

Player’s hand is: Four  Two  Eight  Queen

Player’s hand value is 24

Dealer’s hand is: Six  Three

Dealer’s hand value is 9

Dealer’s hand is: Six  Three  Four

Dealer’s hand value is 13

Dealer’s hand is: Six  Three  Four  Four

Dealer’s hand value is 17

Player’s hand is bust.

Player has 20 dollars

Round 8

Enter bet in dollars, 0 to quit: 0