This commit is contained in:
2025-09-24 16:54:52 +08:00
parent 45f86ba95e
commit 57a7e9216e
22 changed files with 1647 additions and 102 deletions

52
shortdeck/hand_ranking.py Normal file
View File

@@ -0,0 +1,52 @@
from functools import total_ordering
from enum import Enum
from typing import List
from poker.hand_ranking import HandType, HandRanking
from poker.card import ShortDeckRank, Card
@total_ordering
class ShortDeckHandType(Enum):
"""
标准牌型扑克与短牌型扑克的区别:
- 同花(Flush) > 满堂红(Full House)
- 其他牌型等级不变
"""
HIGH_CARD = (1, "High Card")
ONE_PAIR = (2, "One Pair")
TWO_PAIR = (3, "Two Pair")
THREE_OF_A_KIND = (4, "Three of a Kind")
STRAIGHT = (5, "Straight")
FULL_HOUSE = (6, "Full House")
FLUSH = (7, "Flush")
FOUR_OF_A_KIND = (8, "Four of a Kind")
STRAIGHT_FLUSH = (9, "Straight Flush")
ROYAL_FLUSH = (10, "Royal Flush")
def __new__(cls, strength, type_name):
obj = object.__new__(cls)
obj._value_ = strength
obj.strength = strength
obj.type_name = type_name
return obj
def __str__(self):
return self.type_name
def __eq__(self, other):
if isinstance(other, ShortDeckHandType):
return self.strength == other.strength
return NotImplemented
def __lt__(self, other):
if isinstance(other, ShortDeckHandType):
return self.strength < other.strength
return NotImplemented
class ShortDeckHandRanking(HandRanking):
def __init__(self, hand_type: ShortDeckHandType, key_ranks: List[ShortDeckRank], cards: List[Card]):
super().__init__(hand_type, key_ranks, cards)
def __str__(self):
return super().__str__()