Beispiel #1
0
    def isHu(self,
             tiles,
             tile,
             isTing,
             getTileType,
             magicTiles=[],
             tingNodes=[],
             winSeatId=0):
        # 检查是否过胡状态 自摸情况下不判断过胡
        if getTileType != MWinRule.WIN_BY_MYSELF and self.tableTileMgr.isPassHuTileBySeatId(
                winSeatId, tile):
            ftlog.debug('MWinRuleXueZhan.isHu passHu...')
            return False, []
        tileArr = MTile.changeTilesToValueArr(MHand.copyAllTilesToList(tiles))
        # 获取当前座位号定缺的花色
        colorAbsence = self.tableTileMgr.absenceColors[winSeatId]
        # 获取手牌中定缺花色牌的数量,大于0,不用判断胡
        colorAbsenceNum = MTile.getTileCountByColor(tileArr, colorAbsence)
        # ftlog.debug('MWinRuleXueZhan colorAbsenceNum:', colorAbsenceNum, 'tiles:', tiles, 'tile:', tile, 'colorAbsence:', colorAbsence)
        if colorAbsenceNum > 0:
            return False, []

        resultQidui, qiduiPattern = MWin.isQiDui(tiles[MHand.TYPE_HAND], [])
        if resultQidui:
            return True, qiduiPattern

        result, rePattern = MWin.isHu(tiles[MHand.TYPE_HAND])
        if result:
            return True, rePattern
        return False, []
Beispiel #2
0
    def isSanQi(self):
        """是否三七边"""
        # 1,2,3 拿出来,剩下的能不能胡
        # 7,8,9 拿出来 剩下的能不能胡
        handTile = copy.deepcopy(
            self.playerAllTiles[self.winSeatId][MHand.TYPE_HAND])
        handTile.extend(self.playerAllTiles[self.winSeatId][MHand.TYPE_HU])

        if MTile.getValue(self.winTile) == 7 and self.winTile < 30 and (
                self.winTile + 1) in handTile and (self.winTile +
                                                   2) in handTile:
            handTile.remove(self.winTile)
            handTile.remove(self.winTile + 1)
            handTile.remove(self.winTile + 2)
            res, _ = MWin.isHu(handTile)
            ftlog.debug('weihai_one_result.isSanQi result: ', res)
            return res
        elif MTile.getValue(self.winTile) == 3 and self.winTile < 30 and (
                self.winTile - 1) in handTile and self.winTile - 2 in handTile:
            handTile.remove(self.winTile)
            handTile.remove(self.winTile - 1)
            handTile.remove(self.winTile - 2)
            res, _ = MWin.isHu(handTile)
            ftlog.debug('weihai_one_result.isSanQi result: ', res)
            return res
        else:
            ftlog.debug('weihai_one_result.isSanQi result: False')
            return False
Beispiel #3
0
    def isHu(self,
             tiles,
             tile,
             isTing,
             getTileType,
             magicTiles=[],
             tingNodes=[],
             winSeatId=0):
        if not isTing:
            # 没听牌 不和
            return False, []

        # 鸡西打宝炮(先不支持 之后通过配置项目支持) 玩家上听后没有听牌的玩家打出宝牌 则听牌玩家和牌
        # 听牌之后自摸到宝牌 自动和牌
        if isTing and getTileType == MWinRule.WIN_BY_MYSELF:
            if (tile in magicTiles):
                # 听牌并且是宝牌,和牌
                return True, []

        ftlog.debug('win_rule_jixi.isHu tiles:', tiles, ' magicTiles:',
                    magicTiles, ' tile:', tile)

        # 这里的鸡西七对判断胡牌,不用宝牌,判断原始牌。宝牌在上面的逻辑里会判断胡牌
        resultQiDui, patternQiDui = MWin.isQiDui(tiles[MHand.TYPE_HAND])
        if resultQiDui:
            return True, patternQiDui

        result, pattern = MWin.isHu(tiles[MHand.TYPE_HAND])
        if not result:
            return False, []

        #从tingNode中判断,如果是听规则中的才算胡
        if len(tingNodes) > 0:
            hasTile = False
            pattern = []
            #[{'winTile': 16, 'winTileCount': 0, 'pattern': [[16, 17, 18], [12, 12]]}, {'winTile': 19, 'winTileCount': 0, 'pattern': [[17, 18, 19], [12, 12]]}]
            for tingNode in tingNodes:
                if tingNode['winTile'] == tile:
                    hasTile = True
                    pattern = tingNode['pattern']
                    break
            if hasTile:
                #鸡西只有特大夹番型才能抢杠和
                if getTileType == MWinRule.WIN_BY_QIANGGANGHU:
                    if self.isTeDaJia(pattern, tingNodes, tiles, tile,
                                      winSeatId):
                        return True, pattern
                    else:
                        return False, []

                return True, pattern
            else:
                return False, []

        return True, pattern
Beispiel #4
0
    def isHu(self,
             tiles,
             tile,
             isTing,
             getTileType,
             magicTiles=[],
             tingNodes=[],
             winSeatId=0):
        ftlog.debug(self.TAG, '.isHu tiles:', tiles, ' tile:', tile,
                    ' isTing:', isTing, ' getTileType:', getTileType,
                    ' magicTiles:', magicTiles, ' tingNodes:', tingNodes,
                    ' winSeatId:', winSeatId)
        # 平度麻将即可以听也可以不听,听牌后,校验tingNodes即可,无其他限制条件
        if isTing:
            #[{'winTile': 16, 'winTileCount': 0, 'pattern': [[16, 17, 18], [12, 12]]}, {'winTile': 19, 'winTileCount': 0, 'pattern': [[17, 18, 19], [12, 12]]}]
            for tingNode in tingNodes:
                if tingNode['winTile'] == tile:
                    pattern = tingNode['pattern']
                    return True, pattern

        # 检查2,5,8将

        # 平度麻将允许胡七对
        resultQiDui, patternQiDui = MWin.isQiDui(tiles[MHand.TYPE_HAND])
        if resultQiDui:
            for pattern in patternQiDui:
                tile = pattern[0]
                if tile > MTile.TILE_NINE_TIAO:
                    continue

                if MTile.getValue(pattern[0]) % 3 == 2:
                    return True, patternQiDui

            return False, []

        # 挑出2,5,8将,看剩下的牌是否能胡牌
        jiangPatterns = [[MTile.TILE_TWO_WAN, MTile.TILE_TWO_WAN],
                         [MTile.TILE_FIVE_WAN, MTile.TILE_FIVE_WAN],
                         [MTile.TILE_EIGHT_WAN, MTile.TILE_EIGHT_WAN],
                         [MTile.TILE_TWO_TONG, MTile.TILE_TWO_TONG],
                         [MTile.TILE_FIVE_TONG, MTile.TILE_FIVE_TONG],
                         [MTile.TILE_EIGHT_TONG, MTile.TILE_EIGHT_TONG],
                         [MTile.TILE_TWO_TIAO, MTile.TILE_TWO_TIAO],
                         [MTile.TILE_FIVE_TIAO, MTile.TILE_FIVE_TIAO],
                         [MTile.TILE_EIGHT_TIAO, MTile.TILE_EIGHT_TIAO]]

        for jiangPat in jiangPatterns:
            result, pattern = MWin.isHuWishSpecialJiang(
                tiles[MHand.TYPE_HAND], jiangPat)
            if result:
                return result, pattern
        return False, []
Beispiel #5
0
    def isHu(self,
             tiles,
             tile,
             isTing,
             getTileType,
             magicTiles=[],
             tingNodes=[],
             winSeatId=0):
        ftlog.debug(self.TAG, '.isHu tiles:', tiles, ' tile:', tile,
                    ' isTing:', isTing, ' getTileType:', getTileType,
                    ' magicTiles:', magicTiles, ' tingNodes:', tingNodes,
                    ' winSeatId:', winSeatId)
        # 平度麻将即可以听也可以不听,听牌后,校验tingNodes即可,无其他限制条件
        if isTing:
            #[{'winTile': 16, 'winTileCount': 0, 'pattern': [[16, 17, 18], [12, 12]]}, {'winTile': 19, 'winTileCount': 0, 'pattern': [[17, 18, 19], [12, 12]]}]
            for tingNode in tingNodes:
                if tingNode['winTile'] == tile:
                    pattern = tingNode['pattern']
                    return True, pattern

        # 检查8张的规则
        allTiles = MHand.copyAllTilesToListButHu(tiles)
        tilesArr = MTile.changeTilesToValueArr(allTiles)
        wanCount = MTile.getTileCountByColor(tilesArr, MTile.TILE_WAN)
        tiaoCount = MTile.getTileCountByColor(tilesArr, MTile.TILE_TIAO)
        tongCount = MTile.getTileCountByColor(tilesArr, MTile.TILE_TONG)
        fengCount = MTile.getTileCountByColor(tilesArr, MTile.TILE_FENG)
        ftlog.debug('win_rule_pingdu.isHu allTiles:', allTiles,
                    ' tilesLength:', len(allTiles), ' tilesArr:', tilesArr,
                    ' wanCount:', wanCount, ' tiaoCount:', tiaoCount,
                    ' tongCount:', tongCount, ' fengCount:', fengCount)

        if (wanCount >= 8) or (tiaoCount >= 8) or (tongCount >=
                                                   8) or (fengCount >= 8):
            pass
        else:
            #             ftlog.info('win_rule_pingdu.isHu ok but do not have >=8 tiles in one color, allTiles:', allTiles
            #                     , ' tilesLength:', len(allTiles)
            #                     , ' tilesArr:', tilesArr
            #                     , ' wanCount:', wanCount
            #                     , ' tiaoCount:', tiaoCount
            #                     , ' tongCount:', tongCount
            #                     , ' fengCount:', fengCount)
            return False, []

        # 平度麻将允许胡七对
        resultQiDui, patternQiDui = MWin.isQiDui(tiles[MHand.TYPE_HAND])
        if resultQiDui:
            return True, patternQiDui

        result, pattern = MWin.isHu(tiles[MHand.TYPE_HAND])
        return result, pattern
Beispiel #6
0
    def isQiDui(self, isMagic):
        ftlog.debug('jixi_one_result.isQiDui winSeatId:', self.winSeatId,
                    ' tiles:', self.playerAllTiles[self.winSeatId])
        handTile = copy.deepcopy(
            self.playerAllTiles[self.winSeatId][MHand.TYPE_HAND])
        if len(handTile) % 2 > 0:
            handTile.extend(self.playerAllTiles[self.winSeatId][MHand.TYPE_HU])
        ftlog.debug('jixi_one_result.isQiDui adjust tiles:', handTile)

        if isMagic:
            magics = self.tableTileMgr.getMagicTiles(True)
            qiduiResult, _ = MWin.isQiDui(handTile, magics)
        else:
            qiduiResult, _ = MWin.isQiDui(handTile)
        return qiduiResult
Beispiel #7
0
    def isHu(self, tiles, tile, isTing, getTileType, magicTiles=[], tingNodes=[], winSeatId=0):
        ftlog.debug('MWinRuleJiPingHu.isHu tiles:', tiles
                    , ' tile:', tile
                    , ' isTing:', isTing
                    , ' getTileType:', getTileType
                    , ' magicTiles:', magicTiles
                    , ' tingNodes:', tingNodes
                    , ' winSeatId:', winSeatId
                    )
 
        # 检查是否过胡状态
        if self.tableTileMgr.isPassHuTileBySeatId(winSeatId, tile):
            if self.msgProcessor:
                ftlog.debug('songsong MWinRuleJiPingHu.isHu isPassHuTileBySeatId:',winSeatId, 'tile:',tile)
                self.msgProcessor.table_call_show_tips(MTDefine.TIPS_NUM_10, self.tableTileMgr.players[winSeatId])
            return False, []
        
        huqidui = self.tableConfig.get(MTDefine.HUQIDUI, MTDefine.HUQIDUI_YES)
        if huqidui:
            resultQidui, qiduiPattern = MWin.isQiDui(tiles[MHand.TYPE_HAND], magicTiles)
            if resultQidui:
                ftlog.debug('MWinRuleJiPingHu.isQiDui True,', qiduiPattern)
                return True, qiduiPattern

        resultshisan = MWin.isShisanyao(tiles, magicTiles)
        if resultshisan:
            ftlog.debug('MWinRuleJiPingHu.isShisanyao True,')
            return True, []

        tileArr = MTile.changeTilesToValueArr(MHand.copyAllTilesToList(tiles))
        result, rePattern = MWin.isHu(tiles[MHand.TYPE_HAND], magicTiles)
        if result:
            ftlog.debug('MWinRuleJiPingHu.isHu True, ', rePattern)
            if getTileType == MWinRule.WIN_BY_OTHERS:
                jipinghu = False  # 【鸡胡】:X1,顺牌+刻牌+1对将. 鸡胡只能自摸/抢杠胡
                jipinghu = self.isJipinghu(rePattern, tiles, tileArr, magicTiles)
                if jipinghu:
                    if self.msgProcessor:
                        ftlog.debug('MWinRuleJiPingHu.isHu jipinghu buneng hu:')
                        self.msgProcessor.table_call_show_tips(MTDefine.TIPS_NUM_12,self.tableTileMgr.players[winSeatId])
                    return False, []
                else:
                    return True, rePattern
            else:
                return True, rePattern

        ftlog.debug('MWinRuleJiPingHu.isHu False, []')
        return False, []
Beispiel #8
0
 def isQiDui(self, seatId):
     handTile = copy.deepcopy(
         self.playerAllTiles[self.winSeatId][MHand.TYPE_HAND])
     if len(handTile) % 2 > 0:
         handTile.extend(self.playerAllTiles[self.winSeatId][MHand.TYPE_HU])
     ftlog.debug('pingdu_one_result.isQiDui adjust tiles:', handTile)
     qiduiResult, _ = MWin.isQiDui(handTile)
     return qiduiResult
Beispiel #9
0
    def isHu(self, tiles, tile, isTing, getTileType, magicTiles = [], tingNodes = [], curSeatId = 0, winSeatId = 0, actionID = 0, isGangKai = False,isForHu = True):

	if self.tableTileMgr.playMode == "luosihu-luosihu" and isForHu:
	    if not isTing:
	        if not self.tableTileMgr.players[winSeatId].isWon():
		    return False,[],0

        allTiles = MHand.copyAllTilesToListButHu(tiles)
        tilesArr = MTile.changeTilesToValueArr(allTiles)	
        # 需要缺一门: 定缺的时候约定的那门
        if self.absenceColor:
            if MTile.getTileCountByColor(tilesArr, self.absenceColor[winSeatId]) > 0:
                return False, [],0
        result, pattern = self.isQidui(tiles)
        if result:
            if self.tableTileMgr.playMode == "luosihu-luosihu":
                self.fanXing[self.QIDUI]["index"] = 1 
            return True, pattern,self.fanXing[self.QIDUI]["index"]

        result, pattern = MWin.isHu(tiles[MHand.TYPE_HAND], magicTiles)

        if result:
            ftlog.debug('MWinRuleLuosihu.isHu result=',result,' getTileType=',getTileType,' pattern=',pattern)
            player = self.tableTileMgr.players[winSeatId]
            self.winSeatId = winSeatId
            self.__tile_pattern_checker = MTilePatternCheckerFactory.getTilePatternChecker(MPlayMode.LUOSIHU)
            playersAllTiles = [[] for _ in range(self.tableTileMgr.playCount)]
            self.__win_patterns = [[] for _ in range(self.tableTileMgr.playCount)]
            self.__win_patterns[winSeatId] = [pattern]
            for seatId in range(self.tableTileMgr.playCount):
                if seatId == winSeatId:
                    playersAllTiles[seatId] = copy.deepcopy(tiles)
                else:
                    playersAllTiles[seatId] = self.tableTileMgr.players[seatId].copyTiles()
            self.setAllPlayerTiles(playersAllTiles)
            # 判断和牌的时候
            self.__tile_pattern_checker.initChecker(playersAllTiles, tile, self.tableTileMgr, True, curSeatId, winSeatId, actionID)
            winnerResult = []
            if self.tableTileMgr.playMode == "luosihu-ctxuezhan":
                winnerResult = self.getWinnerResultsForXueZhanDaoDi(winSeatId)
            elif self.tableTileMgr.playMode == "luosihu-xuezhan":
                winnerResult = self.getWinnerResultsForLuoSiHuXueZhan(winSeatId)
            elif self.tableTileMgr.playMode == "luosihu-luosihu":
                winnerResult = self.getWinnerResultsForLuoSiHu(winSeatId)
            finalResult = []
            finalResult.extend(winnerResult)
            maxFan = self.tableConfig.get(MTDefine.MAX_FAN, 0)
            winScore,indexFan = self.getScoreByResults(finalResult, maxFan)
            ftlog.debug('MWinRuleLuosihu.isHu player.guoHuPoint :',winScore,' finalResult=',finalResult,' indexFan')
            # 过胡判断
            if getTileType == MWinRule.WIN_BY_MYSELF:
                return True,pattern,indexFan
            if player.guoHuPoint >= winScore and self.tableTileMgr.playMode == "luosihu-ctxuezhan":
                return False, [],0
            player.totalWinPoint = winScore
            return True,pattern,indexFan

	return False, [],0
Beispiel #10
0
 def isQuanYao(self, tableConfig):
     '''
     判断手牌是否为全幺 所有组成的顺子、刻子、将牌里都包含1或9
     '''
     # 房间配置为0,则没有全幺九
     if not tableConfig.get(MFTDefine.QUANYAOJIU_DOUBLE, 0):
         ftlog.debug('MSiChuanTilePattern.isQuanYao False because roomConfig')
         return False
     return MWin.isQuanYaoJiu(self.playerAllTiles)
Beispiel #11
0
 def isFengyise(self):
     """
     风一色:由东南西北中发白组成的胡牌
     """
     handTile = MHand.copyAllTilesToList(
         self.playerAllTiles[self.winSeatId])  # 手牌区+吃+碰+杠+锚+胡区
     handArr = MTile.changeTilesToValueArr(handTile)
     colorCount = MTile.getColorCount(handArr)
     result, _ = MWin.isLuanFengyise(handTile, colorCount)
     return result
Beispiel #12
0
    def isQuanjiang(self):
        """
        全将:手中的牌全部是二五八,不用成牌
        """
        tiles = copy.deepcopy(self.playerAllTiles[self.winSeatId])

        result, _ = MWin.isQuanJiang(tiles)

        ftlog.debug('jinan_one_result.isQuanjiang result: ', result)
        return result
Beispiel #13
0
    def isFlowerHu(self):
        """
        花胡 8张花牌都摸到
        """
        tiles = copy.deepcopy(self.playerAllTiles[self.winSeatId])

        result, _ = MWin.isFlowerHu(tiles)

        ftlog.debug('jinan_one_result.isFlowerHu result: ', result)
        return result
Beispiel #14
0
    def isQidui(self):
        """
        七对:手中有七个对子的胡牌牌型,碰出的牌不算
        """
        handTile = copy.deepcopy(
            self.playerAllTiles[self.winSeatId][MHand.TYPE_HAND])
        handTile.extend(self.playerAllTiles[self.winSeatId][MHand.TYPE_HU])

        qiduiResult, _ = MWin.isQiDui(handTile)
        ftlog.debug('MYantaiOneResult.isQidui result: ', qiduiResult)
        return qiduiResult
Beispiel #15
0
    def getHuPattern(self, tiles, magicTiles=[]):
        # 此处有坑,winPattern只有一种牌型,这样有问题,比如:[14,14,14,15,15,16,16,16,19,19,19,20,20],最后抓15
        # 如果卡五星比碰碰胡番数高,此处应该算卡五星,所以isHu应该返回所有可能的胡的牌型,结算时计算最优的番型
        # 未来有时间需要调整一下

        # 先判断定制的逻辑,防止通用逻辑修改造成业务出错
        result, pattern = self.isQidui(tiles)
        if result:
            # 放炮情况下两番起胡,七对肯定是两番,直接返回
            return result, pattern
        return MWin.isHu(tiles[MHand.TYPE_HAND], magicTiles)
Beispiel #16
0
    def getHuPattern(self, tiles, magicTiles = []):
        # 此处有坑,winPattern只有一种牌型,这样有问题,比如:[14,14,14,15,15,16,16,16,19,19,19,20,20],最后抓15
        # 如果卡五星比碰碰胡番数高,此处应该算卡五星,所以isHu应该返回所有可能的胡的牌型,结算时计算最优的番型
        # 未来有时间需要调整一下

        # 先判断定制的逻辑,防止通用逻辑修改造成业务出错
        result, pattern = self.isQidui(tiles)
        if result:
            # 放炮情况下两番起胡,七对肯定是两番,直接返回
            return result, pattern
        return MWin.isHu(tiles[MHand.TYPE_HAND], magicTiles)
Beispiel #17
0
 def isHu(self,
          tiles,
          tile,
          isTing,
          getTileType,
          magicTiles=[],
          tingNodes=[],
          curSeatId=0,
          winSeatId=0,
          actionID=0,
          isGangKai=False):
     result, pattern = MWin.isHu(tiles[MHand.TYPE_HAND], magicTiles)
     return result, pattern
Beispiel #18
0
 def isMagicHu(self,
               tiles,
               tile,
               isTing,
               getTileType,
               magicTiles=[],
               tingNodes=[],
               curSeatId=0,
               winSeatId=0,
               actionID=0,
               isGangKai=False):
     if len(magicTiles) > 0:
         # 三金倒
         magicHu, pattern = MWin.isMagicHu(tiles, magicTiles[0], tile)
         #if magicHu and actionID > 1:
         return magicHu
Beispiel #19
0
    def isQidui(self):
        """
        七对:手中有七个对子的胡牌牌型,碰出的牌不算
        """
        handTile = copy.deepcopy(self.playerAllTiles[self.winSeatId][MHand.TYPE_HAND])
        handTile.extend(self.playerAllTiles[self.winSeatId][MHand.TYPE_HU])

        result, _ = MWin.isQiDui(handTile)

        # 放锚之后不能胡七对
        maoTile = copy.deepcopy(self.playerAllTiles[self.winSeatId][MHand.TYPE_MAO])
        if len(maoTile) > 0 :
            result = False

        ftlog.debug('jinan_one_result.isQidui result: ', result)
        return result
Beispiel #20
0
    def isJia(self):
        """是否夹牌"""
        # winTile-1 winTile winTile + 1拿出来,剩下的判胡
        handTile = copy.deepcopy(
            self.playerAllTiles[self.winSeatId][MHand.TYPE_HAND])
        handTile.extend(self.playerAllTiles[self.winSeatId][MHand.TYPE_HU])

        if (self.winTile - 1) in handTile and (self.winTile + 1) in handTile:
            handTile.remove(self.winTile)
            handTile.remove(self.winTile - 1)
            handTile.remove(self.winTile + 1)

            res, _ = MWin.isHu(handTile)
            ftlog.debug('weihai_one_result.isJia result: ', res)
            return res
        else:
            ftlog.debug('weihai_one_result.isJia result:False ')
            return False
Beispiel #21
0
    def is13BuKao(self):
        """
        十三不靠:不同花色的 1、4、7 +  2、5、8 + 3、6、9 + 不相同的风牌4张
        #[[1, 4, 7, 12, 15, 18, 23, 26, 29, 31, 32, 33, 36], [], [], [], [], [35], [36], []]
        """

        handTile = copy.deepcopy(self.playerAllTiles[self.winSeatId][MHand.TYPE_HAND])
        handTile.extend(self.playerAllTiles[self.winSeatId][MHand.TYPE_HU])

        chiTile = copy.deepcopy(self.playerAllTiles[self.winSeatId][MHand.TYPE_CHI])
        pengTile = copy.deepcopy(self.playerAllTiles[self.winSeatId][MHand.TYPE_PENG])
        gangTile = copy.deepcopy(self.playerAllTiles[self.winSeatId][MHand.TYPE_GANG])

        if len(chiTile) > 0 or len(pengTile) > 0 or len(gangTile) > 0:
            return False

        result, _ = MWin.is13BuKao(handTile)

        ftlog.debug('jinan_one_result.is13BuKao result: ', result)
        return result
Beispiel #22
0
    def canJinQue(self,magicTile,pattern,handTiles,tile):
	'''
        magicCount = MTile.getTileCount(magicTile,handTiles)
        if magicCount == 2:
            result, pattern= MWin.isHu(handTiles, [])
	    ftlog.debug('MWinRuleQueshou.canJinQue result, pattern=',result, pattern)
            if result:
                return True
        return False
	'''
        magicCount = MTile.getTileCount(magicTile,handTiles)
        if magicCount == 2:
            if tile in handTiles:
                handTiles.remove(tile)
                handTiles.append(31)
            result, pattern= MWin.isHu(handTiles, [31])
	    ftlog.debug('MWinRuleQueshou.canJinQue result, pattern=',result, pattern,handTiles)
            if result:
                return True

        return False
Beispiel #23
0
    def isHu(self,
             tiles,
             tile,
             isTing,
             getTileType,
             magicTiles=[],
             tingNodes=[],
             winSeatId=0):
        if not isTing:
            # 没听牌 不和
            return False, []

        # 哈尔滨打宝炮(先不支持 之后通过配置项目支持) 玩家上听后没有听牌的玩家打出宝牌 则听牌玩家和牌
        # 听牌之后自摸到宝牌 自动和牌
        if isTing and getTileType == MWinRule.WIN_BY_MYSELF:
            if (tile in magicTiles):
                # 听牌并且是宝牌,和牌
                return True, []

        result, pattern = MWin.isHu(tiles[MHand.TYPE_HAND])
        if not result:
            return False, []

        #从tingNode中判断,如果是听规则中的才算胡
        if len(tingNodes) > 0:
            hasTile = False
            pattern = []
            #[{'winTile': 16, 'winTileCount': 0, 'pattern': [[16, 17, 18], [12, 12]]}, {'winTile': 19, 'winTileCount': 0, 'pattern': [[17, 18, 19], [12, 12]]}]
            for tingNode in tingNodes:
                if tingNode['winTile'] == tile:
                    hasTile = True
                    pattern = tingNode['pattern']
                    break
            if hasTile:
                return True, pattern
            else:
                return False, []

        return True, pattern
Beispiel #24
0
    def canJinQue(self, magicTile, pattern, handTiles, tile):
        '''
        magicCount = MTile.getTileCount(magicTile,handTiles)
        if magicCount == 2:
            result, pattern= MWin.isHu(handTiles, [])
	    ftlog.debug('MWinRuleQueshou.canJinQue result, pattern=',result, pattern)
            if result:
                return True
        return False
	'''
        magicCount = MTile.getTileCount(magicTile, handTiles)
        if magicCount == 2:
            if tile in handTiles:
                handTiles.remove(tile)
                handTiles.append(31)
            result, pattern = MWin.isHu(handTiles, [31])
            ftlog.debug('MWinRuleQueshou.canJinQue result, pattern=', result,
                        pattern, handTiles)
            if result:
                return True

        return False
Beispiel #25
0
    def isYouJin(self,magicTile,pattern,handTiles,tile):
        '''
        游金:金做将对
        游金不胡点炮
	
	ftlog.debug('MWinRuleQueshou.isYouJin pattern,handTiles,tile',pattern,handTiles,tile)
        for p in pattern:
            if len(p) == 2:
                if magicTile in p:
                    p.remove(magicTile)
                    if p[0] == tile:
                        return True
	'''
	magicCount = MTile.getTileCount(magicTile,handTiles)
        if magicCount == 1:
            if tile in handTiles:
                handTiles.remove(tile)
                handTiles.append(31)
            result, pattern= MWin.isHu(handTiles, [magicTile])
            #ftlog.debug('MWinRuleQueshou.canJinQue result, pattern=',result, pattern,handTiles)
            if result:
                return True
	return False
Beispiel #26
0
    def isDaFeng(self, isMagic):
        """只补充判断有三种宝牌的情况"""
        if not isMagic:
            return self.daFeng

        if self.isHongZhong():
            return self.daFeng

        handTiles = copy.deepcopy(
            self.playerAllTiles[self.winSeatId][MHand.TYPE_HAND])
        if len(handTiles) % 3 != 2:
            handTiles.append(self.winTile)

        tileArr = MTile.changeTilesToValueArr(handTiles)
        if tileArr[self.winTile] == 4:
            # 测试去掉胡牌的刻子之后是否仍旧能胡牌
            for _ in range(3):
                handTiles.remove(self.winTile)
            result, _ = MWin.isHu(handTiles)
            if result:
                self.setDaFeng(True)

        return self.daFeng
Beispiel #27
0
    def isPiao(self):
        playerChiTiles = self.playerAllTiles[self.winSeatId][MHand.TYPE_CHI]
        if len(playerChiTiles) > 0:
            return False

        playerHandTiles = self.playerAllTiles[self.winSeatId][MHand.TYPE_HAND]
        newPlayerHandTiles = MTile.cloneTiles(playerHandTiles)
        newPlayerHandTiles.append(self.winTile)

        ishu, pattern = MWin.isHu(newPlayerHandTiles,
                                  self.tableTileMgr.getMagicTiles(True), True)
        ftlog.debug('MPanjinOneResult.calcWin isPiao newPlayerHandTiles:',
                    newPlayerHandTiles, 'ishu', ishu, 'pattern', pattern)
        if ishu:
            for p in pattern:
                if len(p) == 3:
                    if (p[0] == p[2] or p[1] == p[2] or p[0] == p[1]):
                        continue
                    else:
                        ftlog.debug('MPanjinOneResult.calcWin isPiao False')
                        return False
        ftlog.debug('MPanjinOneResult.calcWin isPiao True')
        return True
Beispiel #28
0
    def isYouJin(self, magicTile, pattern, handTiles, tile):
        '''
        游金:金做将对
        游金不胡点炮
	
	ftlog.debug('MWinRuleQueshou.isYouJin pattern,handTiles,tile',pattern,handTiles,tile)
        for p in pattern:
            if len(p) == 2:
                if magicTile in p:
                    p.remove(magicTile)
                    if p[0] == tile:
                        return True
	'''
        magicCount = MTile.getTileCount(magicTile, handTiles)
        if magicCount == 1:
            if tile in handTiles:
                handTiles.remove(tile)
                handTiles.append(31)
            result, pattern = MWin.isHu(handTiles, [magicTile])
            #ftlog.debug('MWinRuleQueshou.canJinQue result, pattern=',result, pattern,handTiles)
            if result:
                return True
        return False
Beispiel #29
0
    def isHu(self, tiles, tile, isTing, getTileType, magicTiles = [], tingNodes = [], winSeatId = 0):
        ftlog.debug(self.TAG, '.isHu tiles:', tiles
                    , ' tile:', tile
                    , ' isTing:', isTing
                    , ' getTileType:', getTileType
                    , ' magicTiles:', magicTiles
                    , ' tingNodes:', tingNodes
                    , ' winSeatId:', winSeatId
                    )
        # 平度麻将即可以听也可以不听,听牌后,校验tingNodes即可,无其他限制条件
        if isTing:
            #[{'winTile': 16, 'winTileCount': 0, 'pattern': [[16, 17, 18], [12, 12]]}, {'winTile': 19, 'winTileCount': 0, 'pattern': [[17, 18, 19], [12, 12]]}] 
            for tingNode in tingNodes:
                if tingNode['winTile'] == tile:
                    pattern = tingNode['pattern']
                    return True, pattern

                # 三色全
        allTiles = MHand.copyAllTilesToList(tiles)
        tilesArr = MTile.changeTilesToValueArr(allTiles)
        wanCount = MTile.getTileCountByColor(tilesArr, MTile.TILE_WAN)
        tongCount = MTile.getTileCountByColor(tilesArr, MTile.TILE_TONG)
        tiaoCount = MTile.getTileCountByColor(tilesArr, MTile.TILE_TIAO)
        if wanCount==0 or tongCount==0 or tiaoCount==0:
            return False, []

        #有幺九
        if not self.SatisyYaoJiu(tiles):
            return False,[]
        
        if not self.SatisyKe(tiles):
            return False,[]
        
        result, pattern = MWin.isHu(tiles[MHand.TYPE_HAND])
        ftlog.debug('MWinRulePanjin.isHu tiles:', result, ' pattern:', pattern)

        return result, pattern
Beispiel #30
0
    def calcWin(self):

        isMagic = self.isMagicTile()

        resultwin = []

        ftlog.debug(
            'MBaichengOneResult.calcWin self.playerAllTiles[self.winSeatId]',
            self.playerAllTiles[self.winSeatId])

        for tileTry in range(MTile.TILE_MAX_VALUE):
            if self.SatisyYaoJiu(self.playerAllTiles[self.winSeatId], tileTry):
                handTile = copy.deepcopy(
                    self.playerAllTiles[self.winSeatId][MHand.TYPE_HAND])
                handTile.append(tileTry)
                ishu, pattern = MWin.isHu(handTile, [], True)
                if ishu:
                    winNode = {}
                    winNode['winTile'] = tileTry
                    winNode['winTileCount'] = 2
                    for p in pattern:
                        p.sort()
                    winNode['pattern'] = pattern
                    resultwin.append(winNode)

        ftlog.debug('MBaichengOneResult.calcWin MWin.isHu(handTile) resultwin',
                    resultwin)
        self.setWinNodes(resultwin)

        self.results['type'] = MOneResult.KEY_TYPE_NAME_HU

        name = ''
        index = 0
        _ = [0 for _ in range(self.playerCount)]
        fanPattern = [[] for _ in range(self.playerCount)]
        winMode = [MOneResult.WIN_MODE_LOSS for _ in range(self.playerCount)]
        # 在和牌时统计自摸,点炮,最大番数
        resultStat = [[] for _ in range(self.playerCount)]

        resultStat[self.winSeatId].append({MOneResult.STAT_WIN: 1})
        # 正常和牌
        isZiMo = (self.lastSeatId == self.winSeatId)
        if isZiMo:
            resultStat[self.winSeatId].append({MOneResult.STAT_ZIMO: 1})

        isTianhu = False
        if self.tableConfig.get(MTDefine.TIAN_HU, 0):
            isTianhu = self.isTianHu()
        isJia = self.isJia()
        if not isJia:
            isJia = self.isZFBJia()
        isBian = self.isBian()
        isDanDiao = self.isDanDiao()
        isPiao = self.isPiao()
        isJiHu = self.isJiHu()
        isSanQi = self.isSanQi()
        if not (isJia or isDanDiao or (isBian and isSanQi)):
            if len(self.winNodes) == 1:
                isJia = True
        ftlog.debug('MBaichengOneResult.calcWin isJia:', isJia, ' isTianhu:',
                    isTianhu, ' isBian:', isBian, ' isDanDiao', isDanDiao,
                    ' isPiao:', isPiao, ' isJiHu:', isJiHu, ' isSanQi:',
                    isSanQi)

        self.clearWinFanPattern()

        if self.isWinnerHasBaozhonggang():
            namebaozhonggang = self.fanXing[self.BAOZHONGGANG]['name']
            indexbaozhonggang = self.fanXing[self.BAOZHONGGANG]['index']
            self.addWinFanPattern(namebaozhonggang, indexbaozhonggang)

        if isTianhu:
            nametianhu = self.fanXing[self.TIANHU]['name']
            indextianhu = self.fanXing[self.TIANHU]['index']
            self.addWinFanPattern(nametianhu, indextianhu)
            index += self.fanXing[self.TIANHU]['index']
            ftlog.debug('MBaichengOneResult.calcWin name:', nametianhu,
                        ' index:', indextianhu)

        # 高级番型处理(清一色 通宝 宝中宝)
        isBaoZhongBao = False

        if isZiMo:  # 自摸番型处理
            if isMagic:
                if self.isBaozhongbao():
                    isBaoZhongBao = True
                    nameBaoZhongBao = self.fanXing[self.BAOZHONGBAOJIA]['name']
                    indexBaoZhongBao = self.fanXing[
                        self.BAOZHONGBAOJIA]['index']
                    self.addWinFanPattern(nameBaoZhongBao, indexBaoZhongBao)
                    index += self.fanXing[self.BAOZHONGBAOJIA]['index']
                else:
                    index += self.fanXing[self.MOBAO]['index']
                    self.addWinFanPattern(self.fanXing[self.MOBAO]['name'],
                                          self.fanXing[self.MOBAO]['index'])
                    resultStat[self.winSeatId].append(
                        {MOneResult.STAT_MOBAO: 1})
            else:
                index += self.fanXing[self.ZIMO]['index']

            # 计算基本番型
            name, tempindex = self.calcBaseFan(isJia, isBian, isSanQi,
                                               isDanDiao, isPiao, isJiHu,
                                               isMagic)
            index += tempindex
            ftlog.debug('MBaichengOneResult.calcWin ZiMoFan index:', index)
        else:  # 点炮胡
            # 计算基本番型
            name, tempindex = self.calcBaseFan(isJia, isBian, isSanQi,
                                               isDanDiao, isPiao, isJiHu,
                                               isMagic)
            index += tempindex
            ftlog.debug('MBaichengOneResult.calcWin 点炮胡 index:', index)

        if isJiHu and not isPiao:
            namejihu = self.fanXing[self.JIHU]['name']
            indexjihu = self.fanXing[self.JIHU]['index']
            self.addWinFanPattern(namejihu, indexjihu)
            index += self.fanXing[self.JIHU]['index']

        # 赢家门清永远x2
        if self.menState[self.winSeatId] == 1:
            namemenqing = self.fanXing[self.MENQING]['name']
            indexmenqing = self.fanXing[self.MENQING]['index']
            self.addWinFanPattern(namemenqing, indexmenqing)
            index += self.fanXing[self.MENQING]['index']

        # 庄家赢x2
        if self.bankerSeatId == self.winSeatId:
            index += 1

        biMenFanConfig = self.tableConfig.get(MTDefine.BI_MEN_FAN, 0)
        # 当前局番型处理
        # 输赢模式 输家番型统计
        for seatId in range(self.playerCount):
            if seatId == self.winSeatId:
                winModeValue = MOneResult.WIN_MODE_PINGHU
                # 自摸
                if self.lastSeatId == self.winSeatId:
                    winModeValue = MOneResult.WIN_MODE_ZIMO
                if isMagic and isZiMo:
                    winModeValue = MOneResult.WIN_MODE_mobao
                if isBaoZhongBao:
                    winModeValue = MOneResult.WIN_MODE_baozhongbao
                if self.qiangGang:
                    winModeValue = MOneResult.WIN_MODE_QIANGGANGHU
                    self.addWinFanPattern(
                        self.fanXing[self.QIANGGANG]['name'],
                        self.fanXing[self.QIANGGANG]['index'])

                winMode[seatId] = winModeValue
                fanPattern[self.winSeatId] = self.winFanPattern
            elif seatId == self.lastSeatId:
                winModeValue = MOneResult.WIN_MODE_DIANPAO
                winMode[seatId] = winModeValue
                resultStat[seatId].append({MOneResult.STAT_DIANPAO: 1})
                fanPattern[seatId] = []
                # 点炮包庄
                if self.tableConfig.get(MTDefine.BAOZHUANG_BAOGANG, 0):
                    winModeValue = MOneResult.WIN_MODE_DIANPAO_BAOZHUANG
                    winMode[seatId] = winModeValue
                # 闭门
                if self.menState[seatId] == 1 and biMenFanConfig:
                    looseFanName = self.fanXing[self.BIMEN]['name']
                    looseFanIndex = self.fanXing[self.BIMEN]['index']
                    fanPattern[seatId].append(
                        [looseFanName.strip(),
                         str(looseFanIndex) + "番"])

            else:
                fanPattern[seatId] = []
                # 闭门
                if self.menState[seatId] == 1 and biMenFanConfig:
                    looseFanName = self.fanXing[self.BIMEN]['name']
                    looseFanIndex = self.fanXing[self.BIMEN]['index']
                    fanPattern[seatId].append(
                        [looseFanName.strip(),
                         str(looseFanIndex) + "番"])

        score = [index for _ in range(self.playerCount)]

        # 庄家输x2
        if self.bankerSeatId != self.winSeatId:
            score[self.bankerSeatId] += 1

        # 点炮x2
        if self.lastSeatId != self.winSeatId:
            score[self.lastSeatId] += 1

        # 如果选择背靠背 输家闭门x2
        for seatId in range(len(self.menState)):
            if biMenFanConfig and self.menState[
                    seatId] == 1 and seatId != self.winSeatId:
                score[seatId] += 1

        for seatId in range(self.playerCount):
            ftlog.debug('MBaichengOneResult calcGangInHand seatId:', seatId,
                        'self.playerCount', self.playerCount)
            # 手里三张和宝牌一样算暗杠
            if seatId != self.winSeatId:
                handTile = copy.deepcopy(
                    self.playerAllTiles[seatId][MHand.TYPE_HAND])
                handtileArr = MTile.changeTilesToValueArr(handTile)
                magicTiles = self.tableTileMgr.getMagicTiles(True)
                magictile = magicTiles[0]
                if handtileArr[magictile] == 3:
                    gangFanName = self.fanXing[self.BAOZHONGGANG]['name']
                    gangFanIndex = self.fanXing[self.BAOZHONGGANG]['index']
                    fanPattern[seatId].append(
                        [gangFanName.strip(),
                         str(gangFanIndex) + "番"])
                    break

        scoreIndex = self.tableConfig.get(MTDefine.FAN_LIST,
                                          [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
        oneLossLimit = self.tableConfig.get(MTDefine.MAX_LOSS_SCORE, 256)
        ftlog.debug('MBaichengOneResult.calcWin scoreIndex:', scoreIndex)
        winScore = 0
        for seatId in range(len(score)):
            if seatId != self.winSeatId:
                newIndex = score[seatId]
                score[seatId] = (-scoreIndex[newIndex]
                                 if scoreIndex[newIndex] < oneLossLimit else
                                 -oneLossLimit)
                winScore += abs(score[seatId])
        score[self.winSeatId] = winScore
        ftlog.debug('MBaichengOneResult.calcWin score before baopei:', score)

        if self.lastSeatId != self.winSeatId:
            if self.tableConfig.get(MTDefine.BAOZHUANG_BAOGANG, 0):
                # 包赔
                for seatId in range(len(score)):
                    if seatId != self.winSeatId and seatId != self.lastSeatId:
                        s = score[seatId]
                        score[seatId] = 0
                        score[self.lastSeatId] += s
                ftlog.debug(
                    'MBaichengOneResult.calcWin dianpaobaozhuang score:',
                    score, ' lastSeatId:', self.lastSeatId, ' winSeatId:',
                    self.winSeatId)

        # 单局最佳统计(分数)
        resultStat[self.winSeatId].append(
            {MOneResult.STAT_ZUIDAFAN: score[self.winSeatId]})

        # 白城无漂分,根据score计算最终结果
        self.results[self.KEY_TYPE] = '和牌'
        self.results[self.KEY_NAME] = name
        ftlog.debug('MBaichengOneResult.calcWin result score:', score)
        self.results[self.KEY_SCORE] = score
        ftlog.debug('MBaichengOneResult.calcWin result winMode:', winMode)
        self.results[self.KEY_WIN_MODE] = winMode
        self.results[self.KEY_STAT] = resultStat
        ftlog.debug('MBaichengOneResult.calcWin result fanPattern:',
                    fanPattern)
        self.results[self.KEY_FAN_PATTERN] = fanPattern
Beispiel #31
0
 def isMagicHu(self, tiles, tile, isTing, getTileType, magicTiles = [], tingNodes = [], curSeatId = 0, winSeatId = 0, actionID = 0, isGangKai = False):
     if len(magicTiles) >0:
         # 三金倒
         magicHu,pattern = MWin.isMagicHu(tiles,magicTiles[0],tile)
         #if magicHu and actionID > 1:
         return magicHu
Beispiel #32
0
    def isHu(self, tiles, tile, isTing, getTileType, magicTiles = [], tingNodes = [], curSeatId = 0, winSeatId = 0, actionID = 0, isGangKai = False,isForHu = True):
	#ftlog.debug('MWinRuleQueshou.isHu magicTiles=',magicTiles)

	result, pattern= MWin.isHu(tiles[MHand.TYPE_HAND], magicTiles)
	if not result:
            return False, [],0
	winMode = 0
	if not len(magicTiles):
	    return False, [],0
	if isTing and isForHu and len(magicTiles) > 0:
	    if tile != magicTiles[0]:
		return False,[],0
	    if getTileType != MWinRule.WIN_BY_MYSELF:
	        return False,[],0

        if self.tableConfig.get(MTDefine.QINGHUNYISE, 0):
            #ftlog.debug('isHu isqinghunyise called')
            if self.isHunyise(tiles,magicTiles):
                winMode = self.MODE_HUNYISE
		return result, pattern,winMode	
            if self.isQingyise(tiles):
                winMode = self.MODE_QINGYISE 
		return result, pattern,winMode

        if 1:	#self.tableConfig.get(MTDefine.DANDIAOSHENGJIN, 0):
            handTiles = copy.deepcopy(tiles[MHand.TYPE_HAND])
            handTiles.remove(tile)
            if len(handTiles) == 1 and handTiles[0] == magicTiles[0]:
                if getTileType != MWinRule.WIN_BY_MYSELF:
                    return False,[],0
	handTiles = copy.deepcopy(tiles[MHand.TYPE_HAND])
        if result and getTileType != MWinRule.WIN_BY_MYSELF:
            if tile == magicTiles[0]:
                return False,[],0 
            if self.canJinQue(magicTiles[0],pattern,handTiles,tile):
		handTiles = copy.deepcopy(tiles[MHand.TYPE_HAND])
		if not self.isJinQue(magicTiles[0],pattern,handTiles):
                    return False,[],0
	
	handTiles = copy.deepcopy(tiles[MHand.TYPE_HAND]) 
	if self.isYouJin(magicTiles[0],pattern,handTiles,tile):
	    if getTileType != MWinRule.WIN_BY_MYSELF:
		return False,[],0

        if getTileType == MWinRule.WIN_BY_MYSELF:
            winMode = self.MODE_ZIMO

        if self.isXiaoPingHu(winSeatId):
            winMode = self.MODE_XIAOPINGHU

        if self.isDaPingHu(winSeatId):
            winMode = self.MODE_DAPINGHU
	handTiles = copy.deepcopy(tiles[MHand.TYPE_HAND])

        if len(magicTiles) > 0 and self.isJinQue(magicTiles[0],pattern,handTiles):	#(magicTiles[0],pattern):
            winMode = self.MODE_JINQUE

        if isTing and getTileType == MWinRule.WIN_BY_MYSELF and len(magicTiles) > 0 and tile == magicTiles[0]:
            winMode = self.MODE_JINKAN
	'''
        if self.tableConfig.get(MTDefine.QINGHUNYISE, 0):
	    #ftlog.debug('isHu isqinghunyise called')
            if self.isHunyise(tiles,magicTiles):
                winMode = self.MODE_HUNYISE
            if self.isQingyise(tiles):
                winMode = self.MODE_QINGYISE
	'''
        return result, pattern,winMode
Beispiel #33
0
 def getHuPattern(self, tiles, magicTiles = []):
     return MWin.isHu(tiles[MHand.TYPE_HAND], magicTiles)
Beispiel #34
0
    def isHu(self,
             tiles,
             tile,
             isTing,
             getTileType,
             magicTiles=[],
             tingNodes=[],
             curSeatId=0,
             winSeatId=0,
             actionID=0,
             isGangKai=False,
             isForHu=True):

        if self.tableTileMgr.playMode == "luosihu-luosihu" and isForHu:
            if not isTing:
                if not self.tableTileMgr.players[winSeatId].isWon():
                    return False, [], 0

        allTiles = MHand.copyAllTilesToListButHu(tiles)
        tilesArr = MTile.changeTilesToValueArr(allTiles)
        # 需要缺一门: 定缺的时候约定的那门
        if self.absenceColor:
            if MTile.getTileCountByColor(tilesArr,
                                         self.absenceColor[winSeatId]) > 0:
                return False, [], 0
        result, pattern = self.isQidui(tiles)
        if result:
            if self.tableTileMgr.playMode == "luosihu-luosihu":
                self.fanXing[self.QIDUI]["index"] = 1
            return True, pattern, self.fanXing[self.QIDUI]["index"]

        result, pattern = MWin.isHu(tiles[MHand.TYPE_HAND], magicTiles)

        if result:
            ftlog.debug('MWinRuleLuosihu.isHu result=', result,
                        ' getTileType=', getTileType, ' pattern=', pattern)
            player = self.tableTileMgr.players[winSeatId]
            self.winSeatId = winSeatId
            self.__tile_pattern_checker = MTilePatternCheckerFactory.getTilePatternChecker(
                MPlayMode.LUOSIHU)
            playersAllTiles = [[] for _ in range(self.tableTileMgr.playCount)]
            self.__win_patterns = [[]
                                   for _ in range(self.tableTileMgr.playCount)]
            self.__win_patterns[winSeatId] = [pattern]
            for seatId in range(self.tableTileMgr.playCount):
                if seatId == winSeatId:
                    playersAllTiles[seatId] = copy.deepcopy(tiles)
                else:
                    playersAllTiles[seatId] = self.tableTileMgr.players[
                        seatId].copyTiles()
            self.setAllPlayerTiles(playersAllTiles)
            # 判断和牌的时候
            self.__tile_pattern_checker.initChecker(playersAllTiles, tile,
                                                    self.tableTileMgr, True,
                                                    curSeatId, winSeatId,
                                                    actionID)
            winnerResult = []
            if self.tableTileMgr.playMode == "luosihu-ctxuezhan":
                winnerResult = self.getWinnerResultsForXueZhanDaoDi(winSeatId)
            elif self.tableTileMgr.playMode == "luosihu-xuezhan":
                winnerResult = self.getWinnerResultsForLuoSiHuXueZhan(
                    winSeatId)
            elif self.tableTileMgr.playMode == "luosihu-luosihu":
                winnerResult = self.getWinnerResultsForLuoSiHu(winSeatId)
            finalResult = []
            finalResult.extend(winnerResult)
            maxFan = self.tableConfig.get(MTDefine.MAX_FAN, 0)
            winScore, indexFan = self.getScoreByResults(finalResult, maxFan)
            ftlog.debug('MWinRuleLuosihu.isHu player.guoHuPoint :', winScore,
                        ' finalResult=', finalResult, ' indexFan')
            # 过胡判断
            if getTileType == MWinRule.WIN_BY_MYSELF:
                return True, pattern, indexFan
            if player.guoHuPoint >= winScore and self.tableTileMgr.playMode == "luosihu-ctxuezhan":
                return False, [], 0
            player.totalWinPoint = winScore
            return True, pattern, indexFan

        return False, [], 0
Beispiel #35
0
 def getHuPattern(self, tiles, magicTiles=[]):
     return MWin.isHu(tiles[MHand.TYPE_HAND], magicTiles)
Beispiel #36
0
    def isHu(self,
             tiles,
             tile,
             isTing,
             getTileType,
             magicTiles=[],
             tingNodes=[],
             winSeatId=0):
        ftlog.debug(self.TAG, '.isHu tiles:', tiles, ' tile:', tile,
                    ' isTing:', isTing, ' getTileType:', getTileType,
                    ' magicTiles:', magicTiles, ' tingNodes:', tingNodes,
                    ' winSeatId:', winSeatId)
        # 不能和牌的情况: 放过锚手中有风牌或箭牌
        if len(tiles[MHand.TYPE_MAO]) > 0:
            if self.tableConfig[
                    MTDefine.
                    MAO_DAN_SETTING] & MTDefine.MAO_DAN_DNXBZFB:  #乱锚时手中有风牌或箭牌
                for T in tiles[MHand.TYPE_HAND]:
                    if T >= 31:
                        return False, []
            else:
                has_jmao = 0  #有箭牌
                has_fmao = 0  #有风牌
                for mao in tiles[MHand.TYPE_MAO]:
                    if mao['type'] == 1:
                        has_jmao = 1
                    if mao['type'] == 2:
                        has_fmao = 1
                if has_jmao:
                    for T in tiles[MHand.TYPE_HAND]:
                        if T >= 35:
                            return False, []
                if has_fmao:
                    for T in tiles[MHand.TYPE_HAND]:
                        if T >= 31 and T <= 34:
                            return False, []

        # 威海麻将允许胡七对
        resultQiDui, patternQiDui = MWin.isQiDui(tiles[MHand.TYPE_HAND])
        if resultQiDui:
            return True, patternQiDui

        ftlog.debug('MWinRuleWeihai 258jiang_config======:',
                    self.tableConfig[MTDefine.ONLY_JIANG_258])

        # 挑出2,5,8将,看剩下的牌是否能胡牌
        if self.tableConfig[MTDefine.ONLY_JIANG_258]:
            jiangPatterns = [[MTile.TILE_TWO_WAN, MTile.TILE_TWO_WAN],
                             [MTile.TILE_FIVE_WAN, MTile.TILE_FIVE_WAN],
                             [MTile.TILE_EIGHT_WAN, MTile.TILE_EIGHT_WAN],
                             [MTile.TILE_TWO_TONG, MTile.TILE_TWO_TONG],
                             [MTile.TILE_FIVE_TONG, MTile.TILE_FIVE_TONG],
                             [MTile.TILE_EIGHT_TONG, MTile.TILE_EIGHT_TONG],
                             [MTile.TILE_TWO_TIAO, MTile.TILE_TWO_TIAO],
                             [MTile.TILE_FIVE_TIAO, MTile.TILE_FIVE_TIAO],
                             [MTile.TILE_EIGHT_TIAO, MTile.TILE_EIGHT_TIAO]]
            for jiangPat in jiangPatterns:
                result, pattern = MWin.isHuWishSpecialJiang(
                    tiles[MHand.TYPE_HAND], jiangPat)
                ftlog.debug(
                    'MWinRuleWeihai isHuWishSpecialJiang.result======:',
                    result, 'pattern=====', pattern)
                if result:
                    return result, pattern
            return False, []
        else:
            result, pattern = MWin.isHu(tiles[MHand.TYPE_HAND])
            return result, pattern
Beispiel #37
0
    def calcWin(self):

        ftlog.debug(
            'MDandongOneResult.calcWin self.playerAllTiles[self.winSeatId]',
            self.playerAllTiles[self.winSeatId])

        resultwin = []
        if not self.tingState[self.winSeatId]:
            for tileTry in range(MTile.TILE_MAX_VALUE):
                if self.SatisyYaoJiu(self.playerAllTiles[self.winSeatId],
                                     tileTry):
                    handTile = copy.deepcopy(
                        self.playerAllTiles[self.winSeatId][MHand.TYPE_HAND])
                    handTile.append(tileTry)
                    ishu, pattern = MWin.isHu(handTile, [], True)
                    if ishu:
                        winNode = {}
                        winNode['winTile'] = tileTry
                        winNode['winTileCount'] = 2
                        for p in pattern:
                            p.sort()
                        winNode['pattern'] = pattern
                        resultwin.append(winNode)

            ftlog.debug(
                'MPanjinOneResult.calcWin MWin.isHu(handTile) resultwin',
                resultwin)
            self.setWinNodes(resultwin)

        self.results['type'] = MOneResult.KEY_TYPE_NAME_HU

        name = ''
        index = 0
        fanPattern = [[] for _ in range(self.playerCount)]
        winMode = [MOneResult.WIN_MODE_LOSS for _ in range(self.playerCount)]
        # 在和牌时统计自摸,点炮,最大番数
        resultStat = [[] for _ in range(self.playerCount)]

        resultStat[self.winSeatId].append({MOneResult.STAT_WIN: 1})
        # 正常和牌
        isZiMo = (self.lastSeatId == self.winSeatId)
        if isZiMo:
            resultStat[self.winSeatId].append({MOneResult.STAT_ZIMO: 1})

        isTianhu = False
        if self.tableConfig.get(MTDefine.TIAN_HU, 0):
            isTianhu = self.isTianHu()

        isPiao = self.isPiao()
        isDandiao = self.isDandiao()
        ftlog.debug('MDandongOneResult.calcWin:', ' isTianhu:', isTianhu,
                    ' isPiao:', isPiao, ' isDandiao:', isDandiao)

        self.clearWinFanPattern()

        if isZiMo:
            index += self.fanXing[self.ZIMO]['index']

        if self.tableConfig.get(MTDefine.DAN_DIAO_JIA, 0):
            if isDandiao:
                namejia = self.fanXing[self.JIAHU]['name']
                indexjia = self.fanXing[self.JIAHU]['index']
                self.addWinFanPattern(namejia, indexjia)
                index += self.fanXing[self.JIAHU]['index']

        if isPiao:
            namepiaohu = self.fanXing[self.PIAO]['name']
            indexpiaohu = self.fanXing[self.PIAO]['index']
            self.addWinFanPattern(namepiaohu, indexpiaohu)
            index += self.fanXing[self.PIAO]['index']

        # 赢家门清永远x2
        if self.menState[self.winSeatId] == 1:
            namemenqing = self.fanXing[self.MENQING]['name']
            indexmenqing = self.fanXing[self.MENQING]['index']
            self.addWinFanPattern(namemenqing, indexmenqing)
            index += self.fanXing[self.MENQING]['index']

        if self.tingState[self.winSeatId]:
            nameting = self.fanXing[self.TING]['name']
            indexting = self.fanXing[self.TING]['index']
            self.addWinFanPattern(nameting, indexting)
            index += self.fanXing[self.TING]['index']

        # 庄家赢x2
        if self.bankerSeatId == self.winSeatId:
            index += 1

        # 当前局番型处理
        # 输赢模式 输家番型统计
        biMenFanConfig = self.tableConfig.get(MTDefine.BI_MEN_FAN, 0)

        for seatId in range(self.playerCount):
            if seatId == self.winSeatId:
                winModeValue = MOneResult.WIN_MODE_PINGHU
                # 自摸
                if self.lastSeatId == self.winSeatId:
                    winModeValue = MOneResult.WIN_MODE_ZIMO

                winMode[seatId] = winModeValue
                fanPattern[self.winSeatId] = self.winFanPattern
            elif seatId == self.lastSeatId:
                winModeValue = MOneResult.WIN_MODE_DIANPAO
                winMode[seatId] = winModeValue
                resultStat[seatId].append({MOneResult.STAT_DIANPAO: 1})
                fanPattern[seatId] = []
                # 点炮包庄
                if self.tableConfig.get(MTDefine.BAOZHUANG_BAOGANG, 0):
                    winModeValue = MOneResult.WIN_MODE_DIANPAO_BAOZHUANG
                    winMode[seatId] = winModeValue
                # 闭门
                if self.menState[seatId] == 1 and biMenFanConfig:
                    looseFanName = self.fanXing[self.BIMEN]['name']
                    looseFanIndex = self.fanXing[self.BIMEN]['index']
                    fanPattern[seatId].append(
                        [looseFanName.strip(),
                         str(looseFanIndex) + "番"])

            else:
                fanPattern[seatId] = []
                # 闭门
                if self.menState[seatId] == 1 and biMenFanConfig:
                    looseFanName = self.fanXing[self.BIMEN]['name']
                    looseFanIndex = self.fanXing[self.BIMEN]['index']
                    fanPattern[seatId].append(
                        [looseFanName.strip(),
                         str(looseFanIndex) + "番"])

        score = [index for _ in range(self.playerCount)]

        # 庄家输x2
        if self.bankerSeatId != self.winSeatId:
            score[self.bankerSeatId] += 1
        # 点炮x2
        if self.lastSeatId != self.winSeatId:
            score[self.lastSeatId] += 1

        # 如果选择背靠背 输家闭门x2
        for seatId in range(len(self.menState)):
            if biMenFanConfig and self.menState[
                    seatId] == 1 and seatId != self.winSeatId:
                score[seatId] += 1

        scoreIndex = self.tableConfig.get(MTDefine.FAN_LIST,
                                          [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
        ftlog.debug('MDandongOneResult.calcWin scoreIndex:', scoreIndex)
        winScore = 0
        for seatId in range(len(score)):
            if seatId != self.winSeatId:
                newIndex = score[seatId]
                score[seatId] = -scoreIndex[newIndex]
                winScore += abs(score[seatId])
        score[self.winSeatId] = winScore
        ftlog.debug('MDandongOneResult.calcWin score before baopei:', score)

        # 加入底分的概念*2或者*5
        scoreBase = self.tableConfig.get(MTDefine.WIN_BASE, 1)
        ftlog.debug('MMudanjiangOneResult.calcWin scoreBase:', scoreBase)
        for seatId in range(len(score)):
            score[seatId] *= scoreBase

        # 包庄
        if self.lastSeatId != self.winSeatId:
            if self.tableConfig.get(MTDefine.BAOZHUANG_BAOGANG, 0):
                # 包赔
                for seatId in range(len(score)):
                    if seatId != self.winSeatId and seatId != self.lastSeatId:
                        s = score[seatId]
                        score[seatId] = 0
                        score[self.lastSeatId] += s
                ftlog.debug(
                    'MDandongOneResult.calcWin dianpaobaozhuang score:', score,
                    ' lastSeatId:', self.lastSeatId, ' winSeatId:',
                    self.winSeatId)

        # 单局最佳统计(分数)
        resultStat[self.winSeatId].append(
            {MOneResult.STAT_ZUIDAFAN: score[self.winSeatId]})

        self.results[self.KEY_TYPE] = '和牌'
        self.results[self.KEY_NAME] = name
        ftlog.debug('MDandongOneResult.calcWin result score:', score)
        self.results[self.KEY_SCORE] = score
        ftlog.debug('MDandongOneResult.calcWin result winMode:', winMode)
        self.results[self.KEY_WIN_MODE] = winMode
        self.results[self.KEY_STAT] = resultStat
        ftlog.debug('MDandongOneResult.calcWin result fanPattern:', fanPattern)
        self.results[self.KEY_FAN_PATTERN] = fanPattern
Beispiel #38
0
 def isHu(self, tiles, tile, isTing, getTileType, magicTiles = [], tingNodes = [], curSeatId = 0, winSeatId = 0, actionID = 0, isGangKai = False):
     result, pattern = MWin.isHu(tiles[MHand.TYPE_HAND], magicTiles)
     return result, pattern