def isQingyise(self, tiles): """ 清一色:由同一门花色(筒子或条子)组成的和牌牌型 """ tileArr = MTile.changeTilesToValueArr(MHand.copyAllTilesToListButHu(tiles)) colors = MTile.getColorCount(tileArr) #ftlog.debug('MWinRuleQueshou.isQingyise tileArr=',tileArr,colors) return colors == 1
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
def isQingyise(self, tiles): """ 清一色:由同一门花色(筒子或条子)组成的和牌牌型 """ tileArr = MTile.changeTilesToValueArr( MHand.copyAllTilesToListButHu(tiles)) colors = MTile.getColorCount(tileArr) #ftlog.debug('MWinRuleQueshou.isQingyise tileArr=',tileArr,colors) return colors == 1
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
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
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
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
def SatisyYaoJiu(self, tiles, addtile=-1): # 有幺九 allTiles = MHand.copyAllTilesToListButHu(tiles) if addtile != -1: allTiles.append(addtile) 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
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
def SatisyYaoJiu(self, tiles, addtile=-1): # 有幺九 if len(tiles[MHand.TYPE_MAO]) == 0: allTiles = MHand.copyAllTilesToListButHu(tiles) if addtile != -1: allTiles.append(addtile) 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
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
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
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