shortdeck1.2

This commit is contained in:
2025-10-09 15:27:17 +08:00
parent 7071eaa12b
commit 4763f9a630
19 changed files with 615 additions and 250 deletions

View File

@@ -4,13 +4,14 @@ from .card import Card, Rank
class HandType(Enum):
# 短牌规则:同花 > 葫芦
HIGH_CARD = (1, "High Card")
ONE_PAIR = (2, "Pair")
TWO_PAIR = (3, "Two Pair")
THREE_OF_A_KIND = (4, "Three of a Kind")
STRAIGHT = (5, "Straight")
FLUSH = (6, "Flush")
FULL_HOUSE = (7, "Full House")
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")
@@ -55,3 +56,26 @@ class HandRanking:
return f"Pair({self.key_ranks[0].symbol})"
else:
return f"High Card({self.key_ranks[0].symbol})"
def __lt__(self, other):
"""比较牌力,用于排序"""
if not isinstance(other, HandRanking):
return NotImplemented
if self.hand_type.strength != other.hand_type.strength:
return self.hand_type.strength < other.hand_type.strength
for my_rank, other_rank in zip(self.key_ranks, other.key_ranks):
if my_rank.numeric_value != other_rank.numeric_value:
return my_rank.numeric_value < other_rank.numeric_value
return False
def get_strength(self) -> int:
# 返回牌力 还是 牌型+点数
# 基础强度 = 牌型强度 * 1000000
strength = self.hand_type.strength * 1000000
for i, rank in enumerate(self.key_ranks):
strength += rank.numeric_value * (100 ** (4 - i))
return strength