def cmppari(xt, yt): """ 比较两墩对子, :param xt:cards2(后一墩牌) :param yt:, cards1(前一墩牌) :return:x大返回1,y大返回-1 """ number1 = exchange_number(xt) number2 = exchange_number(yt) c11 = count_card(number1, 2)[0] # 取出是对子的那张牌的位数 c12 = count_card(number2, 2)[0] # 双王在手,直接赢 if c11 == 0: return 1 elif c12 == 0: return -1 # 比较对子大小,如若相同,比较单张大小 if cmp(c11, c12) == 0: for i in range(2): number1.remove(c11) number2.remove(c11) c21 = number1[0] c22 = number2[0] if cmp(c21, c22) == 0: # 若单张也相同,则拿到黑桃对者胜 varnum = MAPPING_LIST_NUM[c11] + 'S' if varnum in xt: return 1 if varnum in yt: return -1 return cmp(c21, c22) return cmp(c11, c12) # 如果两个对子不一样,直接就比较大小
def cmpseq(xt, yt): """ 比较两个同花或者同花顺 :param xt:cards2(后一墩牌) :param yt:, cards1(前一墩牌) :return: """ number1 = exchange_number(xt) number2 = exchange_number(yt) # A23为最小的顺子,若相同比较3的花色 if 14 in number1 and 2 in number1: if 14 in number2 and 2 in number2: # 如果都是A23的顺子 return cmpcard(sorted(xt)[1], sorted(yt)[1]) # 2 ,3,14取到3 return -1 if 14 in number2 and 2 in number2: return 1 return cmpcommon(xt, yt) # 都不是123的顺子,用两个类型相同的牌的方法
def pair(pokers): """ #如果有两张牌一样的,则返回true :param pokers: 三张牌 :return: true """ count = exchange_number(pokers) if count_card(count, 2): return True
def seqfull(player): """ 全是顺子的话怎么算奖励分 :param player: 玩家 :return: """ number = exchange_number(player.cards_in_hand) sl = sorted(set(number)) if len(sl) == 9 and ( (sl[-1] - sl[0]) == 8 or (sl[0] == 2 and sl[-1] == 14 and sl[-2] - sl[0] == 7)): player.add_award_score('seqfull', 1)
def seq(pokers): """ 判断是否为顺子 :param pokers: 一墩三张牌 :return: true """ count = exchange_number(pokers) sortcount = sorted(count) # 先进行排序 if (sortcount[2] == sortcount[1] + 1 and sortcount[1] == sortcount[0] + 1) or (sortcount[0] == 2 and sortcount[1] == 3 and sortcount[2] == 14): #23A return True
def boom(player): """ 判断手牌里是否有四张或者两个四张一样的 :param player: 玩家 :return: """ number1 = exchange_number(player.cards_in_hand) if count_card(number1, 4): temp = count_card(number1, 4)[0] # 拿到有4张的那张牌 for i in range(4): number1.remove(temp) # 把4张删掉 if count_card(number1, 4): # 如果还有4张的 player.add_award_score('doubleboom', 2) else: player.add_award_score('boom', 1)
def enter(self, owner): super(DealState, self).enter(owner) cards_rest = init_landlords(owner.conf.play_type) cheat = True cheat_list = [] cheat_tile_list = [] if cheat: # owner.dealer_seat = 2 # dealer = owner.dealer_seat = 0 # name = "poker:lemon:card:cheat:{0}" tile_list = [] # seat = 0 # while seat < owner.chairs: # tile = [] # rounds = 0 # cards_rest.remove("8G") # cards_rest.insert(0,"8G") # while rounds < 31: # tile.append(cards_rest.pop()) # rounds += 1 # tile_list.append(tile) # seat += 1 # tile_list.append( # ["7H", "8H", "7D", "QD", "QH", "QC", "9C", "8D", "AC"]) # tile_list.append( # ['4S', '2S', '5D', '4H', '9H', '6D', 'AC', '8S', '5C']) # tile_list.append( # ['TH']) # tile_list.append( # ['TH']) # tile_list.append( # ['TH']) # tile_list.append(['TH', 'TS', 'TD', 'TC', 'JH', 'JS', 'JD', 'JC','QH', 'QS', 'QD', 'QC','KH', 'KS', 'KD', 'KC', 'AD']) # tile_list.append(['2H', '3H', '4H', '5H', '6H', '7H', '8H', '9H','TH', 'JH', 'QH', 'KH','AH', '2C', '3C', '4C', '5C']) # tile_list.append(['2S', '3S', '4S', '5S', '6S', '7S', '8S', '9S','TS', 'JS', 'QS', 'KS','AS', '6C', '7C', '8C', '9C']) # tile_list.append(['2D', '3D', '4D', '5D', '6D', '7D', '8D', '9D','TD', 'JD', 'QD', 'KD','AD', 'TC', 'JC', 'QC', 'KC']) # for tmpList in cheat_tile_list: # for card in tmpList: # if card in cards_rest: # cards_rest.remove(card) # 在文件cheat_list.txt中读取配牌玩家uuid,并存入数组cheat_list之中 # cheat_list = [] # with open(r'cheat_list', 'r') as file: # for line in file.readlines(): # line = line.strip('\n') # cheat_list.append(line) # 读取redis中cheat_list字段 cheat_list = redis.smembers('cheat_list') # 配牌思路。 # 通过随机数触发配牌概率。配牌时可随机产生一组三条或同花顺。 # 剩下六张牌随机发放 # 最后处理未特殊配牌的玩家 for pre_seat, cheat_player in owner.seat_dict.items(): if cheat_player.uuid in cheat_list: cheat_tile = [] # 所配牌型根据玩家现有分数,分为三个阶段 # 可将配牌概率理解为一个滑动窗口,达到限额时,窗口滑动并改变大小 # 当低于下限时,配三条或同花顺 if cheat_player.total < -owner.player_num * owner.player_num * owner.conf.base_score: rand = randint(0, 3) # 当高于上限时,不启用特殊配牌 elif cheat_player.total > owner.player_num * ( owner.player_num + 4) * owner.conf.base_score: rand = randint(3, 5) # 当高于一定限额,但未达到上限时,不配三条,根据概率配同花顺或者不配 # elif cheat_player.total > owner.player_num * (owner.player_num + 1) * owner.conf.base_score: # rand = randint(3, 6) else: # 初始配牌概率,分数未达到任何限额,三条、同花顺、不配牌都有可能 rand = randint(2, 4) print rand lis = choose_type(rand, cards_rest) cheat_tile.extend(lis) num = exchange_number(lis) has_baozi_number = count_card(num, 3) # 补足配完牌后其他手牌 addnumber = len(cheat_tile) rounds = 0 while rounds < 9 - addnumber: # 处理四条 if len(has_baozi_number) != 0 and cards_rest[-1][ 0] == has_baozi_number[0]: cheat_tile.append(cards_rest.pop(-2)) else: cheat_tile.append(cards_rest.pop()) rounds += 1 cheat_tile_list.append(cheat_tile) # 正常配其他人的牌 seat = len(cheat_tile_list) + len(tile_list) while seat < owner.player_num: tile = [] rounds = 0 while rounds < 9: tile.append(cards_rest.pop()) rounds += 1 tile_list.append(tile) seat += 1 # while seat < owner.chairs: # tile_list.append([int(i) for i in redis.lrange(name.format(seat), 0, -1)]) # seat += 1 # #print tile_list # cards_rest = [int(i) for i in redis.lrange(name.format("rest"), 0, -1)] # print cards_rest else: tile_list = [] seat = 0 while seat < owner.player_num: tile = [] rounds = 0 while rounds < 9: tile.append(cards_rest.pop()) rounds += 1 tile_list.append(tile) seat += 1 owner.replay = { "room_id": owner.room_id, "round": owner.cur_round, "conf": owner.conf.settings, "game_type": 22, "dealer": owner.dealer_seat, "user": {}, "deal": {}, "procedure": [], } log = {} # 发牌 owner.reset_proto(POKER_DEAL) for k, player in owner.seat_dict.items(): if player.uuid in cheat_list: player.cards_in_hand = sorted(cheat_tile_list.pop(0), cmp=cmpcard) else: player.cards_in_hand = sorted(tile_list.pop(0), cmp=cmpcard) log[str(k)] = player.cards_in_hand proto = game_pb2.CockDealResponse() for c in player.cards_in_hand: card = proto.cards_in_hand.add() card.card = c player.proto.p = copy(proto) owner.replay["user"][k] = (player.uuid, player.info) owner.replay["deal"][k] = copy(player.cards_in_hand) player.machine.trigger(PlayerDealState()) owner.logger.info(log) owner.dumps()
def baozi(pokers): count = exchange_number(pokers) if len(set(count)) == 1: return True