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..
Presiding Officer Training module 2024 lok sabha elections
CPSC 120Second Project—Blackjack gamedue November 15th, 20.docx
1. 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
2. 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:
3. 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
4. (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
5. 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
6. 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
7. 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
The legal concept of property is limited to tangible physical
objects.
Select one:
True
False
Most courts consider an engagement ring to be a conditional
gift
Select one:
True
False
A negotiable warehouse receipt states that the goods received
will be delivered to the bearer or to the order of any named
8. person.
Select one:
True
False
A person who attends a banquet given at a hotel is considered a
guest for purposes of determining the liability of the
hotelkeeper.
Select one:
True
False
If a contract calls for both rendering services and supplying
materials to be used in performing the services, the contract is
classified according to its dominant element.
Select one:
True
False
The provisions of Article 6 concerning bulk transfers are
designed to protect creditors.
Select one:
True
False
Consumer protection statutes may require a writing that is more
detailed than the writing required by the statute of frauds
provision of the Uniform Commercial Code.
Select one:
True
False
Title to goods can be transferred without the actual delivery of
the goods involved.
Select one:
True
False
An express guarantee is governed by the UCC, and warranties
are governed primarily by the common law of contracts.
Select one:
True
9. False
If the party on whom demand for assurance of performance is
made has an established reputation, a reaffirmation of the
contract obligation and a statement that it will be performed
may be sufficient to assure a reasonable person that it will be
performed.
Select one:
True
False
Public policy exceptions to the employment-at-will doctrine
apply only to "whistleblowing" situations.
Select one:
True
False
A bank is required to pay a check presented more than six
months after its date.
Select one:
True
False
A person who obtains life insurance generally can name anyone
as beneficiary, regardless of whether that beneficiary has an
insurable interest in the life of the insured.
Select one:
True
False
A restrictive endorsement specifies the purpose of the
endorsement or the use to be made of the paper.
Select one:
True
False
A person becomes a(n) __________ at the moment of taking
possession of abandoned personal property.
Select one:
a. constructive bailee
b. owner
c. bailor
10. d. bailee
Joan brought her car into Ace Service Station for a tune-up.
After tuning up the car, Ace (the owner of the service station)
decided to visit his mother. Ace drove Joan's car. Ace was
following all safety precautions when a negligent driver without
insurance struck Joan's car. Joan sued Ace for the damages to
her car. The probable result is:
Select one:
a. Joan will win, since the harm was sustained during the
bailee’s unauthorized use of the property.
b. Ace will win, since he was taking reasonable care of the
bailed goods.
c. Joan will win, since bailees are absolutely liable for bailed
goods in their possession and control.
d. Ace will win, since the bailee has the right to use the bailed
goods.
Jeff purchased in good faith a warehouse receipt for 1,000 pairs
of running shoes without notice of any defense to it, for value,
and in the regular course of his business. Unknown to Jeff, the
goods had been stolen from Jane and delivered to the warehouse
that issued the receipt purchased by Jeff. Which of the
following statements is true?
Select one:
a. Jane cannot recover the goods but can sue the warehouse for
conversion.
b. Jeff holds a duly negotiated document of title and is not
subject to Jane's title.
c. Jeff is not a holder of a duly negotiated document.
d. Jane is entitled to the goods and will prevail over Jeff.
The relationship of guest and hotelkeeper ends:
Select one:
a. when the guest's bill is paid.
b. when the guest leaves or ceases to be a transient.
c. when the guest asks to take on the more permanent status of
boarder.
d. when the guest advises the hotelkeeper that the guest is
11. leaving.
Which of the following is not a sale of goods?
Select one:
a. a bailment
b. all of the above
c. a gift
d. an option to purchase
An agreement to periodically deliver home-heating oil to a
residential customer that does not indicate the duration of the
contract
Select one:
a. constitutes a bulk transfer.
b. is enforceable for a reasonable period of time.
c. lasts for one delivery only.
d. is not a legally-enforceable contract.
In a consignment, the dealer-consignee is often referred to as
a(n):
Select one:
a. remainder.
b. exponent.
c. quotient.
d. factor.
Unless otherwise agreed, the proper place for the delivery of
goods is:
Select one:
a. the seller's home.
b. a delivery service selected by the seller.
c. the seller's place of business.
d. the buyer's place of business.
A depositor issued a check and, after mailing the check,
suffered a heart attack and died. In the regular course of
business, the bank paid the check when presented for payment,
despite the fact that the bank had received notice fourteen (14)
days earlier of the depositor's death. In terms of the bank’s
payment of the check
Select one:
12. a. the bank is not liable unless the depositor's executor posted
an indemnity bond.
b. the bank’s authority to act for the depositor ended on the
depositor's death, regardless of whether the bank had been
notified of the depositor’s death.
c. the bank is potentially liable to the depositor’s estate.
d. the bank is liable if the check was a gift to charity.
What is a correct statement concerning burden of proof?
Select one:
a. The insured has the burden of proving that the loss was a
covered loss.
b. Exceptions to coverage are liberally interpreted in favor of
the insurer.
c. The insurer has the burden of proving that the loss was not
covered.
d. Exceptions to coverage are disregarded in life insurance
matters.
A security agreement must:
Select one:
a. all of the above.
b. contain a reasonable description of the collateral.
c. identify the parties involved.
d. demonstrate that the creditor intends to have a security
interest.
If the collateral is in the possession of the creditor:
Select one:
a. the type of goods will determine the method of perfection.
b. a financing statement must be filed to perfect the interest.
c. the security interest is perfected.
d. only a security interest has been obtained.
The term apparent authority is used when there is:
Select one:
a. actual authority.
b. no interaction between the principal and third persons.
c. only the appearance of authority and that appearance of
authority was created by the agent.
13. d. only the appearance of authority and that appearance of
authority was created by the principal.
An agent is under a duty to obey:
Select one:
a. all instructions given by the principal.
b. all lawful instructions given by the principal.
c. none of the above, since “obedience” is not an obligation of
the agent.
d. all instruction given by the third party.
An agreement under which one party agrees to pay drafts drawn
by a creditor is called a:
Select one:
a. debtor's agreement.
b. contract of surety.
c. guaranty contract.
d. letter of credit.
If the issuer of a letter of credit dishonors a draft without
justification, it is liable to its customer for:
Select one:
a. monetary malfeasance.
b. fiduciary peril.
c. fiduciary default.
d. breach of contract.
The relationship of guest and hotelkeeper ends:
Select one:
a. when the guest's bill is paid.
b. when the guest asks to take on the more permanent status of
boarder.
c. when the guest advises the hotelkeeper that the guest is
leaving.
d. when the guest leaves or ceases to be a transient.
A common carrier transporting goods under a COD shipment
may
Select one:
a. not avoid liability without a signed release.
b. make delivery without first obtaining payment.
14. c. not make delivery without first receiving payment.
d. accept a check as payment and have no liability.
Short Answer
1. Humberto called his friend John and asked him to come over
immediately because Humberto had suffered a stroke and might
be dying. In their telephone conversation, Humberto advised
John that he wanted to give John his gold watch. Immediately
after their telephone conversation, Humberto wrote out a will
that left his share in Blackacre to John. Blackacre was the
marital home of Humberto and Connie, who owned the home as
tenants by the entirety. Humberto died before John arrived at
Blackacre. John claims the watch and a share in the home.
Connie contests both matters. Decide.
2. Bob Brown entered the Hotel Lux to attend a conference
being held within the hotel. Sam Smith had arrived to attend the
same conference, had registered at the front desk, and had
obtained a room. Sally Jones also intended to participate in the
conference and was in essence living at the hotel at the time.
What relationship exists between the hotel and each of these
individuals? What can be said of the hotel's obligations to each
individual under these circumstances?
3. Gonzalez Manufacturing negotiated by telephone to purchase
approximately $7,000 worth of digital video recorders from
Video Imports. The final details were worked out by telephone
calls on April 2nd. On April 4th, Video sent Gonzalez a
confirmation of their telephone agreement, which included
pertinent details. Meanwhile, on April 3rd, Gonzalez was
offered a better deal than Video's and accepted it. Upon arrival
of the confirmation on April 6th, Gonzalez ignored it and did
nothing further until May 1st, the date before Video was to
deliver. On May 1st, Gonzalez informed Video that their
contract was an unenforceable oral contract and that delivery
15. would not be accepted.
When attempts to amicably settle the matter failed, Video sued
Gonzalez for breach of contract. Decide.
4. Bob Corporation entered into a contract to sell parts to Zeck.
The contract provided that the goods would be shipped "FOB
Bob's warehouse." Bob shipped parts to Zeck that were stolen
from the carrier. When Zeck checked the invoice, Zeck
discovered that Bob had sent Model #20B instead of Model
#20A, which the contract required. Whose loss? Why?
5. Samuel signed a contract to purchase furniture on credit. The
contract clearly set forth in bold print all charges included in
the cost of the credit, including the interest rate and annual
percentage rate. The seller informed Samuel that the seller
regularly sold these contracts to a finance company that paid it
immediate cash and then collected from the debtors. The seller
further advised that the finance company did not want "the
headache" of determining the validity of consumer complaints
and that therefore the contract provided that the consumer
waived all defenses concerning the furniture against the finance
company. The contract expressly provided that the seller would
remain responsible for any non-conformities in the furniture or
breaches of contract on its part. The furniture was defective, but
the finance company is demanding that Samuel make the
payments to it required by the contract and resolve its disputes
with the seller of the furniture. Samuel consults you regarding
his rights. What is your response?
16. 6. Mark purchased a very expensive automobile on credit.
Within a week, Mark discovered that a tune-up was necessary,
for he was in the habit of driving at an excessive rate of speed.
When the car was repaired, the bill was more than $1,000. Mark
does not have the money to pay for the car repairs or the
monthly car payments. The credit company as well as the repair
shop are concerned over who has priority of repayment. Who
has priority and why?