Question: Can anybody help me with actual code, please? Many versions of this game exist that people play. We'll be using simplified rules. The goal of







Many versions of this game exist that people play. We'll be using simplified rules. The goal of the game for the player is to reach 21 . The dealer deals cards. The values of all cards dealt to a player are added together. 1. If a player's sum exceeds 21 , the player busts and loses immediately. 2. If a player's sum is exactly 21 , they win against the dealer immediately. 3. In all other cases, the player wins if the sum of their cards is greater than the sum of the dealer's cards; the player loses if their sum is less than the dealer. 4. In any hand, the dealer must take cards until their hand is at least 17 points. 5. Each face card has a value of 10 . 6. Each number card has its numeric value. 7. An Ace may be counted as 1 or 11, whichever is better for the hand. Dealing of Cards and Game Play 1. The dealer deals a card face up to the player and then to itself. 2. The dealer deals a second card to the player face up. 3. If the player has two aces, the first one must count as a one. 4. The dealer gives itself a second card face down. If a card is face down, display a question mark in pace of the value and a space where the suit would be. 5. The player has to decide whether to stand or hit. a. if the player stands, then their turn is over and it's the dealer turn. b. if the player hits, another card is dealt to the player and they decide again. 4. The dealer gives itself a second card face down. If a card is face down, display a question mark in pace of the value and a space where the suit would be. 5. The player has to decide whether to stand or hit. a. if the player stands, then their turn is over and it's the dealer turn. b. if the player hits, another card is dealt to the player and they decide again. 6. The dealer reveals the hidden card. a. if its hand is less than 17 , the dealer must take another card. b. once the dealer's hand is at least 17, the dealer must stand. 7. When counting the score for a hand, only count cards that are face up/showing. This image shows an example game state after the initial deal. This image shows a game state at the end of an example game. Design of the Game OOP is about how code and data are organized. Where you put code and data can make other code that uses it either simpler or more complex. You MUST have: - the classes listed below - each class must have a constructor in your code. Other attributes and methods described in each class below are strong suggestions, but not strictly required if another organization makes more sense to OOP is about how code and data are organized. Where you put code and data can make other code that uses it either simpler or more complex. You MUST have: - the classes listed below - each class must have a constructor in your code. Other attributes and methods described in each class below are strong suggestions, but not strictly required if another organization makes more sense to you. Card class A Card class represents one single card. A card typically has the following attributes: - suit one of { "Spades", "Clubs", "Hearts", "Diamonds"\} - value one of {A,"K ", "Q", "J", "2" up to "10" - numeric_value An ace is either 1 or 11,{10, Jack, Queen, King } are 10. numeric cards have their numeric value. Suggestions: - A magic method that returns the card as a string in ASCII art. All cards should be the same size and format. - a boolean flag that indicates whether the card is face up or face down. Deck class A deck is a stack of 52 cards. A deck can be shuffled, and usually cards are dealt from only the top or only the bottom. If you want to print nice unicode characters for suits, and keep track of card values, the following items may be helpful: suits=["Spades","Hearts","Clubs","Diamonds"] An alternate dictionary for suit values should work if your console does not support unicode strings (Windows most likley: Dealer class The dealer deals cards, but also plays a hand. The rules for how a dealer plays are different from how a player plays. Suggestions: - Hand attribute the collection of cards dealt to the dealer - Deck attribute the dealer has the deck - deal() method the dealer deals a card from the deck - magic method returns the dealer's hand and total score as a string Player class The player plays a hand. The rules for how a player plays are different from how a dealer plays. Suggestions: - Hand attribute the collection of cards dealt to the player - magic method returns the players's hand and total score as a string Hand class A hand is 0,1 or more cards that have been dealt to a player or to the dealer. The score of any hand must take into account the value of aces, 50 it's more than just a simple sum for both dealer and player. Suggestions: - add) method adds a card to the hand. If it's an ace, check whether it should be a 1 or an 11 . This check can also be done in the sum method. - method magic method to return the collection of cards as a ASCII art string - method magic method to return how many cards are in the hand, - method return the total score of a hand. The total is affected by the value of aces being 1 or 11 , whichever gives the best score. Game class A game instance runs a game and keeps track of the state of the game. Suggestions: run() method implements the pseudocode algorithm given in the module docstring. Game class A game instance runs a game and keeps track of the state of the game. Suggestions: run() method implements the pseudocode algorithm given in the module docstring. - player_turn () method implement code for the player's turn. - dealer_turn() method implement code for the dealer's turn. - player attribute - dealer attribute Clearing the console It is often convenient when debugging to see the sequence of cards displayed as they are dealt to a player. But when the game is running, it is ctten nicer to clear the console. The following utility function accomplishes this: def clear(): " " for windows if os.name =ar 'nt': " os. system('ols') * for mac and 11 inux, where os.name is "posix' else: - =os.system('olear') Testing Your Code You are not required to create nor submit test code for this project. However. 21 import os 22 23 class Card: pass class Deck: pass class Hand: pass 31 32 class Dealer: 33 pass 34 35 class Player: 36 pass 37 38 class Game: 39 \begin{tabular}{c|c} 40 & def run(self): \\ 41 & pass \\ 42 & \\ 43 & def clear(): \\ 44 & "n'clear the console. "nn \\ 45 & \# for windows \\ 46 & if os. name == 'nt': \\ 47 & = os. systen('cls') \end{tabular} * for mac and linux, where os. nane is 'posix' else: _=os.system('clear') 51 52 def main(): 53 pass 54 55 if __name__ ==main__': 56main()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
