
Blackjack Game using objects
What is Blackjack?
Blackjack, also known as twenty-one, is the most widely played casino banking game in the world. Blackjack is a comparing card game between a player and dealer, meaning players compete against the dealer but not against other players. It is played with one or more decks of 52 cards. The objective of the game is to beat the dealer in one of the following ways:
- Get 21 points on the player’s first two cards (called a “blackjack” or “natural”), without a dealer blackjack;
- Get exactly 21 points anytime in the game.
- Reach a final score higher than the dealer without exceeding 21; or
- Let the dealer draw additional cards until his or her hand exceeds 21.
If the play goes over 21, they lose, regardless of the dealers hand.
The strategy the deal employs is to draw another card whenever they have less than 17.
Here is a link to a small web based version of the game: BlackJack
You are to create a program that plays Blackjack with the computer playing the dealer. The game starts with the dealer drawing two cards and showing only the first, and the player draws two cards, and showing them both. The game then enters a cycle with the playercan choose to either “stand” (stay with the current cards) or hit (get another card). The dealer also continues to hit until he either goes bust (over 21) or stands (when he hit 17 or above). The goal is to either get 21 exactly, or to be the closest to 21 without going over (and thus bust). If the scores are the same, there is a tie, called a “push”.
The scoring of card values is as follows. Number cards are worth their face value. Face cards are worth 10. And the ace is either worth 1 or 11, whichever is omre favorable.
You goal is to create a game that plays until someone wins or loses, and then asks if the player wants to play again. Below is some starting code:
https://repl.it/@JimSkon/BlackjackStart
You must finish the following classes:
class card:
def __init__(self,suit,rank):
"Setup a card given the suit and rank"
def cardInfo(self):
" return a string of the card suit and rank"
class deck:
def __init__(self):
"Create a new deck of 52 cards"
def shuffle(self):
"Shuffle the deck into random order"
def draw(self):
"draw a card, removing it from the deck and returning it"
class hand:
def __init__(self,owner="Player"):
"create a hand, default to Player"
def add(self,card):
"Add a card to the hand"
def showFirst(self):
"Print out the first card in the hand"
def cardList(self):
"Print ou a list of cards in hand"
def showHand(self):
"""
Print the player (Player or Dealer)
followed by a card list
followed by the tally
"""
def tally(self):
"total the value of the cards in this hand"
Sample Output
dealing new cards Dealer shows one card: 8 of Spades♠ Your hand: Queen of Clubs♣ 8 of Clubs♣ Your tally: 18 [H]it [S]tand:s It's a draw, you both have 18 Dealer hand: 8 of Spades♠ King of Diamonds♦ Wins: 0 Losses: 0 Draws: 1 Hit [Q]uit or [C]ontinue:c dealing new cards Dealer shows one card: 6 of Hearts♥ Your hand: Queen of Clubs♣ 7 of Hearts♥ Your tally: 17 [H]it [S]tand:s Dealer draws a card. It's a draw, you both have 17 Dealer hand: 6 of Hearts♥ Ace of Spades♠ Queen of Spades♠ Wins: 0 Losses: 0 Draws: 2 Hit [Q]uit or [C]ontinue:c dealing new cards You lose, 14 is beat by 21 Dealer hand: Ace of Diamonds♦ Jack of Clubs♣ Wins: 0 Losses: 1 Draws: 2 Hit [Q]uit or [C]ontinue:c dealing new cards Dealer shows one card: Ace of Hearts♥ Your hand: 7 of Clubs♣ Ace of Spades♠ dealing new cards Dealer shows one card: Jack of Spades♠ dealing new cards Dealer shows one card: 8 of Clubs♣ Your hand: 6 of Diamonds♦ 4 of Diamonds♦ Your tally: 10 [H]it [S]tand:h You Draw: 5 of Hearts♥ Dealer shows one card: 8 of Clubs♣ Your hand: 6 of Diamonds♦ 4 of Diamonds♦ 5 of Hearts♥ Your tally: 15 [H]it [S]tand:s You lose, 15 is beat by 18 Your hand: 6 of Diamonds♦ 4 of Diamonds♦ 5 of Hearts♥ Dealer hand: 8 of Clubs♣ Jack of Diamonds♦ Wins: 0 Losses: 1 Draws: 0 Hit [Q]uit or [C]ontinue:c dealing new cards Dealer shows one card: Jack of Hearts♥ Your hand: King of Hearts♥ 8 of Hearts♥ Your tally: 18 [H]it [S]tand:s It's a draw, you both have 18 Your hand: King of Hearts♥ 8 of Hearts♥ Dealer hand: Jack of Hearts♥ 8 of Diamonds♦ Wins: 0 Losses: 1 Draws: 1 Hit [Q]uit or [C]ontinue:c dealing new cards Dealer shows one card: 2 of Spades♠ Your hand: Jack of Diamonds♦ 2 of Clubs♣ Your tally: 12 [H]it [S]tand:h You Draw: 5 of Spades♠ Dealer draws a card. Dealer shows one card: 2 of Spades♠ Your hand: Jack of Diamonds♦ 2 of Clubs♣ 5 of Spades♠ Your tally: 17 [H]it [S]tand:s Dealer draws a card. Dealer goes bust: 26 You win! Your hand: Jack of Diamonds♦ 2 of Clubs♣ 5 of Spades♠ Dealer hand: 2 of Spades♠ 5 of Clubs♣ 9 of Spades♠ King of Diamonds♦ Wins: 1 Losses: 1 Draws: 1 Hit [Q]uit or [C]ontinue:c dealing new cards Dealer shows one card: King of Clubs♣ Your hand: Ace of Clubs♣ 7 of Diamonds♦ Your tally: 18 [H]it [S]tand:s You lose, 18 is beat by 20 Your hand: Ace of Clubs♣ 7 of Diamonds♦ Dealer hand: King of Clubs♣ 10 of Clubs♣ Wins: 1 Losses: 2 Draws: 1 Hit [Q]uit or [C]ontinue:c dealing new cards Blackjack!! You win! You win, 21 beats 17 Your hand: Ace of Hearts♥ Queen of Clubs♣ Dealer hand: 7 of Spades♠ King of Spades♠ Wins: 2 Losses: 2 Draws: 1 Hit [Q]uit or [C]ontinue:q
Your function should include calls to input to get the user’s guess.
Grading
| Requirement | Points | Comments | Score |
|---|---|---|---|
| Meets all requirements | 70 | ||
| Code is broken up into functions, with one specific task per function | 10 | ||
| Each function is commented at top of function, after the function name | 10 | ||
| Program has meaningful comments, good variable names, and good formatting | 10 | ||
| Total |
