1
1
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from collections import defaultdict
|
||||
|
||||
from collections import defaultdict
|
||||
|
||||
class Hand:
|
||||
def __init__(self):
|
||||
# 存储所有的牌
|
||||
@@ -24,14 +26,14 @@ class Hand:
|
||||
""" 获取手牌中某张牌的数量 """
|
||||
return self.tile_count[tile]
|
||||
|
||||
def can_pong(self, tile):
|
||||
""" 判断是否可以碰(即是否有3张相同的牌) """
|
||||
return self.tile_count[tile] >= 2
|
||||
def can_peng(self, tile):
|
||||
""" 判断是否可以碰(即是否已经有2张相同的牌,摸一张牌后可以碰) """
|
||||
return self.tile_count[tile] == 2 # 摸一张牌后总数为 3 张,才可以碰
|
||||
|
||||
def can_gang(self, tile):
|
||||
""" 判断是否可以杠(即是否有4张相同的牌) """
|
||||
return self.tile_count[tile] >= 3
|
||||
""" 判断是否可以杠(即是否已经有3张相同的牌,摸一张牌后可以杠) """
|
||||
return self.tile_count[tile] == 3 # 摸一张牌后总数为 4 张,才可以杠
|
||||
|
||||
def __repr__(self):
|
||||
""" 返回手牌的字符串表示 """
|
||||
return f"手牌: {self.tiles}, 牌的数量: {dict(self.tile_count)}"
|
||||
return f"手牌: {self.tiles}, 牌的数量: {dict(self.tile_count)}"
|
||||
|
||||
Reference in New Issue
Block a user