def __init__(self, seat_id, game_data, point=0): self.game_data = game_data self.seat_id = seat_id self.hu_source_seat = -1 # 胡牌来源座位号 self.can_hu_result = [] # 玩家当前可胡的牌型 self.hand_card = HandCard(seat_id, game_data) self.point = point self.time_out_count = 0 # 超时次数 self.is_auto = 0 # 是否处于托管状态 self.zi_mo_num = 0 self.hu_pai_num = 0 self.jie_pao_num = 0 self.dian_pao_num = 0 self.an_gang_num = 0 self.ming_gang_num = 0 self.hook_hu_seat_id = -1 # 抢胡来源座位id self.ting_info = { } # 选择听牌后的胡牌信息 {胡的牌:{"fan":胡牌基本类型番数, "type_list":[胡牌类型]}, ...} self.can_ting_info = { } # 可以听牌的信息 {出牌1:{胡的牌:{"fan":胡牌基本类型番数, "type_list":[胡牌类型]}, ...}
def reset_data(self): """ 一局游戏结束重置玩家数据 :return: """ self.hu_source_seat = -1 # 胡牌来源座位号 self.hand_card = HandCard(self.seat_id, self.game_data) self.time_out_count = 0 # 超时次数 self.is_auto = 0 # 是否处于托管状态 self.zi_mo_num = 0 self.hu_pai_num = 0 self.jie_pao_num = 0 self.dian_pao_num = 0 self.an_gang_num = 0 self.ming_gang_num = 0 self.ting_info = {} self.can_ting_info = {} self.reset_hook()
if hand_card.bu_gang_card_vals: for group in hand_card.bu_gang_card_vals: k.append([group[0], group[0], group[0]]) if hand_card.an_gang_card_vals: for group in hand_card.an_gang_card_vals: k.append([group[0], group[0], group[0]]) if hand_card.dian_gang_card_vals: for group in hand_card.dian_gang_card_vals: k.append([group[0], group[0], group[0]]) return len(k) == 4 if __name__ == "__main__": pass card_analyse = CardAnalyse() hand_card = HandCard(0) # hand_card.hand_card_info = { # 1: [9, 1, 1, 1, 1, 1, 1, 1, 1, 1], # 万 # 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 # 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 # 4: [2, 2, 0, 0, 0], # 风 # 5: [3, 3, 0, 0], # 箭 # } hand_card.hand_card_info = { 1: [14, 0, 3, 3, 3, 2, 3, 0, 0, 0], # 万 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 4: [0, 0, 0, 0, 0], # 风 5: [0, 0, 0, 0], # 箭 }
def __init__(self): super(SiAnKe, self).__init__() def is_this_type(self, hand_card, card_analyse): ret = card_analyse.get_jiang_ke_shun_plus(hand_card.hand_card_vals) for index in xrange(len(ret)): k = ret[index]["k"] if len(k) == 4: return True return False if __name__ == "__main__": pass card_analyse = CardAnalyse() hand_card = HandCard(0, None) hand_card.hand_card_info = { 1: [8, 3, 3, 0, 0, 0, 0, 0, 2, 0], # 万 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 4: [3, 3, 0, 0, 0], # 风 5: [3, 3, 0, 0], # 箭 } # hand_card.hand_card_info = { # 1: [9, 1, 1, 1, 1, 1, 1, 1, 1, 1], # 万 # 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 # 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 # 4: [2, 2, 0, 0, 0], # 风 # 5: [0, 0, 0, 0], # 箭 # }
j, s, k = card_analyse.get_jiang_ke_shun(hand_card.hand_card_vals) if hand_card.chi_card_vals: s.extend(hand_card.chi_card_vals) if len(s) < 2: return False s.sort() print "s=", s if [17, 18, 19] in s and [23, 24, 25] in s: return True return False if __name__ == "__main__": pass card_analyse = CardAnalyse() hand_card = HandCard(0) # hand_card.hand_card_info = { # 1: [9, 1, 1, 1, 1, 1, 1, 1, 1, 1], # 万 # 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 # 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 # 4: [2, 2, 0, 0, 0], # 风 # 5: [3, 3, 0, 0], # 箭 # } hand_card.hand_card_info = { 1: [6, 0, 0, 0, 1, 1, 1, 1, 1, 1], # 万 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 4: [2, 2, 0, 0, 0], # 风 5: [3, 3, 0, 0], # 箭 } # hand_card.chi_card_vals=[[23,24,25]]
class Player(object): """ 游戏内玩家类 """ def __init__(self, seat_id, game_data, point=0): self.game_data = game_data self.seat_id = seat_id self.hu_source_seat = -1 # 胡牌来源座位号 self.can_hu_result = [] # 玩家当前可胡的牌型 self.hand_card = HandCard(seat_id, game_data) self.point = point self.time_out_count = 0 # 超时次数 self.is_auto = 0 # 是否处于托管状态 self.zi_mo_num = 0 self.hu_pai_num = 0 self.jie_pao_num = 0 self.dian_pao_num = 0 self.an_gang_num = 0 self.ming_gang_num = 0 self.hook_hu_seat_id = -1 # 抢胡来源座位id self.ting_info = { } # 选择听牌后的胡牌信息 {胡的牌:{"fan":胡牌基本类型番数, "type_list":[胡牌类型]}, ...} self.can_ting_info = { } # 可以听牌的信息 {出牌1:{胡的牌:{"fan":胡牌基本类型番数, "type_list":[胡牌类型]}, ...} def reset_data(self): """ 一局游戏结束重置玩家数据 :return: """ self.hu_source_seat = -1 # 胡牌来源座位号 self.hand_card = HandCard(self.seat_id, self.game_data) self.time_out_count = 0 # 超时次数 self.is_auto = 0 # 是否处于托管状态 self.zi_mo_num = 0 self.hu_pai_num = 0 self.jie_pao_num = 0 self.dian_pao_num = 0 self.an_gang_num = 0 self.ming_gang_num = 0 self.ting_info = {} self.can_ting_info = {} self.reset_hook() def set_hand_card(self, hand_card): self.hand_card.hand_card_info = hand_card def change_point(self, num): self.point += num def chu_card(self, card_val): self.hand_card.del_hand_card_by_val(card_val) self.hand_card.out_card_vals.append(card_val) def reset_hook(self): self.hook_hu_seat_id = -1 # 抢胡来源座位id def set_can_ting_info(self, ting_info={}): """ 记录可听牌信息 :param ting_info: 可以听牌的信息 {出牌1:{胡的牌:{"fan":胡牌基本类型番数, "type_list":[胡牌类型]}, ...} :return: """ self.can_ting_info = ting_info def set_ting_info(self, chu_card_val): """ 记录选择的听牌信息 :param chu_card_val: 选择打出哪张牌后听牌 :return: """ self.ting_info = self.can_ting_info.get(chu_card_val)
super(XiaoSanYuan, self).__init__() def is_this_type(self, hand_card, card_analyse): # 不是清一色则返 False union_card = hand_card.union_card_info # 4,5,6 至少有一张 for i, count in enumerate(union_card[CardType.JIAN]): if i == 0 and count != 8: return False return True if __name__ == "__main__": pass card_analyse = CardAnalyse() hand_card = HandCard(0, None) # hand_card.hand_card_info = { # 1: [14, 3, 3, 3, 1, 1, 1, 0, 0, 2], # 万 # 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 # 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 # 4: [0, 0, 0, 0, 0], # 风 # 5: [0, 0, 0, 0], # 箭 # } hand_card.hand_card_info = { 1: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 万 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 4: [6, 3, 3, 0, 0], # 风 5: [8, 3, 3, 2], # 箭 }
2) 门前清:胡牌时,除了胡的那张牌是别人打出来的,其他的牌都是自己抓的。 """ def __init__(self): super(MenQianQing, self).__init__() def is_this_type(self, hand_card, card_analyse): used_card_type = [CardType.WAN] # 此游戏中使用的花色 hand_card_for_settle_show = hand_card.hand_card_for_settle_show return len(hand_card_for_settle_show) == 2 if __name__ == "__main__": pass card_analyse = CardAnalyse() hand_card = HandCard(0) # hand_card.hand_card_info = { # 1: [9, 1, 1, 1, 1, 1, 1, 1, 1, 1], # 万 # 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 # 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 # 4: [2, 2, 0, 0, 0], # 风 # 5: [3, 3, 0, 0], # 箭 # } hand_card.hand_card_info = { 1: [9, 1, 1, 1, 1, 1, 1, 1, 1, 1], # 万 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 4: [2, 2, 0, 0, 0], # 风 5: [0, 0, 0, 0], # 箭 } hand_card.record_chi_card(23, [24, 25])
union_card = hand_card.union_card_info print "union_card = ", union_card # 4,5,6 至少有一张 jiang_ke_count = 0 for i, count in enumerate(union_card[CardType.JIAN]): if i == 0 and count < 3: return False if count == 3: jiang_ke_count += 1 return jiang_ke_count == 1 if __name__ == "__main__": pass card_analyse = CardAnalyse() hand_card = HandCard(0) # hand_card.hand_card_info = { # 1: [9, 1, 1, 1, 1, 1, 1, 1, 1, 1], # 万 # 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 # 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 # 4: [2, 2, 0, 0, 0], # 风 # 5: [3, 3, 0, 0], # 箭 # } hand_card.hand_card_info = { 1: [9, 1, 1, 1, 1, 1, 1, 1, 1, 1], # 万 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 4: [2, 2, 0, 0, 0], # 风 5: [0, 0, 0, 0], # 箭 } hand_card.chi_card_vals = [[23, 24, 25]]
k.extend(hand_card.peng_card_vals) if len(k) < 2: return False print "k=", k if [17, 17, 17] in k and [25, 25, 25] in k: return True for i in [65, 66, 67, 68]: if i in k: return True return False if __name__ == "__main__": pass card_analyse = CardAnalyse() hand_card = HandCard(0) # hand_card.hand_card_info = { # 1: [9, 1, 1, 1, 1, 1, 1, 1, 1, 1], # 万 # 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 # 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 # 4: [2, 2, 0, 0, 0], # 风 # 5: [3, 3, 0, 0], # 箭 # } hand_card.hand_card_info = { 1: [8, 0, 0, 0, 1, 1, 1, 2, 0, 3], # 万 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 4: [0, 0, 0, 0, 0], # 风 5: [3, 3, 0, 0], # 箭 } # hand_card.chi_card_vals=[[23,24,25]]
def __init__(self): super(DaSanYuan, self).__init__() def is_this_type(self, hand_card, card_analyse): # 不是清一色则返 False union_card = hand_card.union_card_info # 4,5,6 至少有一张 if union_card[CardType.JIAN][0] == 9: return True return False if __name__ == "__main__": pass card_analyse = CardAnalyse() hand_card = HandCard(0, None) hand_card.hand_card_info = { 1: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 万 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 4: [5, 3, 2, 0, 0], # 风 5: [9, 3, 3, 3], # 箭 } # hand_card.hand_card_info = { # 1: [8, 0, 0, 0, 1, 2, 2, 1, 0, 2], # 万 # 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 # 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 # 4: [0, 0, 0, 0, 0], # 风 # 5: [0, 0, 0, 0], # 箭 # }
def is_this_type(self, hand_card, card_analyse): used_card_type = [CardType.WAN] # 此游戏中使用的花色 union_card = hand_card.union_card_info for index, count in enumerate(union_card[CardType.WAN]): if index in [0, 1, 9]: continue if count > 0: return False return True if __name__ == "__main__": pass card_analyse = CardAnalyse() hand_card = HandCard(0, None) # hand_card.hand_card_info = { # 1: [9, 1, 1, 1, 1, 1, 1, 1, 1, 1], # 万 # 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 # 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 # 4: [2, 2, 0, 0, 0], # 风 # 5: [3, 3, 0, 0], # 箭 # } hand_card.hand_card_info = { 1: [11, 0, 1, 1, 1, 1, 2, 2, 1, 2], # 万 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 4: [3, 0, 0, 3, 0], # 风 5: [0, 0, 0, 0], # 箭 } # hand_card.record_peng_card(67)
k.extend(ke_lst) print "k=", k if len(k) < 3: return False if k[0][0] - 1 == k[1][0] and k[1][0] - 1 == k[2][0]: return True if len(k) == 4: if k[1][0] - 1 == k[2][0] and k[2][0] - 1 == k[3][0]: return True return False if __name__ == "__main__": pass card_analyse = CardAnalyse() hand_card = HandCard(0, None) # hand_card.hand_card_info = { # 1: [14, 3, 3, 3, 1, 1, 1, 0, 0, 2], # 万 # 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 # 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 # 4: [0, 0, 0, 0, 0], # 风 # 5: [0, 0, 0, 0], # 箭 # } hand_card.hand_card_info = { 1: [7, 3, 0, 0, 0, 1, 0, 1, 2, 0], # 万 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 4: [0, 0, 0, 0, 0], # 风 5: [0, 0, 0, 0], # 箭 }
def __init__(self): super(DanGouJiang, self).__init__() def is_this_type(self, hand_card, card_analyse): hu_card_val = hand_card.hu_card_val j, s, k = card_analyse.get_jiang_ke_shun(hand_card.hand_card_vals) print "j=", j if hu_card_val and hu_card_val in j[0]: return True return False if __name__ == "__main__": pass card_analyse = CardAnalyse() hand_card = HandCard(0) # hand_card.hand_card_info = { # 1: [9, 1, 1, 1, 1, 1, 1, 1, 1, 1], # 万 # 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 # 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 # 4: [2, 2, 0, 0, 0], # 风 # 5: [3, 3, 0, 0], # 箭 # } hand_card.hand_card_info = { 1: [11, 3, 0, 0, 1, 1, 1, 2, 0, 3], # 万 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 4: [0, 0, 0, 0, 0], # 风 5: [3, 3, 0, 0], # 箭 } # hand_card.chi_card_vals=[[23,24,25]]
class QuanQiuRen(BaseType): """ 3) 全求人: 胡牌时,全靠吃牌、碰牌、单钓别人打出的牌胡牌。不记番:单钓 """ def __init__(self): super(QuanQiuRen, self).__init__() def is_this_type(self, hand_card, card_analyse): cards = hand_card.hand_card_vals return len(cards) == 2 if __name__ == "__main__": pass card_analyse = CardAnalyse() hand_card = HandCard(0) # hand_card.hand_card_info = { # 1: [9, 1, 1, 1, 1, 1, 1, 1, 1, 1], # 万 # 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 # 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 # 4: [2, 2, 0, 0, 0], # 风 # 5: [3, 3, 0, 0], # 箭 # } hand_card.hand_card_info = { 1: [2, 0, 0, 0, 0, 0, 0, 0, 0, 2], # 万 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 4: [0, 0, 0, 0, 0], # 风 5: [0, 0, 0, 0], # 箭 }
def is_this_type(self, hand_card, card_analyse): an_gang_card_vals = hand_card.an_gang_card_vals bu_gang_card_vals = hand_card.bu_gang_card_vals dian_gang_card_vals = hand_card.dian_gang_card_vals ke_lst = [] ke_lst.extend(an_gang_card_vals) ke_lst.extend(bu_gang_card_vals) ke_lst.extend(dian_gang_card_vals) return len(ke_lst) == 3 if __name__ == "__main__": pass card_analyse = CardAnalyse() hand_card = HandCard(0, None) # hand_card.hand_card_info = { # 1: [9, 1, 1, 1, 1, 1, 1, 1, 1, 1], # 万 # 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 # 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 # 4: [2, 2, 0, 0, 0], # 风 # 5: [3, 3, 0, 0], # 箭 # } hand_card.hand_card_info = { 1: [4, 0, 0, 0, 0, 0, 0, 0, 0, 3], # 万 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 条 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 饼 4: [0, 0, 0, 0, 0], # 风 5: [2, 2, 0, 0], # 箭 }