Question
Python: Create a Game of Blackjack BlackjackHand First we will create a class for storing our hand in blackjack, so we can easily figure out
Python: Create a Game of Blackjack
BlackjackHand
First we will create a class for storing our hand in blackjack, so we can easily figure out how much our hand is worth, or display it to the screen.
__init__()
A BlackjackHand doesnt take in any parameters, but it will need to set up a list for storing Cards.
add_card(new_card)
Adds a card to the hand.
parameters
new_card - the Card object to be added to the hand
__str__()
Returns a string representation of the current hand. The resulting string should contain the __str__() value of each card, delimited by commas.
return
A string representing all the cards in the hand. Example: 7 of Diamonds, King of Spades or Ace of Hearts, 8 of Clubs, Queen of Diamonds
get_value()
Returns a numeric point value of the current hand. This should be the sum of the point values of each card. In our implementation of blackjack, an Ace should be either 11 points, or 1, to give the player the highest score without exceeding 21. Hint: First count the total points assuming all aces are 11, along with the number of aces, then decrement point total as the rules allow.
return
A numeric value representing the value of the hand. Examples, respective to the examples in hand_str, above: 17 or 19.
Blackjack
The Blackjack class is designed to represent a game of blackjack. This object can be thought of as a blackjack table, in which a series of hands are dealt from one or more decks of cards. Read through all the methods before you start! Below are specifications for the methods and instance variables that should be implemented in the Blackjack class:
bank
A instance variable should store the users ChipBank. This instance variable will be created durring __init__()
__init__(starting_dollars)
Creates a new Blackjack games in which the player starts with starting_dollars worth of money. This method will need to set up instance variables to support the rest of the game. This should initialize the deck, and the players chip stack. Remember to shuffle the deck after you create it.
parameters
starting_dollars - Initial amount of money the player has to wager with. Example: 250
draw()
This method draws and returns a card from the deck. If the deck is empty when this method is called, rebuild and reshuffle the deck. Make sure that all cards are drawn face up. Return a card object after it is removed from the deck.
return
A Card object removed from the deck.
start_hand(wager)
Starts a new hand of blackjack. Should initialize instance variables with a new hand for the player and the dealer. Remember that the first dealers card should be set face down. This object should withdraw the wager amount from the ChipBank, and remember that value for the end of the game. Print both the players hand and the dealers hand to the player, and check to see if the player wins automatically with blackjack. If both the player AND the dealer have 21, it is a tie, or push.
parameters
wager - Numeric value representing the bet placed on the hand. Example: 5
hit()
The player choses to hit. Draw a card for the player, and display the players new hand. If they exceed 21 they bust, and if they get 21 exactly they are forced to stand. This method takes no parameters, and has no return value.
stand()
The player stands, and the dealer flips their hidden card face up and begins the process of drawing. The dealer only draws if their hands current value is 16 or less. If the dealer draws over 21, they bust and the player wins. After the dealer is done drawing, and neither has busted, the higher valued hand wins. Ties can occur, and are called pushes. This method has no parameters and no return value.
end_hand(outcome)
This method should be called when a winner has been determined. This method is passed a parameter outcome, which will be win, lose, or push depending on if the player won, the dealer won, or their was a tie. If the player wins they should be given double their wager back. A push should refund the original wager, and a lose should result in no money being deposited. This method is also responsible for setting the two hands and the wager back to None. This method should be called by any of the other methods in which a winner is found.
parameters
outcome - A string containing either win, lose, or push.
game_active()
Returns True or False, indicating if there is a current hand in play. Should return True when start_hand() has been called, and end_hand() has not yet been called to close the game.
return
Returns a boolean value, True or False, depending on if there is an active hand that has not yet been resolved.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started