示例#1
0
    def allow_zimo(self, pid, mopai):
        msg = {}
        msg['tile'] = mopai
        # 判定可能出现的选项
        msg['operation'] = []
        # 处于立直状态 则无法改牌
        msg['lizhi_state'] = self.playerLizhi[pid] > 0
        if self.playerLizhi[pid] == 0:
            msg['operation'].append({'combination': [], 'type': 1})
        # 获取信息
        fulu = self.fuluStack[pid]
        # 是否允 暗/加杠 (最后一张不允许杠)
        if (self.yamaLast - 14) != self.yamaPos:
            oriCount = PaiMaker.GetCount(self.handStack[pid])
            gangmz = MianziMaker.get_gang_mianzi(oriCount, fulu, mopai + '_')
            for mz in gangmz:
                msg['operation'].append({'combination': mz[0], 'type': mz[1]})

        # 是否能自摸
        param = self.getPlayerParam(pid)
        param['haidi'] = 0
        if (self.yamaLast - 14) == self.yamaPos:
            param['haidi'] = 1
        ptr = PtJudger.GetFen(self.handStack[pid], fulu, mopai + '_', param)
        if ptr['hupai'] or ptr['defen'] > 0:
            # print(ptr)
            msg['operation'].append({'combination': mopai + '_', 'type': 8})

        # 是否可以立直
        paiCount = PaiMaker.GetCount(self.handStack[pid])
        # 向听数
        xt = TingJudger.xiangting(paiCount, fulu)
        # 是否门清
        menqing = True
        for f in fulu:
            if re.match('[\-\+\=](?!\!)', f):
                menqing = False

        if (self.playerLizhi[pid] == 0 and menqing and xt == 0
                and (self.yamaLast - 14) - self.yamaPos >= 4
                and self.score[pid] >= 1000):
            lizhipai = TingJudger.FindLizhi(self.handStack[pid], fulu,
                                            str(self.riverStack[pid]))
            msg['operation'].append({'combination': lizhipai, 'type': 7})
        # 九种九牌流局
        #msg.liuju = false
        self.msgList[pid] = msg
示例#2
0
 def isPlayerZhenting(self, i):
     ''' 判断是否振听
     '''
     pCount = PaiMaker.GetCount(self.handStack[i])
     tingpai = TingJudger.tingpai(pCount, self.fuluStack[i])
     riverstr = str(self.riverStack[i])
     # 是否有任何一张听牌是否出现在牌河内
     return TingJudger.IsZhenting(tingpai, riverstr)
示例#3
0
    def Liuju(self):
        # 4风连打
        if max(self.xunshu) == 1 and min(self.xunshu) == 1:
            count = [0, 0, 0, 0]
            dic = {'1z': 0, '2z': 1, '3z': 2, '4z': 3}
            for i in range(4):
                if (len(self.riverStack[i]) > 0):
                    p = self.riverStack[i][0]
                    if (p in dic):
                        count[dic[p]] += 1
            if max(count) == 4:
                print('\n4风连打')
                self.realfenpei = [0, 0, 0, 0]
                self.lianzhuang = True
                self.endSection = True
                return True
        # 4家立直
        if max(self.playerLizhi) == 1 and min(self.playerLizhi) == 1:
            print('\n四家立直', self.score, self.lizhibang)
            self.realfenpei = [-1000, -1000, -1000, -1000]
            self.lianzhuang = True
            self.endSection = True
            return True

        # 计算4家是否听牌
        if (self.yamaPos == self.yamaLast - 14):
            xiangting = [0, 0, 0, 0]
            tingpai = [[], [], [], []]
            self.realfenpei = [0, 0, 0, 0]
            for i in range(4):
                pcount = PaiMaker.GetCount(self.handStack[i])
                xiangting[i] = TingJudger.xiangting(pcount, self.fuluStack[i])
                if (xiangting[i] == 0):
                    tingpai[i] = TingJudger.tingpai(pcount, self.fuluStack[i])
                # 庄家是否听牌连庄
                if (self.playerWind[i] == 0):
                    self.lianzhuang = xiangting[i] == 0
                    if (self.lianzhuang):
                        self.realfenpei[i] = 500
            # 点数更新(id顺)
            tingSum = len(list(filter(lambda t: t == 0, xiangting)))
            if (tingSum > 0 and tingSum < 4):
                for i in range(4):
                    if xiangting[i] == 0:
                        self.realfenpei[i] += 3000 / tingSum
                    else:
                        self.realfenpei[i] += -3000 / (4 - tingSum)
                    self.score[i] += self.realfenpei[i]
            print('\n荒牌流局 {} 连庄{}'.format(self.realfenpei, self.lianzhuang))
            for i in range(4):
                print('p{}:{}向听 手牌{}{}'.format(
                    i, xiangting[i], PaiMaker.GetSortPai(self.handStack[i]),
                    self.fuluStack[i]))
            self.endSection = True
            return True

        return False
示例#4
0
 def fulu_xiangting(self, hand, fulu, pid):
     shoupai = PaiMaker.GetCount(hand)
     # 选择向听数最小的
     menqing = self.xiangting_menqing(shoupai, fulu)
     fanpai = self.xiangting_fanpai(shoupai, fulu, self.changfeng + 1,
                                    self.playerWind[pid] + 1)
     duanyao = self.xiangting_duanyao(shoupai, fulu)
     duidui = self.xiangting_duidui(shoupai, fulu)
     yisem = self.xiangting_yise(shoupai, fulu, 'm')
     yisep = self.xiangting_yise(shoupai, fulu, 'p')
     yises = self.xiangting_yise(shoupai, fulu, 's')
     # print({"鸣牌":fulu,"门清":menqing,"役牌":fanpai,"断幺九":duanyao,"对对":duidui,"m清/混一色":yisem,"p清/混一色":yisep,"s清/混一色":yises});
     return min(menqing, fanpai, duanyao, duidui, yisem, yisep, yises)