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
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, []
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 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
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)
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)
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 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
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, []
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
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
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
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
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
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
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
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
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
def isHu(self, tiles, tile, isTing, getTileType, magicTiles = [], tingNodes = [], winSeatId = 0): result, pattern = MWin.isHu(tiles[MHand.TYPE_HAND], magicTiles) return result, pattern
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
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
def getHuPattern(self, tiles, magicTiles = []): return MWin.isHu(tiles[MHand.TYPE_HAND], magicTiles)
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, []
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
def getHuPattern(self, tiles, magicTiles=[]): return MWin.isHu(tiles[MHand.TYPE_HAND], magicTiles)
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
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
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
def isHu(self, tiles, tile, isTing, getTileType, magicTiles=[], tingNodes=[], winSeatId=0): #tile已经加入到tiles ftlog.debug('MWinRulePanjin.isHu tiles:', tiles, ' magicTiles:', magicTiles, ' tile:', tile) if self.tableTileMgr.isPassHuTileBySeatId(winSeatId, tile): return False, [] #是否允许闭门胡 if not self.tableConfig.get(MTDefine.BI_MEN_FAN, 0): if len(tiles[MHand.TYPE_HAND]) == 14: return False, [] # 三色全 allTiles = MHand.copyAllTilesToList(tiles) #避免摸宝时候检查三色全问题,所以剔除最后一张 allTiles.remove(tile) #会牌剔除 if self.tableConfig.get(MTDefine.HUI_PAI, 0): magics = self.tableTileMgr.getMagicTiles(True) while magics[0] in allTiles: allTiles.remove(magics[0]) 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, [] result, pattern = MWin.isHu(tiles[MHand.TYPE_HAND], magicTiles, True) ftlog.debug('MWinRulePanjin.isHu tiles:', result, ' pattern:', pattern) if not result: return False, [] else: keAlreadyhas = self.SatisyKe2(tiles) if keAlreadyhas: return True, pattern else: #检查胡牌番型pattern,要有刻 for p in pattern: if len(p) == 3 and (p[0] == p[2] or p[1] == p[2] or p[0] == p[1]): return True, pattern elif len(p) == 2: if (p[0] in range(MTile.TILE_DONG_FENG,MTile.TILE_BAI_BAN+1)) \ or (p[1] in range(MTile.TILE_DONG_FENG,MTile.TILE_BAI_BAN+1)): return True, pattern if self.tableConfig.get(MTDefine.HUI_PAI, 0): if (p[0] == p[1] == magicTiles[0]): return True, pattern 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
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
def isHu(self, tiles, tile, isTing, getTileType, magicTiles = [], tingNodes = [], winSeatId = 0): ''' 三色全,玩家手中必须同时具有万饼条三种花色的牌 有幺九(喜杠、幺九杠、中发白作将或刻时可免幺九) 有刻(任意杠、中发白作将或刻时可免刻) ''' ftlog.debug('MWinRuleBaicheng.isHu TIAN_HU:', self.tableConfig.get(MTDefine.TIAN_HU, 0), ' len(self.tableTileMgr.addTiles[winSeatId]):', len(self.tableTileMgr.addTiles[winSeatId]), ' winSeatId:', winSeatId) if getTileType == MWinRule.WIN_BY_MYSELF: if 0==self.tableConfig.get(MTDefine.TIAN_HU, 0): if len(self.tableTileMgr.addTiles[winSeatId]) == 1: return False, [] #tile已经加入到tiles ftlog.debug('MWinRuleBaicheng.isHu tiles:', tiles , ' magicTiles:', magicTiles , ' tile:', tile) # 三色全 allTiles = MHand.copyAllTilesToList(tiles) #避免摸宝时候检查三色全问题,所以剔除最后一张 allTiles.remove(tile) 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 getTileType == MWinRule.WIN_BY_MYSELF: if (tile in magicTiles): canHuWithMagic = False for tileTry in range(MTile.TILE_MAX_VALUE): handTile = copy.deepcopy(tiles[MHand.TYPE_HAND]) handTile.remove(tile) handTile.append(tileTry) ishu, pattern = MWin.isHu(handTile,[],True) ftlog.debug('MWinRuleBaicheng.isHu handTile:', handTile,'tile',tile,'ishu',ishu,'pattern',pattern) if ishu: #摸宝的情况下,判断胡牌pattern里面是否有幺九,是否有刻 #把pattern胡牌加入到手牌,然后判断 allTilesMagicHu = copy.deepcopy(tiles) allTilesMagicHu[MHand.TYPE_HAND] = [] for p in pattern: allTilesMagicHu[MHand.TYPE_HAND].extend(p) ftlog.debug('MWinRuleBaicheng.isHu allTilesMagicHu:', allTilesMagicHu) #有幺九 if not self.SatisyYaoJiu(allTilesMagicHu): continue #有刻 if not self.SatisyKe(allTilesMagicHu): continue #可以胡,说明是摸宝胡牌 ftlog.debug('MWinRuleBaicheng.isHu canHuWithMagic:yes') canHuWithMagic = True return True,[] if not canHuWithMagic: return False, [] #有幺九 if not self.SatisyYaoJiu(tiles): return False,[] result, pattern = MWin.isHu(tiles[MHand.TYPE_HAND],[],True) if not result: return False, [] else: keAlreadyhas = self.SatisyKe2(tiles) if keAlreadyhas: return True, pattern else: #检查胡牌番型pattern,要有刻 for p in pattern: if len(p)==3 and p[0]==p[1]==p[2]: return True,pattern return False,[]