Hi my project in the PDF file.
thanks in advance
CPSC 120::Second Project—Blackjack game
due November 15th, 2013
Background:
Blackjack (also known as 21 in Las Vegas), is a very popular card game. Each player plays directly against the
dealer, and is dealt two cards, which only the player can see. The dealer is also dealt two cards, but one card is
face up, and the other is face down (the dealer’s “hole” card).
Placing your bet
Before each deal, before he receives any cards, the player is asked to place a bet in advance. Typically, the
player can make bets in increments of $5 ($5, $10, $15, up to a maximum bet of $500) per deal. Of course, the
player cannot bet more money than he has (unless he has credit—for this game, we will assume that you have no
credit – cash only.)
Object of the game
The object of the game is to get closer to 21 than the dealer. Note that word: “closer”. If you have the same
score as the dealer, the player does not win that hand. This is called a “push”, and the bet is pushed into the next
hand.
What if the player’s two cards are not very close to 21? Then the player may take additional cards (telling the
dealer to “hit me”), one card at a time. If the player goes over 21, then the player loses his bet immediately.
But if not, at any time, the player may decide to STAND (take no additional cards). Note: the player can
continue taking cards even if his score is almost 21. For example, the player can take another card even if his
score is 20 (not advisable, perhaps, but allowed).
If the dealer’s cards add up to less than 17, then the dealer must continue turning over cards until his score is
greater than or equal to 17. Note: the dealer cannot stand before his score is 17.
Winning the hand
There are several possibilities then:
(1) Either the dealer or the player BUSTS (goes over 21), and they lose.
(2) The player is closer to 21 than the dealer, and the player wins their bet.
(3) The dealer is closer to 21 than the player, and the player loses their bet.
(4) There is a tie, in which case the bet is PUSHED to the next deal.
Additional complications
In real Blackjack, there are additional possibilities (you do NOT have to implement these in this project)
• if the player has a pair of cards, he can split the cards into two bets, and place an additional bet
• if the player looks at his cards and the dealer’s up card after the cards have been dealt, and feels he has a
good chance of winning, he can double his bet
• if the player or the dealer has Blackjack (an Ace and a black Jack), he will beat any other combination
except another Blackjack, and will win 1.5x his original bet.
Task:
Your task is to write a program that plays Blackjack, with the human being the player, and the computer being
the dealer. In this game, there will only be one player (not like Vegas where there might be 5 to 7 players sitting
at a table.) The cards should be dealt out slowly, one card every 0.5 to 1.0 seconds, to make the game more
interesting.
CPSC 120::Second project: Blackjack game due Friday, Nov 15th at midnight
Dr. Will McCarthy page 1 of 3
The player starts with $200 worth of chips. The player must bet before his cards are dealt to him. Bets are in
increments of $5, up to a maximum amount of either the amount the player has, or $500, whichever is less.
After each bet, the program deals two cards to the player, and two to the dealer (one of the dealer’s cards is face
down). The player is asked if he wishes to stand (take no additional cards), or hit (take an additional card).
If he hits, he takes another card, and has another chance to hit or stand. This continues until the player decides to
take no additional cards for the current deal, or busts (goes over 21). Then, the dealer then turns up his hole
card, and must take additional cards until he has at least 18, or busts (goes over 21).
If the player goes over 21, he loses his bet. If he stands, but the dealer goes over, the player wins his bet.
Otherwise: (1) if the player’s cards are closer to 21, he wins the bet, OR (2) the dealer’s cards are closer to 21,
and the player loses the bet, OR it’s a tie, and the bet is pushed to the next deal. The game continues, with
additional bets being placed, until the player loses all his money (is busted), or decides to quit the game.
As per our lab, the cards are scored as follows: 2-10 have the same value as the card, J, Q, and K have value 10,
and Ace has value 1 or 11, whichever helps more to win. (We have already written a program to score Blackjack
hands in lab, so part of this project is already done. You will have to add several features to your skillset before
you can complete this project.
You will have to generate random numbers using rand() and srand(), and you will need to use sleep() or
usleep() or just have the computer count up to a large number using a simple for loop: for (int i = 0; i <
500000; i++) { }. We will work with these functions in your next lab, and get more practice at working with
arrays (of chars, which will represent the cards in our game). For rand() and srand(), see section 4.2, (especially
see pp. 185-87), (Predefined functions) in your textbook. We will go over sleep() and usleep() in this Saturday's
(2 Nov 2013) lab.
In this game, you can assume you have an unlimited number of cards (in Vegas, they usually use a 6-8 deck
shoe, where they have 6*52 or 8*52 cards in the shoe they use to deal from). You don’t have to make your
program try to keep track of this detail. See example output at the bottom of this page…
Due date:
This project is due in two weeks, on Friday, November 15th, 2013, at midnight. It involves designing,
implementing, and testing a substantial program for the subset of C++ that we are studying in this course, from
start to finish. Your submission will be a written project report, including your C++ source code and
output, submitted electronically to TITANium as a single PDF file. Note: You may work in pairs on this
project. Should you work with a partner, please turn in one report with both names.
Example Output:
Welcome to Blackjack! We hope you feel lucky tonight! (Note: push means no one wins that round.)
PLAYER DEALER WINNER CHIPS BET
player: 8 2 8 = 18 dealer: 6 9 7 = 22 PLAYER wins …now has $ 225 Bet: $: 25
player: 2 A A 6 = 20 dealer: 2 6 7 7 = 22 PLAYER wins …now has $ 250 Bet: $: 100
player: 8 J = 18 dealer: 8 8 4 = 20 dealer wins player has $ 150 Bet: $: 50
player: 4 2 6 A Q = 23 dealer: 9 6 4 = 19 dealer wins player has $ 100 Bet: $: 50
player: 7 Q = 17 dealer: 2 6 9 = 17 push——- —————- ———–
player: Q Q = 20 dealer: A 9 = 20 push——- —————- ———–
player: 6 Q = 16 dealer: A 3 2 4 = 20 dealer wins player has $ 50 Bet: $: 25
player: 8 Q = 18 dealer: Q 4 9 = 23 PLAYER wins …now has $ 75 Bet: $: 25
player: 5 5 2 Q = 22 dealer: J 6 A = 17 dealer wins player has $ 50 Bet: $: 25
player: 9 9 = 18 dealer: 3 2 3 Q = 18 push——- —————- ———–
player: A 4 10 9 = 24 dealer: 8 2 Q = 20 dealer wins player has $ 25 Bet: $: 25
player: A A J 8 = 20 dealer: 7 2 Q = 19 PLAYER wins …now has $ 50 Bet: $: 25
player: 8 8 = 16 dealer: Q 4 10 = 24 PLAYER wins …now has $ 75 Bet: $: 75
player:10 6 = 16 dealer: 8 A = 19 dealer wins player has $ 0 BUSTED.
Thank you, play again.
…done.
CPSC 120::Second project: Blackjack game due Friday, Nov 15th at midnight
Dr. Will McCarthy page 2 of 3
Important! The following types of submissions are impermissible, and will receive a score of zero.
✗ Late submissions
✗ Email submissions
✗ Source code that will not compile without errors
✗ Falsified input/output or that doesn’t match the source code.
✗ Submissions that are plagiarized or that violate the below collaboration guidelines.
Late submissions: No late homework, labs, or project assignments will be accepted under any circumstances
(score of 0). Don’t be late.
When working in labs or when working on projects, you will work in a collaborative environment, optionally
with one partner. Partners may work together freely. Each group should complete their own work themselves,
with very limited help from other individuals or sources. The following guidelines apply to collaboration with
any person or resource _other than your partner_.
• You should be able to explain any part of your submission, and be able to explain why you wrote what
you did. If working in a group, each member of the group should be able to explain any part of the
submission, and not just be able to explain “his or her” subset.
• You may help each other understand the assignment and brainstorm general solutions, but must separate
to develop your own detailed solution to the problem, and must individually type in your source code
and project report.
• You may, of course, give each other technical support, for instance troubleshooting installing
Visual Studio or logging into TITANium.
• You can share documented facts, such as the return value of a particular library function.
Given these requirements, any submissions with identical excerpts, or excerpts that are identical up to superficial
rearrangements, will be considered highly suspect of plagiarism.
CPSC 120::Second project: Blackjack game due Friday, Nov 15th at midnight
Dr. Will McCarthy page 3 of 3