Roshambo is the classic rock, paper, scissors game. This is a card game involvin
ID: 3921865 • Letter: R
Question
Roshambo is the classic rock, paper, scissors game. This is a card game involving a deck of 66 cards, 22 of which have a picture of a rock, 22 have a picture of a piece of paper, and 22 have a picture of a pair of scissors. The game starts as follows: The player and the house are each dealt four cards. The player is asked to make a bet that he will win the hand, with the winner of the hand (and bet) being determined by who scores the most points (in the event of a tie, the house wins). The dealer reveals his first card. The player then chooses a card to play. A point is scored by whoever wins, or no points if it is a tie. The player then reveals a card, and the computer plays a card (assume perfect play). The hand continues, alternating who reveals first, until all four cards are played. The player receives the bet amount from the dealer if he wins, otherwise that amount is deducted from the player's account. If the player decides, a new hand is dealt and play repeated. Play ends when the player runs out of money, or he chooses to quit. Your Python implementation: Create a Deck class that has a list of Cards, and a method that deals a card from the list (randomly, without replacement, just like in the earlier homework card games), and a constructor that sets up the list of randomly shuffled cards. Create a Card abstract class that has an integer value (an instance variable). Put in a constructor that sets the integer value (it takes an int as a parameter). Create RockCard, PaperCard, and ScissorsCard classes that inherit from Card. The RockCard's integer value will be 0. PaperCard will have 1, and ScissorsCard will have 2. They will also each have a class variable with the appropriate string representation for that kind of card. Finally, they will have an instance method that takes in a Card as an argument and returns a boolean that reflects whether this card beats the other card. Implement the game play as described above. When the deck runs out of cards, just make a new deck (using the constructor).Explanation / Answer
from abc import ABCMeta, abstractmethod import sys import random # // abstaract class that has an integer value # // has a constructor that takes in an int value class Card(object): ___metaclass__ = ABCMeta @abstractmethod def __init__(self, intValue): print(intValue) class RockCard: string = "Rock" intValue = 0 def __init__(self, Card): print('never called and goes to __new__') def __new__(cls, Card): if (Card.intValue == 1): return True if (Card.intValue == 0): return False if(Card.intValue == 2): return False #integer value 0 # appropriate String representatrion for the suit # inherit from Card #instance method takes a card as an argument returns boolean # (cont) reflects wheter this card beats the other card class PaperCard: string = "Paper" intValue = 1 def __init__(self, Card): print('never called and goes to __new__') def __new__(cls, Card): if (Card.intValue == 1): return False if (Card.intValue == 0): return False if(Card.intValue == 2): return True #integer value 1 # appropriate String representatrion for the suit # inherit from Card #instance method takes a card as an argument returns boolean # (cont) reflects wheter this card beats the other card class ScissorsCard: string = "Scissors" intValue = 2 def __init__(self, Card): print('never called and goes to __new__') def __new__(cls, Card): if (Card.intValue == 1): return False if (Card.intValue == 0): return True if(Card.intValue == 2): return False # integer value 2 # appropriate String representatrion for the suit # inherit from Card #instance method takes a card as an argument returns boolean # (cont) reflects wheter this card beats the other card #listofCards #method that deals a card from the list randomly without replacement like hw2 #a constructor that sets up the list of rand # omly shuffled cards #make a new deck using constructor when cards run out class Deck(object): listOfCards = {} deckArray=[] rockCard = RockCard paperCard = PaperCard scissorsCard = ScissorsCard def __init__(self): print("inside constructor") # self.initializeKeyArray() self.createDeck() self.shuffle() self.amountOfCardsCheck() def amountOfCardsCheck(self): print("amountOfCardsCheck line 95 ") if len(self.deckArray)Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.