示例#1
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
示例#2
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, []
示例#3
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
示例#4
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
示例#5
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
示例#6
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, []
示例#7
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
示例#8
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, []
示例#9
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
示例#10
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
示例#11
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

        # 烟台麻将允许胡七对
        resultQiDui, patternQiDui = MWin.isQiDui(tiles[MHand.TYPE_HAND])
        if resultQiDui:
            if self.tableConfig[MTDefine.ONLY_JIANG_258]:
                ftlog.debug('MWinRuleYantai.isHu checkQiDui with 258')
                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, []
            return True, patternQiDui

        # 烟台麻将允许胡十三幺
        self.tilePatternChecker.setPlayerAllTiles(tiles)
        if self.tilePatternChecker.isShisanyao():
            if self.tableConfig[MTDefine.ONLY_JIANG_258]:
                ftlog.debug(
                    'MWinRuleYantai.isHu isShisanyao with 258, return False')
                return False, []
            return True, tiles[MHand.TYPE_HAND]

        # 烟台麻将允许胡风一色
        allTiles = MHand.copyAllTilesToList(tiles)
        allArr = MTile.changeTilesToValueArr(allTiles)
        colorCount = MTile.getColorCount(allArr)
        resultFeng, patternFeng = MWin.isLuanFengyise(tiles[MHand.TYPE_HAND],
                                                      colorCount)
        if resultFeng:
            if self.tableConfig[MTDefine.ONLY_JIANG_258]:
                ftlog.debug(
                    'MWinRuleYantai.isHu isLuanFengyise with 258, return False'
                )
                return False, []
            return True, patternFeng

        # 挑出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]]
            ftlog.debug('MWinRuleYantai.isHu with 258')
            for jiangPat in jiangPatterns:
                result, pattern = MWin.isHuWishSpecialJiang(
                    tiles[MHand.TYPE_HAND], jiangPat)
                if result:
                    return result, pattern

            return False, []
        else:
            result, pattern = MWin.isHu(tiles[MHand.TYPE_HAND])
            return result, pattern
示例#12
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 self.tableTileMgr.isPassHuTileBySeatId(winSeatId, tile):
            return False, []

        # 济南麻将允许胡七对
        qiduiTiles = copy.deepcopy(tiles)
        resultQiDui, patternQiDui = MWin.isQiDui(qiduiTiles[MHand.TYPE_HAND])
        if resultQiDui:
            if self.tableConfig[MTDefine.ONLY_JIANG_258]:
                for pattern in patternQiDui:
                    tile = pattern[0]
                    if tile > MTile.TILE_NINE_TIAO:
                        continue

                    # 选了258将判断这里,而且不能是风牌
                    if (MTile.getValue(pattern[0]) % 3
                            == 2) and pattern[0] < MTile.TILE_DONG_FENG:
                        return True, patternQiDui
                return False, []
            else:
                return resultQiDui, patternQiDui

        # 花胡
        if getTileType == MWinRule.WIN_BY_MYSELF:
            flowerTiles = copy.deepcopy(tiles)
            resFlowerHu, patternFlowerHu = MWin.isFlowerHu(flowerTiles)
            if resFlowerHu:
                return resFlowerHu, patternFlowerHu

        # 全将
        jiangTiles = copy.deepcopy(tiles)
        resQuanj, patternQuanj = MWin.isQuanJiang(jiangTiles)
        if resQuanj:
            return resQuanj, patternQuanj

        # 十三不靠
        if not self.tableConfig[MTDefine.ONLY_JIANG_258]:
            bukaoTiles = copy.deepcopy(tiles)
            res13Bukao, pattern13Bukao = MWin.is13BuKao(
                bukaoTiles[MHand.TYPE_HAND])
            if res13Bukao:
                return res13Bukao, pattern13Bukao

        # 挑出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]]

            jiangTiles = copy.deepcopy(tiles)
            for jiangPat in jiangPatterns:
                result, pattern = MWin.isHuWishSpecialJiang(
                    jiangTiles[MHand.TYPE_HAND], jiangPat)
                if result:
                    return result, pattern
        else:
            newTiles = copy.deepcopy(tiles)
            result, pattern = MWin.isHu(newTiles[MHand.TYPE_HAND])
            return result, pattern

        return False, []