Question: Problem 1 : Simulating Blackjack In this problem we will use classes and functions to simulate a simplified game of Blackjack ( 2 1 )
Problem : Simulating Blackjack
In this problem we will use classes and functions to simulate a simplified game of Blackjack The game
begins with a standard deck of playing cards no jokers Each player is dealt two cards to start with. The
winner of a hand of Blackjack is the player whose hand has the highest value without going over
When calculating the value of a hand, we add up the rank of each card in the player's hand, where the numbered
cards have ranks through The face cards, Jack, King, and Queen, each add to the value of a player's
hand. The Ace card can be treated as adding either or to the value of the player's hand, depending upon
which brings the player closer to without going over
Player's may request an additional card a "hit" on their turn in order to bring the value of their hand closer to
However, if the value of a player's hand rises above then the player has "busted" and they automatically
lose the game.
In our simulation we are ignoring the distinction between player and dealer. We are also ignoring betting, and
so all the more sophisticated player actions such as "splitting", etc. are also being ignored. The behavior of
players is going to be fixed by a simple algorithm. Details for writing the simulation program are given below.
The program will consist of classes: Card, Deck, Player, Blackjack. Each class represents objects that are
elements of a simulated game of Blackjack. To implement each class, you will have to complete the
implementation of the functions inside the body of the class definition. The names of the classes, the functions,
and the function parameters have already been given. DO NOT CHANGE THEM.
The Card Class:
The Card class is meant to represent a single playing card. It has two attributes, suit and rank.
Playing cards come in one of four suits: Hearts, Diamonds, Spades, and Clubs. In your program, each
suit is represented by a string of a single capital letter: H for Hearts, D for Diamonds, S for
Spades, and C for Clubs. I have included a list of the suits assigned to a global variable in your
program. The variables name is suits.
For each suit there is a Card of one of ranks. Each rank is represented by a string: through
for the ranks of the numbered cards, and JQK and A for the Jack, Queen, King, and Ace face
cards. I have also included a list of the ranks assigned to a global variable in your program. The name
of the variable is ranks.
When a Card object is constructed the values for suit and rank should be assigned to the suit and rank attributes
of the Card class. You must implement this in the init function. You should check that the values
passed to the Card constructor represent possible suit and rank values.
The Deck Class:
The Deck class represents a standard deck of playing cards. The Deck class should have a single attribute
called cards. cards will be a list of Card objects, one for each playing card that makes up a standard deck.
In the init function of the Deck class you should create and add a Card object for each of the
cards that make up a standard playing card deck. That is for each suit there should be a Card of each rank
added to the cards list attribute in the Deck class.
In addition to the init method, you must also implement a dealcard function. This function
takes a single argument, an object of the Player class. Inside the function you should remove the card from the
top of the Deck pop it from the cards list of the Deck and then add that Card to the hand attribute inside the
Player object.
I have provided you with a function shuffledeck that will randomize the order of the cards inside the
cards list inside the Deck object. The function takes a single positive integer that represents how many times
the deck will be shuffled. The default value is DO NOT CHANGE THIS FUNCTION.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
