""" Felix Muzny DS 2000 Lecture 20 code November 19, 2024 Class representing a single card Lecture 18: - __init__ - __str__ Lecture 19: - __gt__ - __eq__ - is_face Lecture 20: no updates, most likely """ # Lecture 19: updated this constant # clubs, diamonds, hearts, spades, using fancy symbols now! VALID_SUITS = {1:'\u2663', 2:'\u2666', 3:'\u2665', 4:'\u2660'} # so that we can print these out nicely too SPECIAL_CARDS = {1:'Ace', 11:'Jack', 12:'Queen', 13:'King'} # Lecture 20: added this constant FACE_CARDS = [11, 12, 13] class Card: def __init__(self, suit, number): """ initialize a new card object :param suit: int value representing the suit of the card, 1 is clubs, 2 diamonds, 3 hearts, 4 spades :param number: int value representing the number of the card with 1 being Ace and 11 being Jack etc """ # set up the attributes self.suit = suit self.number = number def __str__(self): """ Get a string representation like "_____ of _____" for this card :return: str """ if self.number in SPECIAL_CARDS: return SPECIAL_CARDS[self.number] + " of " + VALID_SUITS[self.suit] else: return str(self.number) + " of " + VALID_SUITS[self.suit] def __gt__(self, other): """ Greater than function. Compare this card (the card on the left of > to another card c1 > c2 --> c1.__gt__(c2) Aces are always the lowest card :param other: Card :return: True if this card is greater than the other one """ if self.number > other.number: return True elif self.number < other.number: return False else: return self.suit > other.suit def __eq__(self, other): """ Equals function. Compare this card (the card on the left of == to another card c1 == c2 --> c1.__eq__(c2) :param other: Card :return: True if this card's number and suit are the same as the other card """ return self.number == other.number and self.suit == other.suit def is_face(self): """ tells whether or not a card is a face card :return: True if card is a face card """ return self.number in FACE_CARDS