def can_win(self, handTiles, finalTile, win_op, idx): # 平胡 十三不搭 财神头 飘财 双飘 杠上开花 # 庄9闲7 放炮胡 +1 自摸 *2 财神头 *4 单飘 *8 双飘 *16 三飘 *16 result = [0] * 6 # 胡牌类型 if len(handTiles) % 3 != 2: return False, 0, result if win_op == const.OP_WREATH_WIN: return False, 0, result if self.is_op_limit(idx, win_op, finalTile): return False, 0, result # 自摸 抢杠胡算自摸 is_draw_win = win_op == const.OP_DRAW_WIN or win_op == const.OP_KONG_WIN # 杠开 can_kong_win = False # 财神头 isBaoTou = False handKingTileNum = 0 for t in self.kingTiles: handKingTileNum = max(handKingTileNum, handTiles.count(t)) p = self.players_list[idx] max_discard_king = max(self.discard_king_total) idx_discard_king_num = self.discard_king_total[idx] can_kong_win, kong_win_type = utility.checkIsKongDrawWin(p.op_r) def match_win(baotou): if max_discard_king == 0: if handKingTileNum == 2: multiply = 0 if is_draw_win: if baotou or can_kong_win: multiply += 2 else: multiply += 1 return True, multiply return False, 0 elif handKingTileNum > 2: if baotou or can_kong_win: return True, 2 return False, 0 else: multiply = 0 if is_draw_win: if baotou or can_kong_win: multiply += 2 else: multiply += 1 return True, multiply elif max_discard_king == 1: if is_draw_win: if idx_discard_king_num == 1: if baotou: return True, 3 else: return False, 0 else: return True, 2 if baotou or can_kong_win else 1 else: return False, 0 else: if idx_discard_king_num > 1: if is_draw_win and baotou: return True, 4 else: return False, 0 else: if can_kong_win or baotou: return True, 2 else: return False, 0 if max_discard_king == 1: if win_op != const.OP_DRAW_WIN and win_op != const.OP_KONG_WIN: return False, 0, result elif max_discard_king > 1: if idx_discard_king_num > 1: if win_op != const.OP_DRAW_WIN: return False, 0, result # elif not can_kong_win: # # 不双飘的需要杠开 # return False, 0, result handCopyTiles = list(handTiles) kings, handTilesButKing = utility.classifyWindTiles( handCopyTiles, self.kingTiles) kingTilesNum = len(kings) # 百搭的数量 tmp_can_win, tmp_quantity = match_win(False) if tmp_can_win: if utility.get13Mismatch(handCopyTiles, self.kingTiles): if tmp_can_win: # result[3] = 1 result[0] = 1 return True, tmp_quantity, result else: return False, 0, result is7Double, isBaoTou, kongNum = utility.checkIs7Pair( handCopyTiles, handTilesButKing, kingTilesNum, self.kingTiles, finalTile) # isBaoTou &= win_op == const.OP_DRAW_WIN # 财神头必须自摸 if is7Double: can_win, quantity = match_win(isBaoTou & (win_op == const.OP_DRAW_WIN)) if can_win and (not isBaoTou or (isBaoTou and win_op == const.OP_DRAW_WIN)): # result[1] = 1 if idx_discard_king_num == 1: result[3] = 1 elif idx_discard_king_num > 1: result[4] = 1 else: if can_kong_win or isBaoTou: if isBaoTou: result[2] = 1 if can_kong_win: result[5] = 1 else: result[0] = 1 return True, quantity, result if idx_discard_king_num > 0 and kingTilesNum == 0: WARNING_MSG( '{} impossible: max_discard_king > 0 and hand king == 0: idx:{}, {}' .format(self.prefixLogStr, idx, self.discard_king_total)) return False, 0, result # 白板代替财神 if self.king_mode == const.KING_MODE_RANDOM: handTilesButKing = list( map( lambda x: self.kingTiles[0] if x == const.DRAGON_WHITE else x, handTilesButKing)) insteadFinalTile = self.kingTiles[ 0] if finalTile == const.DRAGON_WHITE else finalTile else: insteadFinalTile = finalTile if kingTilesNum > 0: if finalTile in self.kingTiles: if handCopyTiles.count(finalTile) >= 2: need_king = utility.winWith3NNeedKing(handTilesButKing) isBaoTou = kingTilesNum - 2 >= need_king else: isBaoTou = False else: tmp = handTilesButKing[:] tmp.remove(insteadFinalTile) need_king = utility.winWith3NNeedKing(tmp) isBaoTou = kingTilesNum - 1 >= need_king else: isBaoTou = False # isBaoTou &= (win_op == const.OP_DRAW_WIN) # 财神头必须自摸或抢杠胡 can_win, quantity = match_win(isBaoTou & (win_op == const.OP_DRAW_WIN)) if can_win: if kingTilesNum == 0: if utility.canWinWithoutKing(handTilesButKing): if idx_discard_king_num == 1: result[3] = 1 elif idx_discard_king_num > 1: result[4] = 1 else: if isBaoTou and win_op != const.OP_DRAW_WIN: return False, 0, result if can_kong_win or isBaoTou: if isBaoTou: result[2] = 1 if can_kong_win: result[5] = 1 else: result[0] = 1 return True, quantity, result return False, 0, result else: if utility.winWith3N2NeedKing( handTilesButKing) <= kingTilesNum: if idx_discard_king_num == 1: result[3] = 1 elif idx_discard_king_num > 1: result[4] = 1 else: if isBaoTou and win_op != const.OP_DRAW_WIN: return False, 0, result if can_kong_win or isBaoTou: if isBaoTou: result[2] = 1 if can_kong_win: result[5] = 1 else: result[0] = 1 return True, quantity, result return False, 0, result return False, 0, result
def can_win(self, handTiles, finalTile, win_op, idx): DEBUG_MSG("check can win:{}".format(idx)) victory_value = 0 result = [0] * 12 if const.DRAGON_GREEN in handTiles: return False, victory_value, result if win_op == const.OP_GIVE_WIN and self.players_list[idx].pass_dealer[ 0]: # 没过庄不能胡 return False, victory_value, result p = self.players_list[idx] copyHandTiles = handTiles[:] copyHandTiles = sorted(copyHandTiles) tile2NumDict = utility.getTile2NumDict(handTiles) # 杠子 kongNum = sum([1 for meld in p.upTiles if len(meld) == 4]) # 门前清 pongExposedKongNum = sum([ 1 for player_op in p.op_r if player_op[0] == const.OP_EXPOSED_KONG ]) pongExposedKongNum += sum([1 for meld in p.upTiles if len(meld) <= 3]) # 发财数量 dragonGreenNum = len(p.dragon_greens) # 7对 if utility.checkIs7Pair(copyHandTiles): #**********1炮************* # 平胡 result[0] = 1 victory_value += 1 DEBUG_MSG("PingHu victory_value:{0}".format(victory_value)) DEBUG_MSG("平胡") # 自摸 if win_op == const.OP_DRAW_WIN: result[1] = 1 victory_value += 1 DEBUG_MSG("ZiMo victory_value:{0}".format(victory_value)) DEBUG_MSG("自摸") #**********2炮************* # 手抓 3 红中/白板 if const.DRAGON_RED in tile2NumDict and tile2NumDict[ const.DRAGON_RED] >= 3: victory_value += 2 DEBUG_MSG( "SanHongZhong victory_value:{0}".format(victory_value)) DEBUG_MSG("手抓 3 红中") if const.DRAGON_WHITE in tile2NumDict and tile2NumDict[ const.DRAGON_WHITE] >= 3: victory_value += 2 DEBUG_MSG("SanBaiBan victory_value:{0}".format(victory_value)) DEBUG_MSG("手抓 3 白板") #**********5炮************* # 抢杠 if win_op == const.OP_KONG_WIN: result[4] = 1 victory_value += 5 DEBUG_MSG("QiangGang victory_value:{0}".format(victory_value)) DEBUG_MSG("抢杠") # 流泪 if win_op == const.OP_GIVE_WIN and utility.checkIsKongDiscard( self.players_list[self.last_player_idx].op_r): result[5] = 1 victory_value += 5 DEBUG_MSG("LiuLei victory_value:{0}".format(victory_value)) DEBUG_MSG("流泪") #**********7炮************* # 7对 result[6] = 1 victory_value += 7 DEBUG_MSG("QiDui victory_value:{0}".format(victory_value)) DEBUG_MSG("7对") #**********8炮************* # 4发财 if dragonGreenNum == 4: result[7] = 1 victory_value += 8 DEBUG_MSG("SiFangCai victory_value:{0}".format(victory_value)) DEBUG_MSG("4发财") else: victory_value += dragonGreenNum DEBUG_MSG("FangCai victory_value:{0}".format(victory_value)) DEBUG_MSG("发财") #**********10炮************* # 清一色 if utility.checkIsSameSuit(handTiles, p.upTiles): result[8] = 1 victory_value += 10 DEBUG_MSG("QingYiSe victory_value:{0}".format(victory_value)) DEBUG_MSG("清一色") DEBUG_MSG("can win, True, 111, {0}:{1},{2}".format( idx, victory_value, result)) return True, victory_value, result # 3x+2 elif len(copyHandTiles) % 3 == 2 and utility.meld_with_pair_need_num( copyHandTiles, {}) <= 0: # 平胡 result[0] = 1 victory_value += 1 DEBUG_MSG("PingHu victory_value:{0}".format(victory_value)) DEBUG_MSG("平胡") # 全求人 if len(copyHandTiles) == 2 and win_op != const.OP_DRAW_WIN: result[11] = 1 victory_value += 10 DEBUG_MSG("QuanQiuRen victory_value:{0}".format(victory_value)) DEBUG_MSG("全求人") else: #**********1炮************* tipsList = self.getNormalTipsWinList(copyHandTiles, finalTile) if len(tipsList) == 1: victory_value += 1 DEBUG_MSG( "DiaoDanZhang victory_value:{0}".format(victory_value)) result[2] = 1 DEBUG_MSG("胡单张") #**********5炮************* # 碰碰胡 if utility.checkIsPongPongWin(handTiles, p.upTiles): result[9] = 1 victory_value += 5 DEBUG_MSG( "PengPengHu victory_value:{0}".format(victory_value)) DEBUG_MSG("碰碰胡") #**********1炮************* # 自摸 if win_op == const.OP_DRAW_WIN: result[1] = 1 victory_value += 1 DEBUG_MSG("ZiMo victory_value:{0}".format(victory_value)) DEBUG_MSG("自摸") # if len(copyHandTiles) > 2: # # 单张吊 # removePairTiles = utility.getRemoveFinalPairTiles(copyHandTiles, finalTile) # if len(removePairTiles) > 0 and utility.meld_only_need_num(removePairTiles, {}) <= 0: # victory_value += 1 # else: # # 卡张 # removeMidTiles = utility.getRemoveFinalMidTiles(copyHandTiles, finalTile) # if len(removeMidTiles) > 0 and and utility.meld_with_pair_need_num(removeMidTiles, {}) <= 0: # victory_value += 1 # 门前清 if pongExposedKongNum <= 0: result[3] = 1 victory_value += 1 DEBUG_MSG( "MenQianQing victory_value:{0}".format(victory_value)) DEBUG_MSG("门前清") # 碰红中/白板 victory_value += sum([i for i in p.pongList]) DEBUG_MSG( "PengBaiBan/HongZhong victory_value:{0}".format(victory_value)) DEBUG_MSG("碰红中/白板") # 明杠(不包括红中/白板) victory_value += p.exposedKongList[0] DEBUG_MSG("MingGang(WuBaiBan/HongZhong) victory_value:{0}".format( victory_value)) DEBUG_MSG("明杠") #**********2炮************* # 手抓 3 红中/白板 if const.DRAGON_RED in tile2NumDict and tile2NumDict[ const.DRAGON_RED] >= 3: victory_value += 2 DEBUG_MSG( "SanHongZhong victory_value:{0}".format(victory_value)) DEBUG_MSG("手抓 3 红中") if const.DRAGON_WHITE in tile2NumDict and tile2NumDict[ const.DRAGON_WHITE] >= 3: victory_value += 2 DEBUG_MSG("SanBaiBan victory_value:{0}".format(victory_value)) DEBUG_MSG("手抓 3 白板") # 暗杠 不包括 红中/白板 victory_value += 2 * p.concealedKongList[0] DEBUG_MSG("AnGang(WuBaiBan/HongZhong) victory_value:{0}".format( victory_value)) DEBUG_MSG("暗杠 不包括 红中/白板") #**********3炮************* # 明杠 红中/白板 victory_value += 3 * p.exposedKongList[1] victory_value += 3 * p.exposedKongList[2] DEBUG_MSG("MingGang victory_value:{0}".format(victory_value)) DEBUG_MSG("明杠 红中/白板") #**********4炮************* # 暗杠 红中/白板 victory_value += 4 * p.concealedKongList[1] victory_value += 4 * p.concealedKongList[2] DEBUG_MSG("AnGang victory_value:{0}".format(victory_value)) DEBUG_MSG("暗杠 红中/白板") #**********5炮************* # 抢杠 if win_op == const.OP_KONG_WIN: result[4] = 1 victory_value += 5 DEBUG_MSG( "QiangGangHu victory_value:{0}".format(victory_value)) DEBUG_MSG("抢杠") # 杠开 if win_op == const.OP_DRAW_WIN and utility.checkIsKongDrawWin( p.op_r): result[10] = 1 victory_value += 5 DEBUG_MSG("GangKai victory_value:{0}".format(victory_value)) DEBUG_MSG("杠开") # 流泪 if win_op == const.OP_GIVE_WIN and utility.checkIsKongDiscard( self.players_list[self.last_player_idx].op_r): result[5] = 1 victory_value += 5 DEBUG_MSG("LiuLei victory_value:{0}".format(victory_value)) DEBUG_MSG("流泪") #**********8炮************* # 4发财 if dragonGreenNum == 4: result[7] = 1 victory_value += 8 DEBUG_MSG("SiFaCai victory_value:{0}".format(victory_value)) DEBUG_MSG("4发财") else: victory_value += dragonGreenNum DEBUG_MSG("FaCai victory_value:{0}".format(victory_value)) DEBUG_MSG("发财") #**********10炮************* # 清一色 if utility.checkIsSameSuit(handTiles, p.upTiles): result[8] = 1 victory_value += 10 DEBUG_MSG("QingYiSe victory_value:{0}".format(victory_value)) DEBUG_MSG("清一色") DEBUG_MSG("can win:{0},{1}".format(victory_value, result)) # 一炮不能抓炮胡 if victory_value <= 1: DEBUG_MSG("can win,False 222,{0}:{1},{2}".format( idx, victory_value, result)) return False, victory_value, result DEBUG_MSG("can win,True 333,{0}:{1},{2}".format( idx, victory_value, result)) return True, victory_value, result DEBUG_MSG("can win,False 444,{0}:{1},{2}".format( idx, victory_value, result)) return False, victory_value, result
def can_win(self, handTiles, finalTile, win_op, idx): # 平胡 卡张 碰碰胡 全求人 7对 豪7 双豪7 三豪7 清一色 字一色 乱风 杠开 天胡 地胡 result = [0] * 14 #胡牌类型 quantity = 0 if len(handTiles) % 3 != 2: return False, quantity, result p = self.players_list[idx] handCopyTiles = list(handTiles) handCopyTiles = sorted(handCopyTiles) classifyList = utility.classifyTiles(handCopyTiles, self.kingTiles) kingTilesNum = len(classifyList[0]) #百搭的数量 handTilesButKing = [] #除百搭外的手牌 for i in range(1, len(classifyList)): handTilesButKing.extend(classifyList[i]) upTiles = p.upTiles # 清一色 字一色 colorType = utility.getTileColorType(handTilesButKing, upTiles) # 7对 is7Double, isBrightTiles, isDarkTiles = utility.get7DoubleWin( handCopyTiles, handTilesButKing, kingTilesNum, finalTile) # 获得所有能胡的牌的列表 tmpTiles = list(handTiles) tmpTiles.remove(finalTile) canWinList = utility.getCanWinTiles(tmpTiles) isCanWin = False if is7Double: isCanWin = True quantity += 4 tile2NumDict = utility.getTile2NumDict(handTilesButKing) if colorType == const.SAME_SUIT: quantity += 4 result[8] = 1 elif colorType == const.SAME_HONOR: quantity += 4 result[9] = 1 mul = 0 for t in tile2NumDict: if tile2NumDict[t] == 4: mul += 1 quantity *= 2**mul result[4 + mul] = 1 elif finalTile in canWinList: isPongPongWin = utility.checkIsPongPongWin(handTilesButKing, upTiles, kingTilesNum) isKongWin, kongWinType = utility.checkIsKongDrawWin(p.op_r) if isPongPongWin: # 碰碰胡 quantity += 3 result[2] = 1 # 全求人 if len(handCopyTiles) == 2: quantity += 2 result[3] = 1 #清一色/字一色 if colorType == const.SAME_SUIT: quantity += 4 result[8] = 1 elif colorType == const.SAME_HONOR: quantity += 4 result[9] = 1 # 杠开 if win_op == const.OP_DRAW_WIN and isKongWin: quantity *= 2 result[11] = 1 isCanWin = True elif len(canWinList) == 1: # 卡张 quantity += 2 result[1] = 1 #清一色 --不可能是字一色,字一色必须是碰碰胡 if colorType == const.SAME_SUIT: quantity += 4 result[8] = 1 # 杠开 if win_op == const.OP_DRAW_WIN and isKongWin: quantity *= 2 result[11] = 1 isCanWin = True else: #平胡 --不可能是字一色,字一色必须是碰碰胡 quantity += 1 result[0] = 1 #清一色/字一色 if colorType == const.SAME_SUIT: # 清一色 quantity += 4 result[8] = 1 # 杠开 if win_op == const.OP_DRAW_WIN and isKongWin: quantity *= 2 result[11] = 1 isCanWin = True elif win_op == const.OP_DRAW_WIN: # 平胡 非 清一色/字一色只能自摸 # 杠开 if win_op == const.OP_DRAW_WIN and isKongWin: quantity *= 2 result[11] = 1 isCanWin = True elif win_op == const.OP_KONG_WIN: isCanWin = True elif colorType == const.SAME_HONOR: quantity += 5 result[10] = 1 isCanWin = True # 天胡 地胡 if isCanWin: if idx == self.dealer_idx and len( self.all_discard_tiles ) <= 0 and win_op == const.OP_DRAW_WIN: result[12] = 1 quantity = 40 elif len(self.all_discard_tiles ) == 1 and win_op == const.OP_GIVE_WIN: result[13] = 1 quantity = 40 return isCanWin, quantity, result
def can_win(self, handTiles, finalTile, win_op, idx): p = self.players_list[idx] canWin, result, winMul = False, [0] * 9, 0 result[0] = win_op if p.raceHorse and win_op == const.OP_GIVE_WIN and win_op == const.OP_KONG_WIN: #跑马必须自摸胡 return canWin, result, winMul if len(handTiles) % 3 == 2: classifyList = utility.classifyTiles(handTiles, self.kingTiles) # 财神 curKingTiles = classifyList[0] # 白板 curDragonWhite = classifyList[1] # 非财神 handTilesButKing = [] for i in range(1, len(classifyList)): handTilesButKing.extend(classifyList[i]) # 非白板 handTilesButWhite = [] handTilesButWhite.extend(classifyList[0]) for i in range(2, len(classifyList)): handTilesButWhite.extend(classifyList[i]) # 非财神 非白板 handTilesButKingWhite = [] for i in range(2, len(classifyList)): handTilesButKingWhite.extend(classifyList[i]) #/****************检查胡******************/ '''三财神''' if len(curKingTiles) == 3: canWin = True result[1] = 1 #至少两倍 winMul = 2 # 天胡 if win_op == const.OP_DRAW_WIN and idx == self.dealer_idx and len(self.op_record) == 1: result[3] = 1 winMul = 4 if winMul < 4 else winMul # 地胡 discardNum = 0 for i in range(0, len(self.op_record))[::-1]: if self.op_record[i][1] != self.dealer_idx: discardNum = 0 break if discardNum > 1: break if self.op_record[i][0] == const.OP_DISCARD: discardNum += 1 if win_op == const.OP_GIVE_WIN and idx != self.dealer_idx and discardNum == 1: result[4] = 1 winMul = 4 if winMul < 4 else winMul #抢杠胡 算硬胡 if win_op == const.OP_KONG_WIN: result[7] = 1 winMul = 2 if winMul < 2 else winMul '''八对''' if len(handTiles) == 17 and utility.checkIs8Pairs(handTilesButKing, len(curKingTiles)): canWin = True result[2] = 1 # 倍数相关 # 软8对 硬8对 if len(curKingTiles) > 0: if utility.checkIs8Pairs(handTiles, 0): # 硬8对(有财神 且归位) winMul = 4 result[7] = 1 else: # 软8对(有财神 且不归位) winMul = 2 else: winMul = 4 # 硬8对(无财神) result[7] = 1 # 自摸 if win_op == const.OP_DRAW_WIN: winMul = 2 if winMul < 2 else winMul # 三财神 if result[1] == 1: winMul = 4 if winMul < 4 else winMul # 天胡 if win_op == const.OP_DRAW_WIN and idx == self.dealer_idx and len(self.op_record) == 1: result[3] = 1 winMul = 4 if winMul < 4 else winMul # 地胡 discardNum = 0 for i in range(0, len(self.op_record))[::-1]: if self.op_record[i][1] != self.dealer_idx: discardNum = 0 break if discardNum > 1: break if self.op_record[i][0] == const.OP_DISCARD: discardNum += 1 if win_op == const.OP_GIVE_WIN and idx != self.dealer_idx and discardNum == 1: result[4] = 1 winMul = 4 if winMul < 4 else winMul elif utility.canNormalWin(handTilesButKingWhite, self.kingTiles[0], len(curKingTiles), len(curDragonWhite)): '''非八对''' canWin = True winMul = 1 if winMul < 1 else winMul # 自摸 if win_op == const.OP_DRAW_WIN: winMul = 2 if winMul < 2 else winMul # 三财神 if len(curKingTiles) == 3: winMul = 4 if winMul < 4 else winMul # 天胡 if win_op == const.OP_DRAW_WIN and idx == self.dealer_idx and len(self.op_record) == 1: result[3] = 1 winMul = 4 if winMul < 4 else winMul # 地胡 discardNum = 0 for i in range(0, len(self.op_record))[::-1]: if self.op_record[i][1] != self.dealer_idx: discardNum = 0 break if discardNum > 1: break if self.op_record[i][0] == const.OP_DISCARD: discardNum += 1 if win_op == const.OP_GIVE_WIN and idx != self.dealer_idx and discardNum == 1: result[4] = 1 winMul = 4 if winMul < 4 else winMul # 杠上开花 if win_op == const.OP_DRAW_WIN and utility.checkIsKongDrawWin(p.op_r): result[5] = 1 if self.kong_draw_win_double: winMul = 4 if winMul < 4 else winMul else: winMul = 2 if winMul < 2 else winMul # 财神单吊(全球神) if win_op == const.OP_GIVE_WIN and self.last_player_idx == idx and len(handTiles) == 2 and (handTiles[0] != handTiles[-1] or handTiles[0] in self.kingTiles): result[6] = 1 winMul = 4 if winMul < 4 else winMul # 没有财神 或者 财神归位 if win_op == const.OP_KONG_WIN or len(curKingTiles) <= 0 or utility.canNormalWin(handTilesButWhite, self.kingTiles[0], 0, len(curDragonWhite)): result[7] = 1 winMul = 2 if winMul < 2 else winMul # 碰碰胡 if utility.checkIsPongPongWin(handTilesButKing, p.upTiles, len(curKingTiles)): result[8] = 1 winMul = 4 if winMul < 4 else winMul DEBUG_MSG("can_win==>:{0},{1},{2}".format(canWin, str(result), str(winMul))) return canWin, result, winMul
def getCanWinQuantity (self, handTiles, uptiles, wreaths, finalTile, p_op_r, p_wind, win_op, idx ,isDrawWin, isGunWin): #测试样例 # self.kingTiles = [1] # handTiles = [12,13,14,16,16,23,24] # uptiles = [[5,6,7],[7,8,9]] # wreaths = [41,44] # finalTile = 25 # p_op_r = [(1,[23],1),(3,[34],1),(4,[23,24,25],1)] # p_wind = 31 # win_op = 15 # idx = 1 # isDrawWin = True DEBUG_MSG("handTiles : {0}, uptiles: {1}, wreaths: {2} , finalTile: {3}".format(handTiles, uptiles, wreaths, finalTile)) DEBUG_MSG("p_op_r: {0}, p_wind: {1}, win_op: {2}, idx: {3}, isDrawWin: {4}".format(p_op_r, p_wind, win_op, idx ,isDrawWin)) result = [0] * 47 #胡牌类型 handTiles = sorted(handTiles) classifyList = utility.classifyTiles(handTiles, self.kingTiles) kingTilesNum = len(classifyList[0]) #百搭的数量 handTilesButKing = [] #除百搭外的手牌 kingDict = utility.getTile2NumDict(classifyList[0]) #百搭的dict isGiveWin = False #是否能放炮胡 isSelfWin = False #是否自摸 isHunadaWin = False # 是否是还搭 kongType = 0 #杠开的类型 0:不是杠开 1:直杠或暗杠杠开 2:风险杠杠开 for i in range(1, len(classifyList)): handTilesButKing.extend(classifyList[i]) def removeCheckPairWin(handTilesButKing, removeTuple, useKingNum, kingTilesNum): if useKingNum <= kingTilesNum: tryHandTilesButKing = handTilesButKing[:] tryHandTilesButKing = sorted(tryHandTilesButKing) for t in removeTuple: if t != -1: try: tryHandTilesButKing.remove(t) except: DEBUG_MSG("removeCheckPairWin remove fail.{0},{1}".format(removeTuple, tryHandTilesButKing)) if utility.meld_with_pair_need_num(tryHandTilesButKing, {}) <= kingTilesNum - useKingNum: return True return False def removeCheckOnlyWin(handTilesButKing, removeTuple, useKingNum, kingTilesNum): if useKingNum <= kingTilesNum: tryHandTilesButKing = handTilesButKing[:] tryHandTilesButKing = sorted(tryHandTilesButKing) for t in removeTuple: if t != -1: try: tryHandTilesButKing.remove(t) except: DEBUG_MSG("removeCheckOnlyWin remove fail.{0},{1}".format(removeTuple, tryHandTilesButKing)) if utility.meld_only_need_num(tryHandTilesButKing, {}) <= kingTilesNum - useKingNum: return True return False #显示杠的类型 for i in range(0, len(p_op_r))[::-1]: if p_op_r[i][0] == const.OP_CONCEALED_KONG: result[36] = 1 elif p_op_r[i][0] == const.OP_EXPOSED_KONG: result[34] = 1 elif p_op_r[i][0] == const.OP_RISK_KONG: result[38] = 1 quantity = 0 #分数 stand = 1 #台数 坐台为一台 result[16] = 1 DEBUG_MSG("zuotai: 1") if win_op == const.OP_WREATH_WIN:#8张花 if len(wreaths) == 8: # 8张花胡 = 8张花(14台) + 胡(8台) = 22台 quantities, stands= utility.getWreathQuantity(wreaths, p_wind) quantity += quantities stand += stands result[33] = 1 DEBUG_MSG("wreaths quantity:{0}, stand: {1}".format(quantities, stands)) elif len(handTiles) % 3 == 2: #其他 3x+2 胡 #抛百搭不能放炮胡 if isGunWin and kingTilesNum > 0 and len(self.tiles) > 0: if utility.getCheckWinThorw(handTiles, finalTile, self.kingTiles): DEBUG_MSG("pao baida buneng fangpao hu ") return False, 0, 0, 0, 0 #七对头 注:需要判断finalTile最后一张牌是别人的还是自己的 is7Double, isBrightTiles, isDarkTiles = utility.get7DoubleWin(handTiles, handTilesButKing, kingTilesNum, finalTile) starType = utility.getStarType(handTilesButKing, kingDict, finalTile, isDrawWin) if utility.getTileColorType(handTilesButKing, uptiles) == const.SAME_HONOR and (utility.meld_with_pair_need_num(handTilesButKing, {}) <= kingTilesNum or is7Double): quantity += 1000 result[0] = 1 # 清老头 DEBUG_MSG("qing laotou: 1000") if is7Double: if kingTilesNum > 0: quantity += 70 #七对头有搭 result[8] = 1 DEBUG_MSG("qiduitou youda: 70") else: quantity += 170 #七对头无搭 result[8] = 1 DEBUG_MSG("qiduitou wuda: 170") if isBrightTiles: quantity += 50 #明炸七对头 result[26] = 1 DEBUG_MSG("mingzha qiduitou: 50") if isDarkTiles: quantity += 100 #暗炸七对头 result[27] = 1 DEBUG_MSG("anzha qiduitou: 100") # 天胡 地胡 drawNum = utility.getDiscardNum(self.op_record) if drawNum == 1 and len(handTiles) == 14: if self.dealer_idx == idx: quantity += 150 result[6] = 1 #天胡 DEBUG_MSG("tian hu: 150") else: quantity += 150 result[7] = 1 #地胡 isSelfWin = True DEBUG_MSG("di hu: 150") isGiveWin = True isSelfWin = True elif is7Double: if kingTilesNum > 0: quantity += 70 #七对头有搭 result[8] = 1 DEBUG_MSG("qiduitou youda: 70") else: quantity += 170 #七对头无搭 result[8] = 1 DEBUG_MSG("qiduitou wuda: 170") if isBrightTiles: quantity += 50 #明炸七对头 result[26] = 1 DEBUG_MSG("mingzha qiduitou: 50") if isDarkTiles: quantity += 100 #暗炸七对头 result[27] = 1 DEBUG_MSG("anzha qiduitou: 100") #清一色 混一色 colorType = utility.getTileColorType(handTilesButKing, uptiles) if colorType == const.SAME_SUIT: quantity += 150 result[4] = 1 isGiveWin = True DEBUG_MSG("qing yi se 150") elif colorType == const.MIXED_ONE_SUIT: quantity += 70 result[5] = 1 isGiveWin = True DEBUG_MSG("hun yi se: 70") # 天胡 地胡 drawNum = utility.getDiscardNum(self.op_record) if drawNum == 1 and len(handTiles) == 14: if self.dealer_idx == idx: quantity += 150 result[6] = 1 #天胡 DEBUG_MSG("tian hu: 150") else: quantity += 150 result[7] = 1 #地胡 isSelfWin = True DEBUG_MSG("di hu: 150") isGiveWin = True isSelfWin = True elif len(starType) != 0: if starType[0] == 0: quantity += 50 #十三不搭 DEBUG_MSG("shisan buda: 50") elif starType[0] == 1: quantity += 200 result[30] = 1 # 十三不搭缺色 DEBUG_MSG("shisan buda quese: 200") elif starType[0] == 2: quantity += 150 result[28] = 1 # 十三不搭暗七星 DEBUG_MSG("shisan buda anqixing: 150") elif starType[0] == 3: quantity += 100 result[29] = 1 # 十三不搭明七星 DEBUG_MSG("shisan buda mingqixing: 100") elif starType[0] == 4: quantity += 300 result[28] = 1 result[30] = 1 # 十三不搭暗7星 缺色 DEBUG_MSG("shisan buda: 300") elif starType[0] == 5: quantity += 250 result[29] = 1 result[30] = 1 # 十三不搭明7星 缺色 DEBUG_MSG("shisan buda: 250") result[9] = 1 # 天胡 地胡 drawNum = utility.getDiscardNum(self.op_record) if drawNum == 1 and len(handTiles) == 14: if self.dealer_idx == idx: quantity += 150 result[6] = 1 #天胡 DEBUG_MSG("tian hu: 150") else: quantity += 150 result[7] = 1 #地胡 isSelfWin = True DEBUG_MSG("di hu: 150") isGiveWin = True isSelfWin = True elif utility.getAllColorType(uptiles, handTilesButKing): quantity += 500 result[1] = 1 # 乱老头 DEBUG_MSG("luan laotou: 500") # 天胡 地胡 drawNum = utility.getDiscardNum(self.op_record) if drawNum == 1 and len(handTiles) == 14: if self.dealer_idx == idx: quantity += 150 result[6] = 1 #天胡 DEBUG_MSG("tian hu: 150") else: quantity += 150 result[7] = 1 #地胡 isSelfWin = True DEBUG_MSG("di hu: 150") isGiveWin = True isSelfWin = True elif utility.meld_with_pair_need_num(handTilesButKing, {}) <= kingTilesNum: # 碰碰胡? isPongPongWin = utility.checkIsPongPongWin(handTilesButKing, uptiles, kingTilesNum) if isPongPongWin: if kingTilesNum > 0: quantity += 50 else: quantity += 100 result[2] = 1 isGiveWin = True DEBUG_MSG("peng peng hu: 50+") # 天胡 地胡 drawNum = utility.getDiscardNum(self.op_record) if drawNum == 1 and len(handTiles) == 14: if self.dealer_idx == idx: quantity += 150 result[6] = 1 #天胡 DEBUG_MSG("tian hu: 150") else: quantity += 150 result[7] = 1 #地胡 isSelfWin = True DEBUG_MSG("di hu: 150") # 自摸 if isDrawWin: stand += 1 result[15] = 1 isSelfWin = True DEBUG_MSG("zi mo: 1") # 抢杠胡 if win_op == const.OP_KONG_WIN: isSelfWin = True # 杠上开花 isKongWin, kongWinType = utility.checkIsKongDrawWin(p_op_r) # 连杠开花 isSeriesKongWin = utility.checkIsSeriesKongWin(p_op_r) if win_op == const.OP_DRAW_WIN and isSeriesKongWin > 0: if isSeriesKongWin == 1: quantity += 300 kongType = 3 DEBUG_MSG("liangge angang gangkai 300") elif isSeriesKongWin == 2: quantity += 350 kongType = 3 DEBUG_MSG("angang,fengxiangang gangkai 350") elif isSeriesKongWin == 3: quantity += 300 kongType = 4 DEBUG_MSG("zhigang,fengxiangang gangkai 300") elif isSeriesKongWin == 4: quantity += 400 kongType = 3 DEBUG_MSG("liangge fengxinagang gangkai 400") result[46] = 1 elif win_op == const.OP_DRAW_WIN and isKongWin: if kongWinType == 1: quantity += 150 result[37] = 1 kongType = 1 DEBUG_MSG("angang gang kai 50+") elif kongWinType == 2: quantity += 100 result[35] = 1 kongType = 1 DEBUG_MSG("zhigang gang kai 50+") elif kongWinType == 3: quantity += 50 result[41] = 1 DEBUG_MSG("huagang gang kai 50+") elif kongWinType == 4: quantity += 200 result[39] = 1 kongType = 2 DEBUG_MSG("fengxian gang kai 50+") # #海捞 if len(self.tiles) <= 0: quantity += 150 result[10] = 1 isGiveWin = True DEBUG_MSG("haidi lao yue 150") #大吊车 if len(handTiles) == 2: if kingTilesNum > 0: quantity += 50 else: quantity += 100 result[3] = 1 isGiveWin = True DEBUG_MSG("da diao che 50+") #清一色 混一色 colorType = utility.getTileColorType(handTilesButKing, uptiles) if colorType == const.SAME_SUIT: quantity += 150 result[4] = 1 isGiveWin = True DEBUG_MSG("qing yi se 150") elif colorType == const.MIXED_ONE_SUIT: quantity += 70 result[5] = 1 isGiveWin = True DEBUG_MSG("hun yi se: 70") # 座风三个为一台 sit_wind = const.WINDS[(idx - self.dealer_idx + 4) % 4]; isSitWind = utility.checkIsSitWind(sit_wind, uptiles, handTiles, handTilesButKing, kingTilesNum, self.kingTiles) if isSitWind > 0: if self.game_mode == 0: stand += 2 elif self.game_mode == 1: stand += 1 result[25] = 1 isGiveWin = True DEBUG_MSG("zuo feng: 1 or 2") # 判断是否有东风碰出暗刻 if self.game_mode == 0: isEastWind = utility.checkIsEastWind(const.WIND_EAST, uptiles, handTiles, handTilesButKing, kingTilesNum, self.kingTiles) if isEastWind > 0 and sit_wind != const.WIND_EAST: stand += 1 isGiveWin = True DEBUG_MSG("dongfeng pengchu: 1") # 中发白 isWordColor, dragon_type = utility.checkIsWordColor(uptiles, handTiles, handTilesButKing, kingTilesNum, self.kingTiles) if isWordColor > 0: stand += 1 isGiveWin = True if dragon_type[0] == 1: result[17] = 1 if dragon_type[1] == 1: result[18] = 1 if dragon_type[2] == 1: result[19] = 1 DEBUG_MSG("zhong fa bai: 1") #平打里面的圈风 if self.game_mode == 1: isCircleWind = utility.checkIsSitWind(self.prevailing_wind, uptiles, handTiles, handTilesButKing, kingTilesNum, self.kingTiles) if isCircleWind > 0 : stand += 1 DEBUG_MSG("quan feng: 1") # 还搭 抛百搭 朋胡 friend_win = False if kingTilesNum > 0 and kingTilesNum < 3: # 还搭 抛百搭 DEBUG_MSG("============ {0}, {1}".format(utility.meld_with_pair_need_num(handTilesButKing, {}), kingTilesNum)) if utility.meld_with_pair_need_num(handTilesButKing, {}) < kingTilesNum: stand += 1 result[24] = 1 isHunadaWin = True DEBUG_MSG("huan da: 1") series_win = True #判断对倒,只用过朋胡的条件 seriesDict = utility.getRemoveMatchOrderDict(handTilesButKing, finalTile, self.kingTiles) for key in seriesDict: seriesKingNum = seriesDict[key] if removeCheckPairWin(handTilesButKing, key, seriesKingNum, kingTilesNum): series_win = False DEBUG_MSG("dui dao") break # 朋胡 DEBUG_MSG("############# {0}".format(utility.meld_with_pair_need_num(handTiles, {}))) if series_win and (utility.getFriendWin(uptiles, handTiles, handTilesButKing, kingTilesNum, sit_wind, self.game_mode, self.prevailing_wind)): stand += 1 result[23] = 1 friend_win = True isGiveWin = True DEBUG_MSG("peng hu: 1") #胡两头 # if finalTile < 30: # isWinTwoSides = utility.getRemoveTwoSides(handTilesButKing, finalTile, kingTilesNum,self.kingTiles) # if isWinTwoSides: # if (isSitWind + isWordColor) >= 2 or (isSitWind > 0 and sit_wind == const.WIND_EAST) or friend_win: # isGiveWin = True # DEBUG_MSG("hu liangtou: 1") # else: # # isGiveWin = False # DEBUG_MSG("buneng hu liangtou") #对倒 边 嵌 单吊 #对倒 removeMatchOrderDict = utility.getRemoveMatchOrderDict(handTilesButKing, finalTile, self.kingTiles) for key in removeMatchOrderDict: useKingNum = removeMatchOrderDict[key] if removeCheckPairWin(handTilesButKing, key, useKingNum, kingTilesNum): stand += 1 result[22] = 1 DEBUG_MSG("dui dao: 1") break else: if not isPongPongWin: #边 removeEdgeDict = utility.getRemoveEdgeDict(handTilesButKing, finalTile, self.kingTiles) for key in removeEdgeDict: useKingNum = removeEdgeDict[key] if removeCheckPairWin(handTilesButKing, key, useKingNum, kingTilesNum): stand += 1 result[45] = 1 DEBUG_MSG("bian: 1") break else: #嵌 removeMidDict = utility.getRemoveMidDict(handTilesButKing, finalTile, self.kingTiles) for key in removeMidDict: useKingNum = removeMidDict[key] if removeCheckPairWin(handTilesButKing, key, useKingNum, kingTilesNum): stand += 1 result[20] = 1 DEBUG_MSG("jia: 1") break else: #单吊 removeSingleCraneDict = utility.getRemoveSingleCraneDict(handTilesButKing, finalTile, self.kingTiles) for key in removeSingleCraneDict: useKingNum = removeSingleCraneDict[key] if removeCheckOnlyWin(handTilesButKing, key, useKingNum, kingTilesNum): stand += 1 result[21] = 1 DEBUG_MSG("dandiao: 1") break else: # 胡两头 isGiveWin = False if (isSitWind + isWordColor) >= 2 or (isSitWind > 0 and sit_wind == const.WIND_EAST) or friend_win: isGiveWin = True DEBUG_MSG("hu liangtou: 1") else: DEBUG_MSG("buneng hu liangtou") #无搭, 一搭,二搭,三百搭, 三花三百搭 if kingTilesNum == 0: stand += 1 result[12] = 1 DEBUG_MSG("wuda: 1") elif kingTilesNum == 1: stand += 1 result[13] = 1 DEBUG_MSG("yida: 1") elif kingTilesNum == 2: stand += 2 result[14] = 1 DEBUG_MSG("erda: 1") elif kingTilesNum == 3: if self.kingTiles[0] in const.SEASON or self.kingTiles[0] in const.FLOWER: quantity += 300 result[43] = 1 DEBUG_MSG("san hua sanbaida: 300") else: quantity += 150 result[42] = 1 DEBUG_MSG("san baida: 150") # 花 手牌 桌牌 非胡台数 quantities, stands, four_flower= utility.getWreathQuantity(wreaths, p_wind) quantity += quantities stand += stands if four_flower: result[44] = 1 DEBUG_MSG("wreaths quantity:{0}, stand: {1}".format(quantities, stands)) # 抢杠胡 if win_op == const.OP_KONG_WIN: quantity += 100 result[32] = 1 DEBUG_MSG("qiangganghu: 100" ) #判断台数 DEBUG_MSG("quantity: {0}, stand: {1}, {2}".format(quantity, stand, isHunadaWin)) tatal_stands = quantity + stand if isGiveWin and isHunadaWin == False and tatal_stands >= self.win_quantity and (win_op == const.OP_GIVE_WIN or (win_op == const.OP_FINAL_WIN and idx != self.last_player_idx)): return True, quantity, stand, result, kongType elif isSelfWin: return True, quantity, stand, result, kongType else: return False, quantity, stand, result, kongType