# extendedcard.py # YOUR NAME(S) AND NETID(S) HERE # skeleton by Lillian Lee (LJL2) and Steve Marschner (SRM2) # DATE COMPLETED HERE """Module for representing cards in decks that include jokers. Intent is to practice writing a subclass""" import card class ExtendedCard(card.Card): """Represents either a standard playing card or a black or red joker. Class variables: SUIT_NAMES [list of strings]: list of names of cards. NUM_SUITS [int]: length of SUIT_NAMES BJRANK [int]: rank for black joker. Fixed at 1 RJRANK [int]: rank for red joker. Fixed at 2 RANK_NAMES [list of strings except first item] (inherited): list of names for the ranks of cards, like 'Jack' or '9'. The first item is None. NUM_RANKS [int] (inherited): length of RANK_NAMES Instance variables: suit [int] (inherited): the suit of this particular card. The name of this suit is given by class variable SUIT_NAMES[suit]. Always in 0..NUM_SUITS-1 rank [int] (inherited): the rank of this particular card. The name of this rank is given by RANK_NAMES[rank]. Always in 1..NUM_RANKS Hence, if we execute c = ExtendedCard(0, 12), SUIT_NAMES[c.suit] is 'Clubs' and RANK_NAMES[c.rank] is '12' and this card is the Queen of Clubs. The only ranks allowed for suit 'Joker' are 1 and 2. """ # initialization of class variables (intended as constants) SUIT_NAMES = card.Card.SUIT_NAMES[:] + ['Joker'] NUM_SUITS = len(SUIT_NAMES) BJRANK = 1 # mnemonic for rank of the black joker RJRANK = 2 # mnemonic for rank of the red joker def __init__(self, suit, rank): """Initializer: A new card whose suit encoding is and rank encoding is . Example: if we execute c = ExtendedCard(0, 12), then this card is the Queen of Clubs, since SUIT_NAMES[c.suit] is 'Clubs' and RANK_NAMES[c.rank] is 12. Preconditions: s in 0..NUM_SUITS-1 (inclusive) and r in 1..NUM_RANKS (inclusive). If corresponds to 'Joker', then must be either 1 (black joker) or 2 (red joker).""" pass # IMPLEMENT ME # UNCOMMENT AND IMPLEMENT # def __str__(self): # """Readable string representation of this card. # Examples: '2 of Hearts', 'King of Diamonds', 'Black Joker', 'Red Joker'.""" def full_deck(): """Returns: list of the standard 52 cards plus the two jokers""" jokersuit = ExtendedCard.NUM_SUITS-1 return (card.full_deck() + [ExtendedCard(jokersuit, ExtendedCard.BJRANK), ExtendedCard(jokersuit, ExtendedCard.RJRANK)]) def print_cards(clist): """Print cards in list clist. Precondition: clist is a list of Cards, possibly empty.""" # We are providing this function just as a convenience, so that one doesn't # have to import card.py in order to use the print_cards function. card.print_cards(clist)