def doQingYiSe(self, allTiles, leftTiles, seatId, abColors):
        '''
            是否做清一色
        '''
        isSanSha, bestColor = self.isSanShaQingYiSe(seatId, abColors)
        if isSanSha:
            ftlog.debug('SanSha, best situation!!! doSanShaQingYiSe')
            return True, bestColor

        length = 9
        if len(leftTiles) >= 50:
            length = 8
        elif len(leftTiles) >= 40:
            length = 9
        elif len(leftTiles) >= 30:
            length = 10
        elif len(leftTiles) >= 20:
            length = 11

        allTilesArr = MHand.copyAllTilesToList(allTiles)
        cpgTiles = MHand.copyTiles(
            allTiles, [MHand.TYPE_CHI, MHand.TYPE_PENG, MHand.TYPE_GANG])
        wans = MTile.filterTiles(allTilesArr, MTile.TILE_WAN)
        wanLength = len(wans)
        if wanLength >= length:
            for tile in cpgTiles:
                if MTile.getColor(tile) != MTile.TILE_WAN:
                    return False, MTile.TILE_FENG
            return True, MTile.TILE_WAN

        tongs = MTile.filterTiles(allTilesArr, MTile.TILE_TONG)
        tongLength = len(tongs)
        if tongLength >= length:
            for tile in cpgTiles:
                if MTile.getColor(tile) != MTile.TILE_TONG:
                    return False, MTile.TILE_FENG
            return True, MTile.TILE_TONG

        tiaos = MTile.filterTiles(allTilesArr, MTile.TILE_TIAO)
        tiaoLength = len(tiaos)
        if tiaoLength >= length:
            for tile in cpgTiles:
                if MTile.getColor(tile) != MTile.TILE_TIAO:
                    return False, MTile.TILE_FENG
            return True, MTile.TILE_TIAO

        if wanLength >= tongLength and wanLength >= tiaoLength:
            return False, MTile.TILE_WAN
        elif tongLength >= wanLength and tongLength >= tiaoLength:
            return False, MTile.TILE_TONG
        else:
            return False, MTile.TILE_TIAO
Esempio n. 2
0
    def isJiHu(self):
        # 只要牌里有幺鸡,就是鸡胡
        # tileArr = MTile.changeTilesToValueArr(MHand.copyAllTilesToList(self.playerAllTiles[self.winSeatId]))
        iszimo = self.lastSeatId == self.winSeatId

        tempCount = MTile.getTileCount(
            MTile.TILE_ONE_TIAO,
            MHand.copyAllTilesToList(self.playerAllTiles[self.winSeatId]))
        ftlog.debug('MBaichengOneResult.calcWin isJiHu tempCount:', tempCount)

        magics = self.tableTileMgr.getMagicTiles(True)
        if iszimo and (self.winTile == magics[0] == MTile.TILE_ONE_TIAO):
            isHuYaoji = False
            for wn in self.winNodes:
                if wn['winTile'] == MTile.TILE_ONE_TIAO:
                    isHuYaoji = True
            if isHuYaoji:
                return True
            else:
                if tempCount <= 1:
                    return False
                else:
                    return True

        else:
            # 胡牌
            if tempCount >= 1:
                return True
            else:
                return False
Esempio n. 3
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, []
Esempio n. 4
0
    def initChecker(self, playersAllTiles, winTile, tableTileMgr, isWinTileOnHand, curSeatId, winSeatId, actionID = 0):
        self.setLastSeatId(curSeatId)
        self.setWinSeatId(winSeatId)
        self.setActionID(actionID)
        self.setWinTile(winTile)
        self.setTableTileMgr(tableTileMgr)
        self.setTableConfig(self.tableTileMgr.tableConfig)
        self.__player_all_tiles = [[] for _ in range(self.tableTileMgr.playCount)]
        self.__player_all_tiles_arr = [[] for _ in range(self.tableTileMgr.playCount)]
        self.__player_hand_tiles_with_hu = [[] for _ in range(self.tableTileMgr.playCount)]

        # 不要用tableTileMgr.player里面的牌,因为可能这些牌还没抓到用户手里,以传入的playersAllTiles为准
        for seatId in range(len(playersAllTiles)):
            # 按手牌格式的数组
            self.__player_all_tiles[seatId] = copy.deepcopy(playersAllTiles[seatId])
            # 合到一个数组中
            self.__player_all_tiles_arr[seatId].extend(MHand.copyAllTilesToList(self.__player_all_tiles[seatId]))
            # 只获取手牌,此时手牌包含所胡的牌
            self.__player_hand_tiles_with_hu[seatId] = copy.deepcopy(playersAllTiles[seatId][MHand.TYPE_HAND])
            if not isWinTileOnHand and seatId == winSeatId:
                self.__player_hand_tiles_with_hu[seatId].append(winTile)

        ftlog.info('MTilePatternChecker.calcScore __player_all_tiles=', self.__player_all_tiles)
        ftlog.info('MTilePatternChecker.calcScore __player_all_tiles_arr=', self.__player_all_tiles_arr)
        ftlog.info('MTilePatternChecker.calcScore __player_hand_tiles_with_hu=', self.__player_hand_tiles_with_hu)
Esempio n. 5
0
    def isJiHu(self):
        # 只要牌里有幺鸡,就是鸡胡
        # tileArr = MTile.changeTilesToValueArr(MHand.copyAllTilesToList(self.playerAllTiles[self.winSeatId]))
        if self.tableConfig.get(MTDefine.HUI_PAI, 0) and self.tableConfig.get(
                MTDefine.JI_HU, 0):
            magics = self.tableTileMgr.getMagicTiles(True)
            if magics[0] == MTile.TILE_ONE_TIAO == self.winTile:
                playerHandTiles = copy.deepcopy(
                    self.playerAllTiles[self.winSeatId][MHand.TYPE_HAND])
                if MTile.TILE_ONE_TIAO in playerHandTiles:
                    return False
                else:
                    return True

        if self.tableConfig.get(MTDefine.JI_HU, 0):
            tempCount = MTile.getTileCount(
                MTile.TILE_ONE_TIAO,
                MHand.copyAllTilesToList(self.playerAllTiles[self.winSeatId]))
            ftlog.debug('MPanjinOneResult.calcWin isJiHu tempCount:',
                        tempCount)
            # 胡牌
            if tempCount >= 1:
                return True
            else:
                return False

        return False
Esempio n. 6
0
 def canTing(self, tiles, leftTiles, tile, magicTiles=[], winSeatId=0):
     """子类必须实现
     参数:
     1)tiles 该玩家的手牌
     返回值:
     是否可以听牌,听牌详情
     """
     # 血流 血战听牌 需要没有缺牌
     tileArr = MTile.changeTilesToValueArr(MHand.copyAllTilesToList(tiles))
     # 获取当前座位号定缺的花色
     colorAbsence = self.tableTileMgr.absenceColors[winSeatId]
     # 获取手牌中定缺花色牌的数量,大于1,不用判断听 缺牌为1张的时候,打出去缺牌,有可能会听牌
     colorAbsenceNum = MTile.getTileCountByColor(tileArr, colorAbsence)
     # ftlog.debug('MTingRuleSiChuan.canTing colorAbsenceNum:', colorAbsenceNum, 'tiles:', tiles, 'tile:', tile, 'colorAbsence:', colorAbsence)
     if colorAbsenceNum > 1:
         return False, []
     resultFlag, result = MTing.canTing(self.tilePatternChecker, self.tableTileMgr, tiles, leftTiles, self.winRuleMgr, tile, magicTiles, winSeatId)
     # 如果听牌中有定的缺色,需要把其余的听口去掉
     ftlog.debug('MTingRuleSiChuan.canTing result:', result)
     if resultFlag and colorAbsenceNum == 1:
         filterResult = []
         for tingNodes in result:
             if MTile.getColor(tingNodes['dropTile']) == colorAbsence:
                 filterResult.append(tingNodes)
         ftlog.debug('MTingRuleSiChuan.canTing filterResult:', filterResult)
         return len(filterResult) > 0, filterResult   
     else:
         return resultFlag, result 
    def doQingYiSe(self, allTiles, leftTiles):
        '''
            是否做清一色
        '''
        length = 9
        if len(leftTiles) >= 50:
            length = 8
        elif len(leftTiles) >= 40:
            length = 9
        elif len(leftTiles) >= 30:
            length = 10
        elif len(leftTiles) >= 20:
            length = 11

        allTilesArr = MHand.copyAllTilesToList(allTiles)
        cpgTiles = MHand.copyTiles(
            allTiles, [MHand.TYPE_CHI, MHand.TYPE_PENG, MHand.TYPE_GANG])
        wans = MTile.filterTiles(allTilesArr, MTile.TILE_WAN)
        wanLength = len(wans)
        if wanLength >= length:
            for tile in cpgTiles:
                if MTile.getColor(tile) != MTile.TILE_WAN:
                    return False, MTile.TILE_FENG
            return True, MTile.TILE_WAN

        tongs = MTile.filterTiles(allTilesArr, MTile.TILE_TONG)
        tongLength = len(tongs)
        if tongLength >= length:
            for tile in cpgTiles:
                if MTile.getColor(tile) != MTile.TILE_TONG:
                    return False, MTile.TILE_FENG
            return True, MTile.TILE_TONG

        tiaos = MTile.filterTiles(allTilesArr, MTile.TILE_TIAO)
        tiaoLength = len(tiaos)
        if tiaoLength >= length:
            for tile in cpgTiles:
                if MTile.getColor(tile) != MTile.TILE_TIAO:
                    return False, MTile.TILE_FENG
            return True, MTile.TILE_TIAO

        if wanLength >= tongLength and wanLength >= tiaoLength:
            return False, MTile.TILE_WAN
        elif tongLength >= wanLength and tongLength >= tiaoLength:
            return False, MTile.TILE_TONG
        else:
            return False, MTile.TILE_TIAO
Esempio n. 8
0
    def isQingyise(self, tiles):
        """
        清一色:由同一门花色(筒子或条子)组成的和牌牌型
        """
        tileArr = MTile.changeTilesToValueArr(MHand.copyAllTilesToListButHu(tiles))
        colors = MTile.getColorCount(tileArr)
        #ftlog.debug('MWinRuleQueshou.isQingyise tileArr=',tileArr,colors)
	return colors == 1
Esempio n. 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
Esempio n. 10
0
 def isQingyise(self, tiles):
     """
     清一色:由同一门花色(筒子或条子)组成的和牌牌型
     """
     tileArr = MTile.changeTilesToValueArr(
         MHand.copyAllTilesToListButHu(tiles))
     colors = MTile.getColorCount(tileArr)
     #ftlog.debug('MWinRuleQueshou.isQingyise tileArr=',tileArr,colors)
     return colors == 1
Esempio n. 11
0
 def isZhangYiSe(self, seatId):
     tiles = MHand.copyAllTilesToList(self.playerAllTiles[self.winSeatId])
     if len(tiles) % 2 > 0:
         tiles.extend(self.playerAllTiles[self.winSeatId][MHand.TYPE_HU])
     for tile in tiles:
         if (tile >= MTile.TILE_DONG_FENG) or (MTile.getValue(tile) % 3 !=
                                               2):
             return False
     return True
    def isQingYiSe(self, allTiles, qingColor):
        '''
        判断当前是否是清一色
        '''
        allTilesArr = MHand.copyAllTilesToList(allTiles)
        for tile in allTilesArr:
            if MTile.getColor(tile) != qingColor:
                return False

        return True
Esempio n. 13
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
Esempio n. 14
0
 def getLongGenCount(self):
     '''
     获取玩家手牌根的个数 杠过的牌也算
     ''' 
     count = 0
     tiles = MHand.copyAllTilesToListButHu(self.playerAllTiles)
     tileArr = MTile.changeTilesToValueArr(tiles)
     for tile in tileArr:
         if tile == 4:
             count += 1
     return count
Esempio n. 15
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
Esempio n. 16
0
    def isQingYiSe(self):
        if self.colorState[self.winSeatId] == 1:
            return True

        if self.isMagicTile():
            tileArr = MTile.changeTilesToValueArr(
                MHand.copyAllTilesToListButHu(
                    self.playerAllTiles[self.winSeatId]))
            tempCountColor = MTile.getColorCount(tileArr)
            if tempCountColor == 1:
                return True

        return False
Esempio n. 17
0
 def isQuanJiang(self):
     '''
     判断是否全将
     血流血战的独特番型,所有的牌都是2,5,8
     '''
     tiles = MHand.copyAllTilesToListButHu(self.playerAllTiles)
     jiang258 = [2, 5, 8, 12, 15, 18, 22, 25, 28]
     ftlog.debug('MSiChuanOneResult.isQuanJiang tiles:', tiles)
     for tile in tiles:
         if tile not in jiang258:
             ftlog.debug('MSiChuanOneResult.isQuanJiang: False')
             return False
     ftlog.debug('MSiChuanOneResult.isQuanJiang: True')
     return True
Esempio n. 18
0
 def SatisyYaoJiu(self,tiles):
     #有幺九
     allTiles = MHand.copyAllTilesToList(tiles)
     tilesArr = MTile.changeTilesToValueArr(allTiles)
     
     yaojiucount = MTile.getYaoJiuCount(tilesArr)
     if yaojiucount>0:
         return True
     else:
         for feng in range(MTile.TILE_DONG_FENG,MTile.TILE_BAI_BAN+1):
             if tilesArr[feng]>=1:
                 return True
                 
     return False
Esempio n. 19
0
    def SatisyKe(self,tiles):
        #有刻
        if len(tiles[MHand.TYPE_PENG])==0:
            ming,an = MTile.calcGangCount(tiles[MHand.TYPE_GANG])
            if (ming + an) ==0:
                allTiles = MHand.copyAllTilesToList(tiles)
                tilesArr = MTile.changeTilesToValueArr(allTiles)
                #中发白做将
                if tilesArr[MTile.TILE_HONG_ZHONG] < 2 and tilesArr[MTile.TILE_FA_CAI] < 2 and tilesArr[MTile.TILE_BAI_BAN] < 2:
                    #中发白
                    if not self.hasKe(tiles[MHand.TYPE_HAND]):
                        return False

        return True
Esempio n. 20
0
    def isDuanYaoJiu(self):
        """
        断幺九:每副顺子,刻字,将牌都不包含1或9
        """
        if self.tableConfig.get(MTDefine.DUANYAOJIU, 0) != 1:
            return False
        
        allPlayerTiles = MHand.copyAllTilesToList(self.tableTileMgr.players[self.winSeatId].copyTiles())
        yaoJiuCount = 0
        for tile in allPlayerTiles:
            if MTile.getColor(tile) == MTile.TILE_FENG or tile%10 == 1 or tile%10 == 9:
                yaoJiuCount += 1

        return yaoJiuCount == 0
Esempio n. 21
0
    def isHunyise(self):
        """
        混一色:只有一色牌(如全是万),有金牌,但金牌不同色
        """
	'''
        colorArr = [0, 0, 0, 0]
        handTile = MHand.copyAllTilesToList(self.playerAllTiles[self.winSeatId])  # 手牌区+吃+碰+杠+锚+胡区
        for tile in handTile:
            color = MTile.getColor(tile)
            colorArr[color] = 1
        
        magicTile = self.tableTileMgr.getMagicTile()
        magicTileColor = MTile.getColor(magicTile)
	
	handTile = MHand.copyAllTilesToList(self.playerAllTiles[self.winSeatId])
        tilesArr = MTile.changeTilesToValueArr(handTile)
        count = MTile.getTileCountByColor(tilesArr, magicTileColor)

        magicCount = MTile.getTileCount(magicTile,handTile[MHand.TYPE_HAND])
	
        if count!=magicCount:
            return False
	
        colorCount = 0
        for eachColor in colorArr:
            if eachColor:
                colorCount += 1
        if colorCount == 2 and colorArr[magicTileColor] == 1:
            return True
        return False
	'''
	magicTile = self.tableTileMgr.getMagicTile()
	magicCount = 0
	allTiles = MHand.copyAllTilesToList(self.playerAllTiles[self.winSeatId])
        #allTiles = MHand.copyAllTilesToListButHu(handTile)
        allTileArr = MTile.changeTilesToValueArr(allTiles)
        allColors = MTile.getColorCount(allTileArr)
        for tile in allTiles:
            if magicTile and tile == magicTile:
		magicCount = magicCount + 1

        for i in range(magicCount):
            allTiles.remove(magicTile)

        tileArr = MTile.changeTilesToValueArr(allTiles)
        colors = MTile.getColorCount(tileArr)

        if allColors == 2 and colors == 1:
            return True
        return False 
Esempio n. 22
0
    def SatisyYaoJiu(self,tiles):
        #有幺九
        if len(tiles[MHand.TYPE_MAO])==0:
            allTiles = MHand.copyAllTilesToList(tiles)
            tilesArr = MTile.changeTilesToValueArr(allTiles)
            #中发白做将
            if tilesArr[MTile.TILE_HONG_ZHONG] < 2 and tilesArr[MTile.TILE_FA_CAI] < 2 and tilesArr[MTile.TILE_BAI_BAN] < 2:
                #中发白
                if not (tilesArr[MTile.TILE_HONG_ZHONG]>0 and tilesArr[MTile.TILE_FA_CAI]>0 and tilesArr[MTile.TILE_BAI_BAN]>0):
                    yaojiucount = MTile.getYaoJiuCount(tilesArr)
                    if yaojiucount==0:
                        return False

        return True
Esempio n. 23
0
 def canTing(self, tiles, leftTiles, tile, magicTiles=[], winSeatId=0):
     """子类必须实现
     参数:
     1)tiles 该玩家的手牌
     返回值:
     是否可以听牌,听牌详情
     """
     tileArr = MTile.changeTilesToValueArr(MHand.copyAllTilesToList(tiles))
     resultFlag, result = MTing.canTing(self.tilePatternChecker,
                                        self.tableTileMgr, tiles, leftTiles,
                                        self.winRuleMgr, tile, magicTiles,
                                        winSeatId)
     ftlog.debug('MTingJiPingHuRule.canTing result:', resultFlag, result)
     return resultFlag, result
Esempio n. 24
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, []
Esempio n. 25
0
    def SatisyYaoJiu(self, tiles):
        #有幺九
        allTiles = MHand.copyAllTilesToList(tiles)
        tilesArr = MTile.changeTilesToValueArr(allTiles)
        if self.tableConfig.get(MTDefine.HUI_PAI, 0):
            magics = self.tableTileMgr.getMagicTiles(True)
            tilesArr[magics[0]] = 0

        yaojiucount = MTile.getYaoJiuCount(tilesArr)
        if yaojiucount > 0:
            return True
        else:
            for feng in range(MTile.TILE_DONG_FENG, MTile.TILE_BAI_BAN + 1):
                if tilesArr[feng] >= 1:
                    return True

        return False
Esempio n. 26
0
    def isDuanYaoJiu(self):
        """
        断幺九:每副顺子,刻字,将牌都不包含1或9
        """
        if self.tableConfig.get(MTDefine.DUANYAOJIU, 0) != 1:
            return False

        allPlayerTiles = MHand.copyAllTilesToList(
            self.tableTileMgr.players[self.winSeatId].copyTiles())
        yaoJiuCount = 0
        for tile in allPlayerTiles:
            if MTile.getColor(
                    tile
            ) == MTile.TILE_FENG or tile % 10 == 1 or tile % 10 == 9:
                yaoJiuCount += 1

        return yaoJiuCount == 0
Esempio n. 27
0
    def isQingyise(self):
        """
        清一色:只有一色牌(如全是万),有无金牌皆可,但金牌必须与其他牌同色
        """
        colorArr = [0, 0, 0, 0]
        handTile = MHand.copyAllTilesToList(self.playerAllTiles[self.winSeatId])  # 手牌区+吃+碰+杠+锚+胡区

        for tile in handTile:
            color = MTile.getColor(tile)
            colorArr[color] = 1

        colorCount = 0
        for eachColor in colorArr:
            if eachColor:
                colorCount += 1
        if colorCount == 1:
            return True
        return False
Esempio n. 28
0
 def isDuanYao(self, tableConfig):
     '''
     判断手牌是否为断幺
     '''
     # 房间配置为0,则没有全幺九
     if not tableConfig.get(MFTDefine.DUANYAOJIU_DOUBLE, 0):
         ftlog.debug('MSiChuanTilePattern.isDuanYao False because roomConfig')
         return False
     
     tiles = MHand.copyAllTilesToListButHu(self.playerAllTiles)
     ftlog.debug('MSiChuanTilePattern.isDuanYao tiles:', tiles)
     for tile in tiles:
         tileValue = MTile.getValue(tile)
         if tileValue == 1 or tileValue == 9:
             ftlog.debug('MSiChuanTilePattern.isDuanYao : False')
             return False
     ftlog.debug('MSiChuanTilePattern.isDuanYao: True')
     return True
Esempio n. 29
0
    def initChecker(self,
                    playersAllTiles,
                    winTile,
                    tableTileMgr,
                    isWinTileOnHand,
                    curSeatId,
                    winSeatId,
                    actionID=0):
        self.setLastSeatId(curSeatId)
        self.setWinSeatId(winSeatId)
        self.setActionID(actionID)
        self.setWinTile(winTile)
        self.setTableTileMgr(tableTileMgr)
        self.setTableConfig(self.tableTileMgr.tableConfig)
        self.__player_all_tiles = [[]
                                   for _ in range(self.tableTileMgr.playCount)]
        self.__player_all_tiles_arr = [
            [] for _ in range(self.tableTileMgr.playCount)
        ]
        self.__player_hand_tiles_with_hu = [
            [] for _ in range(self.tableTileMgr.playCount)
        ]

        # 不要用tableTileMgr.player里面的牌,因为可能这些牌还没抓到用户手里,以传入的playersAllTiles为准
        for seatId in range(len(playersAllTiles)):
            # 按手牌格式的数组
            self.__player_all_tiles[seatId] = copy.deepcopy(
                playersAllTiles[seatId])
            # 合到一个数组中
            self.__player_all_tiles_arr[seatId].extend(
                MHand.copyAllTilesToList(self.__player_all_tiles[seatId]))
            # 只获取手牌,此时手牌包含所胡的牌
            self.__player_hand_tiles_with_hu[seatId] = copy.deepcopy(
                playersAllTiles[seatId][MHand.TYPE_HAND])
            if not isWinTileOnHand and seatId == winSeatId:
                self.__player_hand_tiles_with_hu[seatId].append(winTile)

        ftlog.info('MTilePatternChecker.calcScore __player_all_tiles=',
                   self.__player_all_tiles)
        ftlog.info('MTilePatternChecker.calcScore __player_all_tiles_arr=',
                   self.__player_all_tiles_arr)
        ftlog.info(
            'MTilePatternChecker.calcScore __player_hand_tiles_with_hu=',
            self.__player_hand_tiles_with_hu)
Esempio n. 30
0
    def SatisyKe2(self,tiles):
        #有刻
        if len(tiles[MHand.TYPE_MAO])>0 or len(tiles[MHand.TYPE_PENG])>0:
            return True
        
        ming,an = MTile.calcGangCount(tiles[MHand.TYPE_GANG])
        if (ming + an) >0:
            return True
        
        allTiles = MHand.copyAllTilesToList(tiles)
        tilesArr = MTile.changeTilesToValueArr(allTiles)
        #中发白做将
        if tilesArr[MTile.TILE_HONG_ZHONG] >= 2 or tilesArr[MTile.TILE_FA_CAI] >= 2 or tilesArr[MTile.TILE_BAI_BAN] >= 2:
            return True
        
        #中发白
        if (tilesArr[MTile.TILE_HONG_ZHONG]>0 and tilesArr[MTile.TILE_FA_CAI]>0 and tilesArr[MTile.TILE_BAI_BAN]>0):
            return True

        return False
Esempio n. 31
0
    def isHunyise(self, tiles, magicTiles):
        if not len(magicTiles):
            return False
        magicTile = magicTiles[0]
        magicCount = 0
        allTiles = MHand.copyAllTilesToListButHu(tiles)
        allTileArr = MTile.changeTilesToValueArr(allTiles)
        allColors = MTile.getColorCount(allTileArr)
        for tile in allTiles:
            if tile == magicTile:
                magicCount = magicCount + 1

        for i in range(magicCount):
            allTiles.remove(magicTile)

        tileArr = MTile.changeTilesToValueArr(allTiles)
        colors = MTile.getColorCount(tileArr)
        #ftlog.debug('MWinRuleQueshou.isHunyise allColors colors=',allColors,colors,magicCount,allTiles)
        if allColors == 2 and colors == 1:
            return True
        return False
Esempio n. 32
0
    def isHunyise(self, tiles, magicTiles):
	if not len(magicTiles):
	    return False
	magicTile = magicTiles[0]
	magicCount = 0
        allTiles = MHand.copyAllTilesToListButHu(tiles)
        allTileArr = MTile.changeTilesToValueArr(allTiles)
        allColors = MTile.getColorCount(allTileArr)
        for tile in allTiles:
	    if tile == magicTile:
		magicCount = magicCount + 1

        for i in range(magicCount):
            allTiles.remove(magicTile)

        tileArr = MTile.changeTilesToValueArr(allTiles)
        colors = MTile.getColorCount(tileArr)
	#ftlog.debug('MWinRuleQueshou.isHunyise allColors colors=',allColors,colors,magicCount,allTiles)
        if allColors == 2 and colors == 1:
            return True
        return False 
Esempio n. 33
0
    def isQingyise(self):
        """
        清一色:由同一门花色(筒子或条子)组成的和牌牌型
        """
        colorArr = [0, 0, 0, 0]
        handTile = MHand.copyAllTilesToList(self.playerAllTiles[self.winSeatId])  # 手牌区+吃+碰+杠+锚+胡区

        ftlog.debug('jinan_one_result.isQingyise handTile=', handTile)

        for tile in handTile:
            color = MTile.getColor(tile)
            colorArr[color] = 1

        colorCount = 0
        for eachColor in colorArr:
            if eachColor:
                colorCount += 1
        if colorCount == 1 and colorArr[3] == 0:
            ftlog.debug('jinan_one_result.isQingyise result: True')
            return True
        ftlog.debug('jinan_one_result.isQingyise result: False')
        return False
Esempio n. 34
0
    def isHunyise(self):
        """
        混一色:由东南西北中发白 + 万、条、筒中的任意一种组成的胡牌
        """
        colorArr = [0, 0, 0, 0]
        handTile = MHand.copyAllTilesToList(self.playerAllTiles[self.winSeatId])  # 手牌区+吃+碰+杠+锚+胡区

        ftlog.debug('jinan_one_result.isHunyise handTile=', handTile)

        for tile in handTile:
            color = MTile.getColor(tile)
            colorArr[color] = 1

        colorCount = 0
        for eachColor in colorArr:
            if eachColor:
                colorCount += 1
        if colorCount == 2 and colorArr[3] == 1:
            ftlog.debug('jinan_one_result.isHunyise result: True')
            return True
        ftlog.debug('jinan_one_result.isHunyise result: False')
        return False
Esempio n. 35
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