Esempio n. 1
0
	def getKingTilesNum(self, tiles):
		tile2NumDict = utility.getTile2NumDict(tiles)
		kingTilesNum = 0
		for k in self.kingTiles:
			if k in tile2NumDict:
				kingTilesNum += tile2NumDict[k]
		return kingTilesNum
Esempio n. 2
0
    def deal(self, prefabHandTiles, prefabTopList):
        """ 发牌 """
        if prefabHandTiles is not None:
            for i, p in enumerate(self.players_list):
                if p is not None and len(prefabHandTiles) >= 0:
                    if len(prefabHandTiles[i]) >= 4:
                        p.standTileList = prefabHandTiles[i][0:4]
                    elif len(prefabHandTiles[i]) < 4:
                        p.standTileList = prefabHandTiles[i][
                            0:len(prefabHandTiles[i])]
                    p.tiles = prefabHandTiles[i] if len(
                        prefabHandTiles[i]
                    ) <= const.INIT_TILE_NUMBER else prefabHandTiles[i][
                        0:const.INIT_TILE_NUMBER]
            topList = prefabTopList if prefabTopList is not None else []
            allTiles = []
            for i, p in enumerate(self.players_list):
                if p is not None:
                    allTiles.extend(p.tiles)
            allTiles.extend(topList)

            tile2NumDict = utility.getTile2NumDict(allTiles)
            warning_tiles = [t for t, num in tile2NumDict.items() if num > 4]
            if len(warning_tiles) > 0:
                WARNING_MSG(
                    "room:{},curround:{} prefab {} is larger than 4.".format(
                        self.roomID, self.current_round, warning_tiles))
            for t in allTiles:
                if t in self.tiles:
                    self.tiles.remove(t)
            for i in range(const.INIT_TILE_NUMBER):
                num = 0
                for j in range(self.player_num):
                    p = self.players_list[j]
                    if len(p.tiles) >= const.INIT_TILE_NUMBER:
                        continue
                    if len(p.standTileList) < 4:
                        p.standTileList.append(self.tiles[num])
                    p.tiles.append(self.tiles[num])
                    num += 1
                self.tiles = self.tiles[num:]

            newTiles = topList
            newTiles.extend(self.tiles)
            self.tiles = newTiles
        else:
            for i in range(const.INIT_TILE_NUMBER):
                for j in range(self.player_num):
                    p = self.players_list[j]
                    p.tiles.append(self.tiles[j])
                    if i <= 3:
                        p.standTileList.append(self.tiles[j])
                self.tiles = self.tiles[self.player_num:]

        for i, p in enumerate(self.players_list):
            DEBUG_MSG("room:{},curround:{} idx:{} deal tiles:{}".format(
                self.roomID, self.current_round, i, p.tiles))
            DEBUG_MSG(
                "room:{},curround:{} idx:{} deal standTileList:{}".format(
                    self.roomID, self.current_round, i, p.standTileList))
Esempio n. 3
0
def checkIs7Pair(handTiles, handTilesButKing, kingTilesNum, kingTiles, finalTile): #return 7对,暴头,杠数
	if len(handTiles) != 14:
		return False, False, 0
	needNum = 0
	tileDict = utility.getTile2NumDict(handTilesButKing)
	meld_list = []
	for tile in tileDict:
		meld_list.append([tile] * tileDict[tile])
	for meld in meld_list:
		if len(meld) % 2 != 0:
			meld.append(-1)
			needNum += 1
	if needNum > kingTilesNum:
		return False, False, 0
	# 暴头
	isBaoTou = False
	if kingTilesNum > 0:
		if finalTile in kingTiles: #最后一张是财神 必须 财神凑成对子
			isBaoTou = kingTilesNum - needNum >= 2
		else:
			isBaoTou = any(finalTile in meld and -1 in meld for meld in meld_list) or kingTilesNum - needNum >= 2
	# # 全部配对后,剩余必然是偶数
	restKingPairNum = int((kingTilesNum - needNum)/2)
	pairNum = sum([1 for meld in meld_list if len(meld) == 2])
	kongPairNum = sum([1 for meld in meld_list if len(meld) == 4])

	return True, isBaoTou, kongPairNum + min(restKingPairNum, pairNum)
Esempio n. 4
0
	def can_discard(self, tiles, t, idx):
		if t in tiles:
			if t in self.kingTiles:
				return False
			tile2NumDict = utility.getTile2NumDict(tiles)
			single_dragon_wind_num = 0
			for key in tile2NumDict:
				val = tile2NumDict[key]
				if key in const.WORDS and key not in self.kingTiles and val <= 1:
					single_dragon_wind_num += 1
				elif key == const.DRAGON_WHITE and self.kingTiles[0] in const.WORDS and val <= 1:
					single_dragon_wind_num += 1
			# 白板 并且 财神 是 字
			if t == const.DRAGON_WHITE and self.kingTiles[0] in const.WORDS:
				return True
			if single_dragon_wind_num > 0 and t not in const.WORDS:
				return False
			return True
		return False
Esempio n. 5
0
def get7DoubleWin(handTiles, handTilesButKing, kingTilesNum, lastTile):
	""" 返回值为(是否是七对,是否是豪七,是否是双豪七) """
	if len(handTiles) != 14:
		return False, False, False
	tileDict = utility.getTile2NumDict(handTilesButKing)
	need_kingtiles_num = 0
	isBrightTiles = False
	isDarkTiles = False
	for tile in tileDict:
		need_kingtiles_num  += tileDict[tile] % 2
		if tileDict[tile] == 4:
			if tile == lastTile:
				isBrightTiles = True
			else:
				isDarkTiles = True
	DEBUG_MSG("get7DoubleWin {0}, {1}".format(need_kingtiles_num,kingTilesNum))
	if kingTilesNum == need_kingtiles_num or need_kingtiles_num == 0:
		return True, isBrightTiles, isDarkTiles
	else:
		return False, False, False
Esempio n. 6
0
    def deal(self, prefabHandTiles, prefabTopList):
        """ 发牌 """
        if prefabHandTiles is not None:
            for i, p in enumerate(self.players_list):
                if p is not None and len(prefabHandTiles) >= 0:
                    p.tiles = prefabHandTiles[i] if len(prefabHandTiles[i]) > const.INIT_TILE_NUMBER else \
                     prefabHandTiles[i][0:const.INIT_TILE_NUMBER]
            topList = prefabTopList if prefabTopList is not None else []
            allTiles = []
            for i, p in enumerate(self.players_list):
                if p is not None:
                    allTiles.extend(p.tiles)
            allTiles.extend(topList)

            tile2NumDict = utility.getTile2NumDict(allTiles)
            warning_tiles = [t for t, num in tile2NumDict.items() if num > 4]
            if len(warning_tiles) > 0:
                WARNING_MSG("{} prefab {} is larger than 4.".format(
                    self.prefixLogStr, warning_tiles))
            for t in allTiles:
                if t in self.tiles:
                    self.tiles.remove(t)
            for i in range(const.INIT_TILE_NUMBER):
                for j in range(self.player_num):
                    if len(self.players_list[j].tiles
                           ) >= const.INIT_TILE_NUMBER:
                        continue
                    self.players_list[j].tiles.append(self.tiles.pop(0))

            newTiles = topList
            newTiles.extend(self.tiles)
            self.tiles = newTiles
        else:
            for i in range(const.INIT_TILE_NUMBER):
                for j in range(self.player_num):
                    self.players_list[j].tiles.append(self.tiles[j])
                self.tiles = self.tiles[self.player_num:]

        for i, p in enumerate(self.players_list):
            DEBUG_MSG("{} idx:{} deal tiles:{}".format(self.prefixLogStr, i,
                                                       p.tiles))
Esempio n. 7
0
    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
Esempio n. 8
0
    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
Esempio n. 9
0
	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