Ejemplo n.º 1
0
    def __le__(self, other):
        return self.value >= other.value

    def __gt__(self, other):
        return self.value < other.value

    def __ge__(self, other):
        return self.value <= other.value


SUITS_FORCE_UNICODE = False

Strain = Enum("Strain", zip("CDHSN", range(5)))
Strain.__str__ = lambda self: self.name
Strain.__lt__ = lambda self, other: self.value < other.value
Strain.__le__ = lambda self, other: self.value <= other.value
Strain.__gt__ = lambda self, other: self.value > other.value
Strain.__ge__ = lambda self, other: self.value >= other.value

Rank = Enum("Rank", zip("23456789TJQKA", range(2, 15)))
Rank.__str__ = lambda self: self.name
Rank.__index__ = lambda self: self.value - 2
Rank.__lt__ = lambda self, other: self.value < other.value
Rank.__le__ = lambda self, other: self.value <= other.value
Rank.__gt__ = lambda self, other: self.value > other.value
Rank.__ge__ = lambda self, other: self.value >= other.value

Card = namedtuple("Card", ["suit", "rank"])
Card.from_str = lambda s: Card(Suit[s[0]], Rank[s[1]])
Card.__str__ = lambda self: "{0.suit}{0.rank}".format(self)
Ejemplo n.º 2
0
 def __lt__(self, other):
     return int(self).__lt__(other) if isinstance(other, int) else Enum.__lt__(self, other)
Ejemplo n.º 3
0
 def __lt__(self, other):
     return int(self).__lt__(other) if isinstance(other, int) else Enum.__lt__(self, other)