May-30-2023, 02:12 PM
So i'm trying to simulate a deck of cards using dataclasses. The suit and rank of a card are represented as a enum.Enum DataClass. Together they make the Card DataClass. A list of cards makes a Deck. Now the wall i've hit lies in the fact that different games using cards have different rules. So in the one game it could be that the hearts are trump and thus a 2 of hearts is higher than a king of spades. While in an other game the rank solely dictates the ordering. How can I define the ordering of a set of cards in de dataclass Deck? Is this even possible?
Here some sample code:
Here some sample code:
@dataclass
class Suit(enum.Enum):
HEARTS='hearts'
SPADES='spades'
DIAMONDS='diamonds'
CLUBS='clubs'
@dataclass
class Card():
suit:Suit
rank:int
def __repr__(self):
return f'{self.suit}{self.rank}'
def __gt__(self, other):
# IF (for example) Deck.orderingtype == some_ordering_type:
if self.suit == other.suit:
return self.rank > other.rank
else:
return self.suit > other.suit
# ELSE: ....
@dataclass
class Deck():
cards:list
trump:Suit
