Question: Please help with this python coding. Scenario Youve just been hired by a small-town casino that wants to create a simulated card playing platform. To
Please help with this python coding.
Scenario
Youve just been hired by a small-town casino that wants to create a simulated card playing platform. To get you warmed up, they want you to be able to create a blackjack game simulator.





![numbers = set([i for i in range(2,15)]) a = 551 seed(a) def](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66fa34bc99cd5_53266fa34bc1c736.jpg)




from itertools import product
from random import choice, seed
from os import linesep
suits = {'hearts', 'clubs', 'spades', 'diamonds'}
numbers = set([i for i in range(2,15)])
a = 551
seed(a)
def create_standard_deck():
pass
def get_all_cards(deck):
pass
def get_all_twos(deck):
pass
def get_all_aces(deck):
pass
def get_card_number(deck, card_number):
pass
def get_card_suit(deck, suit):
pass
def get_number_and_suit(deck, num, suit):
pass
def remove_card_from_deck(deck, suit, num):
pass
def remove_suit_from_deck(deck, suit):
pass
def remove_number_from_deck(deck, number):
pass
def add_card_to_deck(deck, suit, num):
pass
def add_suit_to_deck(deck, suit):
pass
def add_number_to_deck(deck, number):
pass
def draw_card(deck):
# replace this with your implementation
pass
def display_dealer(opponent, start=False):
print('Dealer:')
if start:
the_output = [opponent[0], ('?', '?')]
print(the_output)
else:
print(opponent)
def display_player(player):
print('Player:')
print(player)
def get_count(player):
# replace this with your implementation
return 0
def check_cards(player):
# replace this with your implementation
pass
def create_blackjack_game(user_input):
# FIRST SECTION INSERT YOUR CODE HERE
# REPLACE WITH YOUR CODE
if not user_input:
player_action = input('press h to hit, s to stand, q to quit.').lower().strip(linesep)
while player_action not in ('s', 'h', 'q'):
player_action = input('press h to hit, s to stand, q to quit.').lower().strip(linesep)
else:
player_action = user_input.pop(0)
if player_action == 'q':
return 0
while player_action != 'q':
if player_action == 'h':
pass
# SECOND SECTION INSERT YOUR CODE HERE
# REPLACE WITH YOUR CODE
else:
while True:
# THIRD SECTION INSERT YOUR CODE HERE
# REPLACE WITH YOUR CODE
pass
if not user_input:
player_action = input('press h to hit, s to stand, q to quit.').lower().strip(linesep)
while player_action not in ('s', 'h', 'q'):
player_action = input('press h to hit, s to stand, q to quit.').lower().strip(linesep)
if player_action == 'q':
return 0
else:
player_action = user_input.pop(0)
What you need to know The game logic needs to follow this pattern: 1. Create a deck. 2. Give each player two cards (chosen randomly using random.choice). 3. Display both hands 4. Prompt the player to either hit (that is, draw another card) or stay. 5. If the player hits, keep checking whether the total value of the player's cards is equal to 21. If it is, then the player wins, and if it is above 21, then the player loses. Display each updated hand after each card draw. 6. If the player stays, then it's the dealer's turn to act. If the total value in the dealer's hand is less than 17, then they must hit. If it is greater than or equal to 17 but less than or equal to 21, then the dealer must stay. If at any time the dealer's total value is above 21, then the dealer busts and the player wins. 7. Finally, if both the player and dealer scores are below 21, and no one has busted yet, the player with the highest total wins. In the case of a tie, the dealer wins. What you need to do, part 1 Best Practices to Follow: It's worth breaking up each functional task in create_blackjack_game() into separate functions. For example, a function to check the score of a player's hand, to check whether a player has won, and so on. This entire implementation can be done neatly in about eight functions. Create a Deck of Cards Complete the create_standard_deck() function, which creates a new deck. The deck itself must be a data structure list. The cards within the deck must be represented as tuples of the form (suit, number), where the suit is a string that must be either 'hearts', 'clubs', 'spades', or 'diamonds, and the number is an integer that must be one of the following: 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, or 14. Note that the number used to identify the card has the following association: Jack = 11, Queen = 12, King = 13, and Ace = 14. In terms of value, the picture cards (Jack, Queen, and King) all have a value of 10, and the Ace card has a value of 11. The casino only wants you to implement a simple implementation of blackjack, in that the first to 21 wins, and special cases for checking for blackjack are not required. The deck should be sorted in alphabetical order of the suit, and then by an ascending integer identifier; for example: [['clubs', 2), ('clubs', 3), ..., ('diamonds', 2), ..., ('diamonds', 14), ('hearts', 2), ... , ('Spades', 14)]. Task Implement the create_deck() function to create the deck of cards. Drawing a Card from a Deck Your task is to complete the function stub draw_card(deck). The function takes a deck as the input. The function should randomly select a card from the deck using the random.choice() method and then remove the card from the deck by completing the remove_card_from_the_deck() function. Once this is done, the function needs to return the card that was selected. Task > Implement the draw_card() function which deals cards to the dealer and players and removes the corresponding card from the deck. Getting the Count of the Cards in a Player's Hands Your task is to complete the function stub get_count(player). The function takes a player's hand, which is a list, as input. The function calculates and returns the value of the player's hand. It should be noted that a special mapping is required. Currently, in the deck, Jack has a value of 11, Queen has a value of 12, King has a value of 13, and Ace has a value of 14. You need to ensure that the Jack, Queen, and King cards all have a value of 10. Finally, for the purposes of this implementation, we will only treat the Ace with a value of 11. Task > Implement the 'get_count function to calculate the value of cards in a player's Checking whether a Player has Won Your task is to complete the function stub check_cards (player). The function takes a player's hand as input and returns WIN' if the input player has exactly a count of 21. If they have a count that is greater than 21, then it returns 'BUST"; otherwise, it returns 'OK'. Task > Implement the check_cards() function to check if the player has won, lost, or has room to hit. What you need to do, part 2 Putting it All Together Your task is to now combine everything together to create the blackjack game that is defined in the create_blackjack_game(user_input) function. In the first part of this task, you will implement the section marked with # FIRST SECTION INSERT YOUR CODE HERE . For this first section, you should do the following: Create a list for the player called 'player", which will hold the cards in the player's hand, and then create another list for the dealer called 'dealer", which will hold the cards in the dealer's hand. Create a new deck of cards using the create_standard_deck() function. Draw two cards for each player and add them to the respective player's hands. Create two variables, one for each player, that stores the count of the player's hands. The cards will be displayed using the display_player (player) function and the display_dealer (opponent, start=true) function. These functions have been written already, but will need to be placed correctly. You then need to implement the second section marked with # SECOND SECTION INSERT YOUR CODE HERE . For this second section, you should do the following: Implement the logic for the player. The code has already been provided that prompts the user for an action and stores this in player_action. If the user action is q, then the game quits. You need to implement the part where the user provides an h, which stands for 'hit' (that is, for drawing a card), and s, which stands for 'stay" (that is, to stop drawing cards). After each card is drawn, the player's hand needs to be checked to see whether they have won, they are bust, or whether everything is okay. You will need to implement display_player (player) and display_dealer (opponent, start=true) after each draw. You then need to implement the third section marked with # THIRD SECTION INSERT YOUR CODE HERE . For this third section, you should do the following: Implement the logic for the dealer. The dealer will continue to 'hit' (that is, draw a new card) if the total count in their hand is lower than 17. During each 'hit', you must check whether the dealer has won, is bust, or is in the range from 17 to 20 (inclusive). If the dealer has a total value in the range from 17 to 20 (inclusive), then the dealer must stop drawing cards. After this, if no winner/loser has been decided (that is, each of the players has opted to stay at some point), a final comparison is made to see who has the highest total in their hands. The winner is the player with the highest total. At each point that represents an endpoint to the game (such as a bust, the count = 21, or the highest deck value if both players stay), you need to return an appropriate value. For example, if the player wins, return 1, and if the dealer wins, then return -1. Make it your own Extend the implementation of blackjack to work with multiple decks. This involves creating several decks and then executing the same logic, as mentioned previously, for the blackjack game. Note that with multiple decks, it's possible to get multiple copies of the same card. For example, a player may get a hand consisting of (clubs", 2), ('clubs', 2), and so on. Further extend the implementation of blackjack with cheat decks (or missing cards); that is, create decks with known missing cards and ensure that the blackjack logic still works. For example, it should be possible to create decks consisting entirely of Aces and picture cards. This would drastically increase the number of times either player has a hand consisting of a value of 21. Create a "card counting" scheme to keep track of the running count. First, you will need to extend the game logic to create a discard pile. The discard pile contains all the cards that have been used in the previous hands and starts off empty. Create a system that tracks the cards the player has observed and use this information to display the probability of a player drawing a picture card. For this, you should assume that the deck is a complete standard deck. This probability should be printed to the screen and should be "live" in that it updates each time a card is revealed to the player. Task > This task will be manually graded by your instructor to check that the goals and the requirements for the task have been met. blackjack.py + 1 from itertools import product 2 from random import choice, seed 3 from os import linesep 4 5 6 suits = {'hearts', 'clubs', 'spades', 'diamonds"} 7 numbers = set([i for i in range (2,15)]) 8 a = 551 9 seed(a) 10 11 def create_standard_deck(): 12 pass 13 14 15 def get_all_cards (deck): 16 pass 17 18 19 def get_all_twos (deck): 20 pass 21 22 23 def get_all_aces (deck): 24 pass 25 26 27 def get_card_number(deck, card_number): 28 pass 29 30 31 def get_card_suit(deck, suit): 32 pass 33 34 35 def get_number_and_suit(deck, num, suit): 36 pass 37 38 39 def remove_card_from_deck(deck, suit, num): 40 pass 41 42 43 def remove_suit_from_deck(deck, suit): pass 44 45 46 47 def remove_number_from_deck(deck, number): 48 pass 49 50 51 def add_card_to_deck(deck, suit, num): 52 pass 53 54 55 def add_suit_to_deck(deck, suit): 56 pass 57 58 59 def add_number_to_deck(deck, number): 60 pass 61 62 63 def draw_card(deck): 64 # replace this with your implementation pass 65 66 67 68 def display_dealer (opponent, start=False): 69 print('Dealer:) 70 if start: 71 the_output = (opponent[@], ('?', '?')] 72 print(the_output) 73 else: print (opponent) 75 74 76 77 def display_player (player): 78 print("Player:') 79 print(player) 80 81 82 def get_count(player): 83 81 82 def get_count(player): # replace this with your implementation 84 return 85 86 87 def check_cards (player): 88 # replace this with your implementation 89 pass 90 91 92 def create_blackjack_game (user_input): 93 # FIRST SECTION INSERT YOUR CODE HERE 94 # REPLACE WITH YOUR CODE 95 96 97 if not user_input: 98 player_action = input('press h to hit, s to stand, q to quit.').lower().strip(linesep) 99 while player_action not in ('s', 'h', 'q'): 100 player_action = input('press h to hit, s to stand, a to quit.').lower().strip(linesep) 101 else: 102 player_action = user_input.pop() 103 104 if player_action == 'q': 105 return 106 while player_action != 'q': 107 108 if player_action == 'h': 109 pass 110 # SECOND SECTION INSERT YOUR CODE HERE 111 # REPLACE WITH YOUR CODE 112 else: 113 while True: 114 # THIRD SECTION INSERT YOUR CODE HERE 115 # REPLACE WITH YOUR CODE 116 117 pass 118 119 120 121 if not user_input: player_action = input('press h to hit, s to stand, q to quit.').lower().strip(linesep) while player_action not in ('s', 'h', 'q'): 119 120 121 122 123 124 125 126 127 129 if not user_input: player_action = input('press h to hit, s to stand, 9 to quit.').lower().strip(linesep) while player_action not in ('s', 'h', 'q'): player_action = input('press h to hit, s to stand, 9 to quit.').lower().strip(linesep) if player_action == 'q': return else: player_action = user_input.pop()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
