其他分享
首页 > 其他分享> > 2021-07-02

2021-07-02

作者:互联网

基于Python的德州扑克的实现

德州扑克# 设计一个程序:# (1)洗牌功能# (2)发牌功能# (3)验证手牌# 皇家同花顺(同一个花色五张连牌 A K Q J 10)# 同花顺(同一个花色 7 8 9 10 J)# 四条 (x x x x + y)# 满堂红(x x x + y y)# 同花 (5张同一花色)# 顺子 (不同花色组成的顺子)# 三条 (x x x + y z)# 两对 (x x y y + z)# 一对 (x x y z c)# 普通牌 # 52张牌, 包含4种花色(红心, 黑心, 方块, 梅花)# 每种花色13张(A 2 3 4 5 6 7 8 9 10 J Q K) 1 2 3 4 5 6 7 8 9 10 11 12 13import randomclass D: dict = {10: ‘同花顺’}class Card: “”“卡牌”"" def init(self): # 一张卡牌是由花色+点数构成的 self.__color = ‘’ self.__value = 1 @property def color(self): return self.__color @color.setter def color(self, value): if isinstance(value, str): self.__color = value @property def value(self): return self.__value @value.setter def value(self, value): if isinstance(value, int): if value < 1 or value >= 14: self.__value = 1 else: self.__value = value def str(self): “”" 重写该方法的目的是为了输出对象的时候,输出我们想要的信息 “”" # 构造特殊点数的映射关系 special_point = {1: ‘A’, 11: ‘J’, 12: ‘Q’, 13: ‘K’} # 判断 if self.value in special_point: # 替换 str_value = special_point[self.__value] else: str_value = str(self.__value) return self.color + str_value + " " class Poke: def init(self): “”" 初始化一副扑克 “”" # 花色 poke_color = [‘红桃’, ‘黑桃’, ‘方块’, ‘梅花’] # 点数 poke_point = [value for value in range(1, 14)] # 存储牌 self.poke = [] # 定义索引 index = 0 # 构造扑克 for i in range(4): for j in range(13): # 1. 创建card card = Card() # 2. 将生成的card装入扑克中 self.poke.append(card) # 3. 设置card的花色和点数 self.poke[index].color = poke_color[i] self.poke[index].value = poke_point[j] # 4. 索引递增 index += 1 def show(self, poke): “”“显示所有的扑克”"" index = 0 for card in poke: if index % len(poke) == 0: print("") print(card, end=’’) index += 1 print("") def shuffle(self): “”“洗牌”"" random.shuffle(self.poke) def deal_poke(self, start=0, end=5, step=1): “”“发牌”"" return self.poke[start

标签:02,poke,07,self,value,hand,2021,print,card
来源: https://blog.csdn.net/m0_58930438/article/details/118418180