Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part II: Programming For this assignment, your job is to create a program that plays ( a simplified version of ) blackjack. Name your program

Part II: Programming
For this assignment, your job is to create a program that plays (a simplified version of) blackjack. Name your program blackjack.py.
The Rules
For simplicity, we won't be implementing the full set of blackjack rules, but will get the core of the game working:
A regular deck of 52 cards is used. The cards are every combination of 13 ranks (two, three, four, five, six, seven, eight, nine, ten, jack, queen, king, ace) and 4 suits (spades, clubs, diamonds, hearts). The deck is shuffled (put into a random order) before the game begins.
In our game, each player starts with $1000. At the start of the game, ask how many people wish to play.
Before each turn, each player makes a bet. They can risk any amount of their money on each turn.
Two cards are dealt (given) to each player and placed face-up on the table. The dealer also receives two cards, but one is kept face-down (the hole card). The rest of the cards form the shoe.
The object of the game is to get cards that have value as close as possible to 21 without going over (busting). The cards in a players hand have point values as follows.
Card Rank Value
210 the card's face value (210)
J, Q, K 10
A 1 or 11, whichever is better
Each player gets a turn to take additional cards from the shoe. A player can take another card (hit) as many times as they like. When they stop taking new cards (stand), their turn is over. The cards in the player's hand will not change after their turn is over.
Once the players have taken their turns, the dealer reveals his/her hole card. The dealer also has the chance to hit and stand, but they have a more rigid rule to follow. The dealer must hit (take another card) if their hand contains 16 points or less, and stand (stop taking cards) if they have 17 points or more.
Once all of the cards have been played, each player either wins or loses depending on what is in their hand and the dealer's hand.
Player Busts Player Doesn't Bust
Dealer Busts player loses player wins
Dealer points < Player points player loses player wins
Dealer points == Player points n/a push
Dealer points > Player points n/a player loses
If the player wins, they get their bet back plus an equal amount from the dealer. If they lose, they lose the amount of money they bet.
A push is a tie. In that case, the player takes his/her money back and doesn't win or lose anything. [In true blackjack, there is an additional set of outcomes that occur when either the player or dealer has blackjack: 21 points with two cards. We won't worry about those rules here.]
After the turn is played and the bets are settled, they play continues with another round (go back to step 3).
In a true game of blackjack, players can join or leave the game between hands. We won't worry about that. For this game, all of the players will play three hands, and then the game will stop.
Implementing
To help you along, a cards module has been provided. You'll have to download the cards module. Save this file in the same directory as your blackjack.py file and you should be able to import cards.
You must use Card objects as provided to represent the cards in the deck and players' hands. The deck and hands should be lists of Card objects. There are several functions in the cards module that will help you complete the assignment; they are described in the module documentation.
Several hints have been provided to help you find your way through this assignment. The hints don't say much about breaking your code into functions: deciding how to do that is part of the assignment.
Output
Here is a short sample of what the program should look like when it runs.
How many players are there? 2
Player #1:
You have $1000.
How much do you want to bet? 100
Player #2:
You have $1000.
How much do you want to bet? 200
Hands:
Dealer: **4H
Player #1: 2D JH
Player #2: 9D TS
Player #1
Cards: 2D JH, total: 12
Hit (h) or stand (s)? h
Cards: 2D JH 8H, total: 20
Hit (h) or stand (s)? s
Player #2
Cards: 9D TS, total: 19
Hit (h) or stand (s)? s
Dealer draws 4S.
Dealer's hand: QC 4H 4S, total: 18
Player #1 wins $100.
Player #2 wins $200.
Press enter to continue.
Player #1:
You have $1100.
How much do you want to bet? 100
Player #2:
You have $1200.
How much do you want to bet? 200
Hands:
Dealer: **8D
Player #1: JC 6C
Player #2: 6H KC
Player #1
Cards: JC 6C, total: 16
Hit (h) or stand (s)? s
Player #2
Cards: 6H KC, total: 16
Hit (h) or stand (s)? h
Cards: 6H KC KD, total: 26
Bust!
Dealer draws 5C.
Dealer's hand: 4D 8D 5C, total: 17
Player #1 loses $100.
Player #2 loses $200.
Press enter to continue.
Player #1:
You have $1000.
How much do you want to bet? 500
Player #2:
You have $1000.
How much do you want to bet? 200
Hands:
Dealer: **6S
Player #1: 7S JS
Player #2: 5D 5S
Player #1
Cards: 7S JS, total: 17
Hit (h) or stand (s)? s
Player #2
Cards: 5D 5S, total: 10
Hit (h) or stand (s)? h
Cards: 5D 5S 9H, total: 19
Hit (h) or stand (s)? s
Dealer draws QH.
Dealer's hand: 3C 6S QH, total: 19
Player #1 loses $500.
Player #2 pushes.
Press enter to continue.
Player 1: $500
Player 2: $1000

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

Describe the major social and economic burdens of risk on society.

Answered: 1 week ago