62 lines
1.2 KiB
Python
62 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
from enum import IntEnum
|
|
from typing import List
|
|
|
|
|
|
class Suit(IntEnum):
|
|
S = 0
|
|
H = 1
|
|
D = 2
|
|
C = 3
|
|
|
|
def __str__(self) -> str:
|
|
return "shdc"[self.value]
|
|
|
|
|
|
class Rank(IntEnum):
|
|
R6 = 6
|
|
R7 = 7
|
|
R8 = 8
|
|
R9 = 9
|
|
RT = 10
|
|
RJ = 11
|
|
RQ = 12
|
|
RK = 13
|
|
RA = 14
|
|
|
|
def __str__(self):
|
|
if self.value <= 9:
|
|
return str(self.value)
|
|
return {10: "T", 11: "J", 12: "Q", 13: "K", 14: "A"}[self.value]
|
|
|
|
@property
|
|
def numeric_value(self):
|
|
return self.value
|
|
|
|
@property
|
|
def symbol(self):
|
|
return str(self)
|
|
|
|
|
|
class Card:
|
|
def __init__(self, rank: Rank, suit: Suit):
|
|
self.rank = rank
|
|
self.suit = suit
|
|
|
|
def __repr__(self) -> str:
|
|
return f"{str(self.rank)}{str(self.suit)}"
|
|
|
|
def __str__(self) -> str:
|
|
return self.__repr__()
|
|
|
|
@classmethod
|
|
def all_short(cls) -> List["Card"]:
|
|
cards: List[Card] = []
|
|
for r in [Rank.R6, Rank.R7, Rank.R8, Rank.R9, Rank.RT, Rank.RJ, Rank.RQ, Rank.RK, Rank.RA]:
|
|
for s in Suit:
|
|
cards.append(Card(r, s))
|
|
return cards
|
|
|
|
|