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
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
def isJinQue(self,magicTile,pattern,handTiles): """ 金雀:金做将对 """ magicCount = MTile.getTileCount(magicTile,handTiles) if magicCount != 2: return False for p in pattern: for oneTile in p: if oneTile in handTiles: handTiles.remove(oneTile) if len(handTiles) == 2 and handTiles[0] == handTiles[1] and handTiles[0] == magicTile: return True return False
def isSanJinDao(self): """ 三金倒 """ magicTile = self.tableTileMgr.getMagicTile() handTiles = self.playerAllTiles[self.winSeatId][MHand.TYPE_HAND] magicCount = MTile.getTileCount(magicTile,handTiles) huTiles = self.tableTileMgr.players[self.winSeatId].huTiles ftlog.debug('isSanJinDao. self.winSeatId,huTiles=',self.winSeatId,huTiles) if len(huTiles) and huTiles[0] == magicTile: magicCount = magicCount + 1 ftlog.debug('isSanJinDao.magicCount=',magicCount,handTiles,magicTile) if magicCount == 3: return True return False
def isJinQue(self, magicTile, pattern, handTiles): """ 金雀:金做将对 """ magicCount = MTile.getTileCount(magicTile, handTiles) if magicCount != 2: return False for p in pattern: for oneTile in p: if oneTile in handTiles: handTiles.remove(oneTile) if len(handTiles) == 2 and handTiles[0] == handTiles[1] and handTiles[ 0] == magicTile: return True return False
def isJinQue(self,isZiMo = False): """ 金雀:金做将对 if not isZiMo: return False """ magicTile = self.tableTileMgr.getMagicTile() handTiles = self.playerAllTiles[self.winSeatId][MHand.TYPE_HAND] magicCount = MTile.getTileCount(magicTile,handTiles) huTiles = self.tableTileMgr.players[self.winSeatId].huTiles if len(huTiles) and huTiles[0] == magicTile: magicCount = magicCount + 1 if magicCount != 2: return False for p in self.__win_pattern: if len(p) == 2: if p[0] == p[1] and p[0] == magicTile: 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 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 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 getWinnerResultsForLuoSiHu(self, winSeatId, isFlow=False): winnerResults = [] # 不需要根据和牌牌型计算的番型,先计算 maxFan = self.tableConfig.get(MTDefine.MAX_FAN, 0) """清一色""" if self.__tile_pattern_checker.isQingyise(): self.fanXing[self.QINGYISE]["index"] = 1 winnerResults.append(self.processFanXingResult(self.QINGYISE)) """碰碰胡""" for pattern in self.__win_patterns[winSeatId]: if self.__tile_pattern_checker.isPengpenghu(pattern): if self.isJinGouDiao(): winnerResults.append( self.processFanXingResult(self.JINGOUDIAO, 0, 2)) else: winnerResults.append( self.processFanXingResult(self.PENGPENGHU)) # 个别番型和和牌牌型有关,算分时选取分数最大的情况 #winnerResultsByPattern = [] maxPatternScore = 0 bestWinnerResultsByPattern = [] ftlog.info('MLuosihuOneResult.getWinnerResults winSeatId', self.__win_patterns[winSeatId]) for pattern in self.__win_patterns[winSeatId]: ftlog.info('MLuosihuOneResult.getWinnerResults win_pattern=', pattern) # pattern内,全部是手牌(包含最后一张牌) eachWinnerResultsByPattern = [] """七对""" if self.__tile_pattern_checker.isQidui(pattern): self.fanXing[self.QIDUI]["index"] = 1 eachWinnerResultsByPattern.append( self.processFanXingResult(self.QIDUI)) """豪华七对""" hu_tiles = self.tableTileMgr.players[winSeatId].copyHuArray() tempcount = 0 if len(hu_tiles) > 0: tiles = self.allPlayerTiles[ self. winSeatId] # self.tableTileMgr.players[self.winSeatId].copyTiles() handTiles = tiles[MHand.TYPE_HAND] tempcount = MTile.getTileCount(hu_tiles[-1], handTiles) ftlog.debug('MLuosihuOneResult.getWinnerResults hu_tiles=', hu_tiles, tempcount) if self.__tile_pattern_checker.isQiduiHao( pattern) and tempcount >= 3: self.fanXing[self.QIDUIHAO]["index"] = 2 eachWinnerResultsByPattern.append( self.processFanXingResult(self.QIDUIHAO)) ftlog.info( 'MLuosihuOneResult.getWinnerResults eachWinnerResultsByPattern=', eachWinnerResultsByPattern) bestWinnerResult = [] maxScore = 0 for result in eachWinnerResultsByPattern: tempResult = [] tempResult.append(result) calctempResult = [] calctempResult.extend(tempResult) tempScore, _ = self.getScoreByResults(calctempResult) if tempScore > maxScore: maxScore = tempScore bestWinnerResult = tempResult # 计算当前牌型的赢牌奖励分数,选取最大值的牌型 calceachWinnerResultsByPattern = [] #calceachWinnerResultsByPattern.extend(winnerResults) calceachWinnerResultsByPattern.extend(bestWinnerResult) tempScore, _ = self.getScoreByResults( calceachWinnerResultsByPattern) if tempScore > maxPatternScore: # 分数相同就不管了 maxPatternScore = tempScore bestWinnerResultsByPattern = calceachWinnerResultsByPattern winnerResults.extend(bestWinnerResultsByPattern) ftlog.info('MLuosihuOneResult.getWinnerResults luosihu winnerResults=', winnerResults) return winnerResults
def calcWin(self,winState = 0): self.clearWinFanPattern() # 在和牌时统计自摸,点炮状态 resultStat = [[] for _ in range(self.playerCount)] winMode = [MOneResult.WIN_MODE_LOSS for _ in range(self.playerCount)] fanPattern = [[] for _ in range(self.playerCount)] fanXing = self.fanXing[self.PINGHU] resultStat[self.winSeatId].append({MOneResult.STAT_WIN:1}) isZiMo = (self.lastSeatId == self.winSeatId) if isZiMo: resultStat[self.lastSeatId].append({MOneResult.STAT_ZIMO:1}) winMode[self.lastSeatId] = MOneResult.WIN_MODE_ZIMO else: if not winState: resultStat[self.lastSeatId].append({MOneResult.STAT_DIANPAO: 1}) winMode[self.lastSeatId] = MOneResult.WIN_MODE_DIANPAO winMode[self.winSeatId] = MOneResult.WIN_MODE_PINGHU if self.qiangGang: winMode[self.winSeatId] = MOneResult.WIN_MODE_QIANGGANGHU score = [0 for _ in range(self.playerCount)] # 底分 配置项的底分 baseScore = 1 winScore = 0 # 连庄 bankerRemainCount = 0 if self.winSeatId == self.bankerSeatId: bankerRemainCount = self.tableTileMgr.tableConfig.get(MTDefine.WIN_BASE,1) - 1 winScore = winScore + bankerRemainCount ### 算杠分 minggangScore = 0 angangScore = 0 gangscore = 0 # 杠牌得分 gangList = self.playerGangTiles[self.winSeatId] for gang in gangList: #if MTile.getColor(gang['pattern'][0]) == 3: # gangscore += 1 # minggangScore += 1 if gang['style'] == 0: # 暗杠 gangscore += 2 angangScore += 2 else: gangscore += 1 minggangScore += 1 #winScore = winScore + angangScore + minggangScore ##算花分 huaScore = len(self.tableTileMgr.flowerTiles(self.winSeatId)) #winScore = winScore + huaScore ###算金分 magicTile = self.tableTileMgr.getMagicTile() handTiles = self.playerAllTiles[self.winSeatId][MHand.TYPE_HAND] magicScore = MTile.getTileCount(magicTile,handTiles) huTiles = self.tableTileMgr.players[self.winSeatId].huTiles if len(huTiles) > 0 and huTiles[0] == magicTile and not winState == MTableState.TABLE_STATE_SANJINDAO: magicScore = magicScore + 1 ftlog.debug('calcWin handTiles=',handTiles,huTiles,magicScore) winScore = winScore + magicScore winnerResults = [] if winState: if winState == MTableState.TABLE_STATE_TIANHU: winnerResults.append(self.processFanXingResult(self.TIANHU)) elif winState == MTableState.TABLE_STATE_QIANGJIN: winnerResults.append(self.processFanXingResult(self.QIANGJIN)) elif winState == MTableState.TABLE_STATE_QIANGJIN_B: winnerResults.append(self.processFanXingResult(self.QIANGJIN)) elif winState == MTableState.TABLE_STATE_SANJINDAO: winnerResults.append(self.processFanXingResult(self.SANJINDAO)) #if not isZiMo: if not huaScore and not len(gangList): winnerResults.append(self.processFanXingResult(self.PINGHU)) if huaScore + gangscore == 1: winnerResults.append(self.processFanXingResult(self.PINGHUYIHUA)) if winState and winState == MTableState.TABLE_STATE_TIANHU: if self.isSanJinDao(): winnerResults.append(self.processFanXingResult(self.SANJINDAO)) if self.tableConfig.get(MTDefine.QINGHUNYISE, 0): if self.isQingyise(): #清一色 winnerResults.append(self.processFanXingResult(self.QINGYISE)) elif self.isHunyise(): # 混一色 winnerResults.append(self.processFanXingResult(self.HUNYISE)) if self.tableTileMgr.players[self.winSeatId].jinkanState: winnerResults.append(self.processFanXingResult(self.JINKAN)) if self.isJinQue(isZiMo): winnerResults.append(self.processFanXingResult(self.JINQUE)) if not winState: if self.isSanJinDao(): winnerResults.append(self.processFanXingResult(self.SANJINDAO)) if self.tableConfig.get(MTDefine.QINGHUNYISE, 0): if self.isQingyise(): #清一色 winnerResults.append(self.processFanXingResult(self.QINGYISE)) elif self.isHunyise(): # 混一色 winnerResults.append(self.processFanXingResult(self.HUNYISE)) if self.tableTileMgr.players[self.winSeatId].jinkanState: winnerResults.append(self.processFanXingResult(self.JINKAN)) if self.isJinQue(isZiMo): winnerResults.append(self.processFanXingResult(self.JINQUE)) if not len(winnerResults): winScore = winScore + baseScore ###自摸 或者特殊番型*2 #if isZiMo or len(winnerResults) > 0: # winScore = winScore * 2 bestWinnerResult = None maxScore = 0 for result in winnerResults: tempScore = self.getScoreByResults(result) if tempScore > maxScore: maxScore = tempScore bestWinnerResult = result if bestWinnerResult and bestWinnerResult['index'] == 19: huaScore = 0 else: winScore = winScore + angangScore + minggangScore winScore = winScore + huaScore ###自摸 或者特殊番型*2 if isZiMo or len(winnerResults) > 0: winScore = winScore * 2 winScore = winScore + maxScore #### 胡法判断 if isZiMo: #自摸 score = [-winScore for _ in range(self.playerCount)] score[self.winSeatId] = (self.playerCount-1) * winScore else: #点炮 # if self.qiangGang: #抢杠包三家 # score = [0 for _ in range(self.playerCount)] # score[self.winSeatId] = (self.playerCount - 1) * winScore # score[self.lastSeatId] = -(self.playerCount - 1) * winScore # else: if winState: #抢金 score = [-winScore for _ in range(self.playerCount)] score[self.winSeatId] = (self.playerCount-1) * winScore else: if self.getFangHuConfig() == 1: score = [-winScore for _ in range(self.playerCount)] score[self.winSeatId] = (self.playerCount-1) * winScore elif self.getFangHuConfig() == 2: score[self.lastSeatId] = -winScore score[self.winSeatId] = winScore if bestWinnerResult: winMode[self.winSeatId] = bestWinnerResult['index'] flowerScores = {} flowerScores['scores'] = [self.tableTileMgr.flowerScores(seat) for seat in range(self.playerCount)] # 给前端显示花分 # 最大番统计(改成单局最佳) resultStat[self.winSeatId].append({MOneResult.STAT_ZUIDAFAN: score[self.winSeatId]}) self.results[self.KEY_TYPE] = '和牌' self.results[self.KEY_NAME] = fanXing['name'] self.results[self.KEY_SCORE] = score self.results[self.KEY_WIN_MODE] = winMode self.results[self.KEY_STAT] = resultStat fanPattern[self.winSeatId] = bestWinnerResult #self.results[self.KEY_FAN_PATTERN] = fanPattern ''' winInfo = [] jinResult = [] huaResult = [] baseResult = [] winPatt = [] if len(winnerResults) > 0 or isZiMo: #self.results['double'] = 2 jinResult.append("金牌:" + str(magicScore) + "花" + "*2") huaResult.append("花牌:" + str(huaScore) + "花" + "*2") baseResult.append("底分:" + str(baseScore) + "花" + "*2") if bestWinnerResult: winPatt.append(bestWinnerResult['name'] + ":" + str(bestWinnerResult['value'])+ "花") else: jinResult.append("金牌:" + str(magicScore) + "花") huaResult.append("花牌:" + str(huaScore) + "花") baseResult.append("底分:" + str(baseScore) + "花") winInfo.append(baseResult) if magicScore: winInfo.append(jinResult) if huaScore: winInfo.append(huaResult) if len(winPatt) > 0: winInfo.append(winPatt) ''' winInfo = [] jinResult = "金牌" + str(magicScore) huaResult = "花牌" + str(huaScore) baseResult = "底分" + str(baseScore) remainResult = "连庄" + str(bankerRemainCount) winPatt = None if bestWinnerResult: winPatt = bestWinnerResult['name'] + str(bestWinnerResult['value']) minggangResult = "明杠" + str(minggangScore) angangResult = "暗杠" + str(angangScore) winResult = "(" if not len(winnerResults): winResult = winResult + " " + baseResult if huaScore: winResult = winResult + " " + huaResult if magicScore: winResult = winResult + " " + jinResult if minggangScore: winResult = winResult + " " + minggangResult if angangScore: winResult = winResult + " " + angangResult if bankerRemainCount: winResult = winResult + " " + remainResult if len(winnerResults) > 0 or isZiMo: if bestWinnerResult: winPatt = bestWinnerResult['name'] + str(bestWinnerResult['value']) if huaScore or magicScore or minggangScore or angangScore or bankerRemainCount: winResult = winResult + " )" + " *2 + " + winPatt + " = " + str(winScore) else: winResult = winPatt + " = " + str(winScore) else: winResult = winResult + " )" + " *2" + " = " + str(winScore) else: winResult = winResult + " )" + " *1" + " = " + str(winScore) winInfo.append([winResult]) fanPattern[self.winSeatId] = winInfo self.results[self.KEY_FAN_PATTERN] = fanPattern self.results[self.KEY_FLOWER_SCORES] = flowerScores self.results[self.KEY_LIANZHUANG] = bankerRemainCount
def getWinnerResultsForLuoSiHu(self,winSeatId, isFlow=False): winnerResults = [] # 不需要根据和牌牌型计算的番型,先计算 maxFan = self.tableConfig.get(MTDefine.MAX_FAN, 0) """清一色""" if self.__tile_pattern_checker.isQingyise(): self.fanXing[self.QINGYISE]["index"] = 1 winnerResults.append(self.processFanXingResult(self.QINGYISE)) """碰碰胡""" for pattern in self.__win_patterns[winSeatId]: if self.__tile_pattern_checker.isPengpenghu(pattern): if self.isJinGouDiao(): winnerResults.append(self.processFanXingResult(self.JINGOUDIAO,0,2)) else: winnerResults.append(self.processFanXingResult(self.PENGPENGHU)) # 个别番型和和牌牌型有关,算分时选取分数最大的情况 #winnerResultsByPattern = [] maxPatternScore = 0 bestWinnerResultsByPattern = [] ftlog.info('MLuosihuOneResult.getWinnerResults winSeatId', self.__win_patterns[winSeatId]) for pattern in self.__win_patterns[winSeatId]: ftlog.info('MLuosihuOneResult.getWinnerResults win_pattern=', pattern) # pattern内,全部是手牌(包含最后一张牌) eachWinnerResultsByPattern = [] """七对""" if self.__tile_pattern_checker.isQidui(pattern): self.fanXing[self.QIDUI]["index"] = 1 eachWinnerResultsByPattern.append(self.processFanXingResult(self.QIDUI)) """豪华七对""" hu_tiles = self.tableTileMgr.players[winSeatId].copyHuArray() tempcount = 0 if len(hu_tiles) > 0: tiles = self.allPlayerTiles[self.winSeatId] # self.tableTileMgr.players[self.winSeatId].copyTiles() handTiles = tiles[MHand.TYPE_HAND] tempcount = MTile.getTileCount(hu_tiles[-1],handTiles) ftlog.debug('MLuosihuOneResult.getWinnerResults hu_tiles=',hu_tiles,tempcount) if self.__tile_pattern_checker.isQiduiHao(pattern) and tempcount >= 3: self.fanXing[self.QIDUIHAO]["index"] = 2 eachWinnerResultsByPattern.append(self.processFanXingResult(self.QIDUIHAO)) ftlog.info('MLuosihuOneResult.getWinnerResults eachWinnerResultsByPattern=', eachWinnerResultsByPattern) bestWinnerResult = [] maxScore = 0 for result in eachWinnerResultsByPattern: tempResult = [] tempResult.append(result) calctempResult = [] calctempResult.extend(tempResult) tempScore,_ = self.getScoreByResults(calctempResult) if tempScore > maxScore: maxScore = tempScore bestWinnerResult = tempResult # 计算当前牌型的赢牌奖励分数,选取最大值的牌型 calceachWinnerResultsByPattern = [] #calceachWinnerResultsByPattern.extend(winnerResults) calceachWinnerResultsByPattern.extend(bestWinnerResult) tempScore,_ = self.getScoreByResults(calceachWinnerResultsByPattern) if tempScore > maxPatternScore: # 分数相同就不管了 maxPatternScore = tempScore bestWinnerResultsByPattern = calceachWinnerResultsByPattern winnerResults.extend(bestWinnerResultsByPattern) ftlog.info('MLuosihuOneResult.getWinnerResults luosihu winnerResults=', winnerResults) return winnerResults