import random """ Class which describes playing cards """ class Card(): """ A joker card has value 0 and suit 0 """ HEARTS = 1 DIAMONDS = 2 SPADES = 3 CLUBS = 4 def __init__(self, value, suit) -> None: self.value = value self.suit = suit def __str__(self) -> str: suits = ["J", "♥", "♦", "♠", "♣"] special_cards = {1: "A", 11: "J", 12: "Q", 13: "K"} strValue = "" if self.value in special_cards.keys(): strValue = special_cards[self.value] else: strValue = str(self.value) string = "" string.format("%s %s", suits[self.suit], strValue) return string """ Class for interacting with a deck of cards """ class Deck(): def __init__(self) -> None: self.deck = [] self.discard = [] self.joker = False if self.joker: self.deck = [x for x in range(0, 52)] else: self.deck = [x for x in range(0, 51)] def shuffle(self): random.shuffle(self.deck) def take_from_deck(self): card = self.deck.pop() return card def return_to_deck_top(self, card): self.deck.insert(0, card) def returnToDeckBottom(self, card): self.deck.append(card) def addToDiscard(self, card): self.discard.insert(0, card) def returnFromDiscard(self): self.returnToDeckTop(self.discard.pop()) def __str__(self) -> str: string = "" for card in self.deck: string += convertNumberToCard(card) return string class Hand(): def __init__(self) -> None: self.hand = [] def sortHand(self): self.hand.sort() def addToHand(self, card): self.hand.append(card) def removeFromHand(self, index): card = self.hand.remove(index) return card