コード例 #1
0
    def InitPai(self):##初始化牌
        m_MJVec = []
        #中发白
        for  i in range(1,4):
            t_Pai = stPAI()
            t_Pai.m_Type = 0
            t_Pai.m_Value = i
            m_MJVec.append(t_Pai)
            m_MJVec.append(t_Pai)
            m_MJVec.append(t_Pai)
            m_MJVec.append(t_Pai)

         #东南西北
        for  i in range(1,5):
            t_Pai = stPAI()
            t_Pai.m_Type = 1
            t_Pai.m_Value = i
            m_MJVec.append(t_Pai)
            m_MJVec.append(t_Pai)
            m_MJVec.append(t_Pai)
            m_MJVec.append(t_Pai)
        # 万 饼 条
        for j in range(2, 5):
            for i in range(1, 10):
                t_Pai = stPAI()
                t_Pai.m_Type = j
                t_Pai.m_Value = i
                m_MJVec.append(t_Pai)
                m_MJVec.append(t_Pai)
                m_MJVec.append(t_Pai)
                m_MJVec.append(t_Pai)
        return m_MJVec
コード例 #2
0
    def Init(self):  ##初始化
        self.m_BaoPAIVec = []
        self.m_MyPAIVec = [[], [], [], [], []]  #起的种牌型
        self.m_ChiPAIVec = [[], [], [], [], []]  #吃的种牌型
        self.m_PengPAIVec = [[], [], [], [], []]  #碰的种牌型
        self.m_MGangPAIVec = [[], [], [], [], []]  #明杠的种牌型
        self.m_AGangPAIVec = [[], [], [], [], []]  #暗杠的种牌型

        self.m_PassGangPAIVec = []  #不能再杠的牌,玩家能杠的时候没杠
        self.m_PutPAIVec = []  #打出去的牌
        self.m_OrderPaiVec = []  #记录吃碰杠的次序

        self.m_LastPAI = stPAI()  #最后起的牌,检测胡用
        self.m_LastRealPAI = stPAI()  # 真正最后起的牌
        self.m_GoodInfo = stGoodInfo()  #胡牌信息

        self.m_TempChiPAIVec = []  #吃的可选组合
        self.m_TempPengPAIVec = []  #碰的可选组合
        self.m_TempGangPAIVec = []  #杠的可选组合

        self.m_gamePlay = []  # 玩法子类的组合(有关胡的玩法)
        self.m_gameCMJSuanFen = []  # 玩法子类的组合(有关算分的玩法)

        self.m_bTing = False  #玩家是否已经听了

        self.m_winType = []  #赢得类型集合

        self.m_canHuList = []  #每次判断听牌的时候,这个可能的胡牌列表

        self.m_lastPutPai = stPAI()  #最后一张打出的牌
        self.m_PutTingPai = stPAI()  #打这张牌可以听
        self.m_checkDanDiao = False

        self.m_Gamer = None
        return True
コード例 #3
0
    def HandleAIPutPai(self):  ##获取杠数量
        if self.m_bTing: return self.m_LastRealPAI

        putPai = stPAI()
        for index, pool in enumerate(self.m_MyPAIVec):
            cnt = Counter(pool)
            paiVTemp = []
            for paiV, count in cnt.iteritems():
                if count < 2:
                    paiVTemp.append(paiV)
            for k, v in enumerate(paiVTemp):
                if (self.CreateNearPai(v, 1) in pool) and (self.CreateNearPai(
                        v, 2) in pool):
                    continue
                elif (self.CreateNearPai(v, -1)
                      in pool) and (self.CreateNearPai(v, 1) in pool):
                    continue
                elif (self.CreateNearPai(v, -2)
                      in pool) and (self.CreateNearPai(v, -1) in pool):
                    continue
                putPai.m_Type = v.m_Type
                putPai.m_Value = v.m_Value
                return putPai
        for index, pool in enumerate(self.m_MyPAIVec):
            for k, paiV in enumerate(pool):
                putPai.m_Type = index
                putPai.m_Value = paiV
                return putPai
コード例 #4
0
    def CheckGangPai(self, p_Type, p_Value, nGangState):  ##检测杠牌
        if self.CheckPassGangPai(p_Type, p_Value) == True: return False
        self.m_TempGangPAIVec = []
        myPai = self.m_MyPAIVec[p_Type]
        iSize = len(myPai)
        maxRange = 3
        bGang = False
        if nGangState == config_game['gangState']['an']: maxRange = 4
        if iSize >= maxRange:
            for i in range(0, iSize - (maxRange - 1)):
                if nGangState == config_game['gangState']['an']:
                    if (myPai[i].m_Value == p_Value) and (myPai[i+1].m_Value == p_Value) and \
                            (myPai[i+2].m_Value == p_Value) and (myPai[i+3].m_Value == p_Value):
                        bGang = True
                else:
                    if (myPai[i].m_Value == p_Value) and (myPai[i + 1].m_Value == p_Value) and \
                            (myPai[i + 2].m_Value == p_Value) :
                        bGang = True
                if bGang:
                    t_Gang = stPAI()
                    t_Gang.m_Type = p_Type
                    t_Gang.m_Value = p_Value
                    self.m_TempGangPAIVec.append(t_Gang)
                    break

        if len(self.m_TempGangPAIVec) > 0:
            return True
        return False
コード例 #5
0
 def __init__(self, id, conn, pos, bAI=False):  ##房主链接,房主id
     self.id = id  #玩家userid
     self.conn = conn
     self.pos = pos  #玩家方位
     self.boss = False  #庄家标志
     self.state = 0  # 1可胡 2可听 4可杠 8可碰 16可吃 1听 2胡
     self.lastMsg = None  # 断线重连用,发送上一次的打牌或者can牌消息
     self.m_gamePlay = None
     self.m_score = 0
     self.cmj = None  #牌墙类,负责玩家牌池管理和逻辑处理
     self.m_bDianPao = False  #是否点炮
     self.m_bZiMo = False  #是否自摸
     self.m_nGameState = config_game['gamerState']['join']  #是否准备好
     self.m_nGameAction = config_game['gameAction']['standby']  #玩家当前动作 默认待机
     self.m_huPai = stPAI()  #胡的牌
     self.m_showState = []  #结算显示类型
     self.m_bAI = bAI  #玩家是否是机器人
     if bAI:
         #self.m_nGameState = config_game['gamerState']['ready']  # 是否准备好
         self.m_nAIRandInfo = Utils().gen_ai_info_rand()
         self.m_nAIRandHead = Utils().gen_ai_head_rand()
     #总结算临时数据
     self.m_nHuCount = 0  #胡牌数量
     self.m_nMoBaoCount = 0  #摸宝数量
     self.m_nZiMoCount = 0  #自摸数量
     self.m_nGangCount = 0  #杠牌数量
     self.m_nDianPaoCount = 0  #点炮数量
     self.m_nDanJuBestCount = 0  #单句最佳数量
     self.m_TotalScore = 0  #总分
コード例 #6
0
 def Reset(self):  ##重置
     for i in range(0, len(self.m_MyPAIVec)):
         self.m_MyPAIVec[i] = []
         self.m_ChiPAIVec[i] = []
         self.m_PengPAIVec[i] = []
         self.m_MGangPAIVec[i] = []
         self.m_AGangPAIVec[i] = []
     self.m_BaoPAIVec = []
     self.m_PutPAIVec = []
     self.m_PassGangPAIVec = []
     self.m_OrderPaiVec = []  # 记录吃碰杠的次序
     self.ResetTemp()
     self.ResetCircle()
     self.m_bTing = False  # 玩家是否已经听了
     self.m_winType = []  # 赢得类型集合
     self.m_LastPAI = stPAI()  # 最后起的牌,检测胡用
     self.m_LastRealPAI = stPAI()  # 真正最后起的牌
コード例 #7
0
 def AddPaiReal(self, p_Type, p_Value):  ##真正加入新牌,并排序
     if CMJManage.m_baoPai.m_Type == p_Type and CMJManage.m_baoPai.m_Value == p_Value:
         newPai = stPAI()
         newPai.m_Type = p_Type
         newPai.m_Value = p_Value
         self.m_BaoPAIVec.append(newPai)
         return True
     self.AddPai(p_Type, p_Value)
     self.m_LastRealPAI.m_Type = p_Type  #玩家真正的最后一张摸牌
     self.m_LastRealPAI.m_Value = p_Value
コード例 #8
0
    def CheckTING(self):  ##检测是否听牌,以及可以胡的牌列表
        self.m_canHuList = []
        bHu = False
        for j in range(0, 3):
            #起牌,加一张牌,如果胡了,说明当前可以听
            pai = stPAI()
            pai.m_Type = 0
            pai.m_Value = j + 1
            self.AddPaiObj(pai)
            if self.CheckAllPai(config_game['MJ']['MJPAI_GETPAI']):
                self.m_canHuList.append(pai)
                bHu = True
            self.DelPaiObj(pai)

        for j in range(0, 4):
            #起牌,加一张牌,如果胡了,说明当前可以听
            pai = stPAI()
            pai.m_Type = 1
            pai.m_Value = j + 1
            self.AddPaiObj(pai)
            if self.CheckAllPai(config_game['MJ']['MJPAI_GETPAI']):
                self.m_canHuList.append(pai)
                bHu = True
            self.DelPaiObj(pai)

        for i in range(2, 5):
            for j in range(0, 9):
                #起牌,加一张牌,如果胡了,说明当前可以听
                pai = stPAI()
                pai.m_Type = i
                pai.m_Value = j + 1
                self.AddPaiObj(pai)
                if self.CheckAllPai(config_game['MJ']['MJPAI_GETPAI']):
                    self.m_canHuList.append(pai)
                    bHu = True
                self.DelPaiObj(pai)

        return bHu
コード例 #9
0
 def CheckGangPaiFromPeng(self, p_Type, p_Value):  ##检测杠牌,必然是明杠
     self.m_TempGangPAIVec = []
     # 除了检测个人牌墙中,还要检测碰牌组合
     myPengPai = self.m_PengPAIVec[p_Type]
     for i in range(0, len(myPengPai)):
         if myPengPai[i] == p_Value:
             t_Gang = stPAI()
             t_Gang.m_Type = p_Type
             t_Gang.m_Value = p_Value
             self.m_TempGangPAIVec.append(t_Gang)
             break
     if len(self.m_TempGangPAIVec) > 0:
         return True
     return False
コード例 #10
0
    def CheckPengPai(self, p_Type, p_Value):  ##检测碰牌
        self.m_TempPengPAIVec = []
        myPai = self.m_MyPAIVec[p_Type]
        iSize = len(myPai)
        if iSize > 0:
            if iSize >= 2:
                for i in range(0, iSize - 1):
                    if (myPai[i].m_Value == p_Value) and (myPai[i + 1].m_Value
                                                          == p_Value):
                        t_Peng = stPAI()
                        t_Peng.m_Type = p_Type
                        t_Peng.m_Value = p_Value
                        self.m_TempPengPAIVec.append(t_Peng)
                        break
            if len(self.m_TempPengPAIVec) > 0:
                return True

        return False
コード例 #11
0
    def AddPai(self, p_Type, p_Value):  ##加入新牌,并排序,给判断用
        myPaiVec = self.m_MyPAIVec[p_Type]
        newPai = stPAI()
        newPai.m_Type = p_Type
        newPai.m_Value = p_Value
        t_Find = False
        for i, v in enumerate(myPaiVec):
            if v.m_Value > p_Value:
                myPaiVec.insert(i, newPai)
                t_Find = True
                break

        if t_Find == False:
            myPaiVec.append(newPai)

        self.m_LastPAI.m_Type = p_Type
        self.m_LastPAI.m_Value = p_Value

        return True
コード例 #12
0
ファイル: ACMJ.py プロジェクト: cary-lichi/ZKMJ
 def seperateArr(self, mjArr, bao):
     res = [[], [], [], [], []]
     for mj in mjArr:
         index = mj / 100
         pai = stPAI()
         pai.m_Type = index
         pai.m_Value = mj % 10
         # 宝牌是花牌
         if bao > 500:
             if index == 5:
                 res[0].append(pai)
             else:
                 res[index].append(pai)
         else:
             if index == 5:  #//此时花牌处理成宝的本位牌
                 i = bao / 100
                 res[i].append(pai)
             else:
                 pai
                 if mj == bao:
                     res[0].append(pai)
                 else:
                     res[index].append(pai)
     return res
コード例 #13
0
 def CreateNearPai(self, pai, apart):
     newpai = stPAI()
     newpai.m_Type = pai.m_Type
     newpai.m_Value = pai.m_Value + apart
     return newpai
コード例 #14
0
 def AddPutPai(self, p_Type, p_Value):  ##加入出的牌
     putPai = stPAI()
     putPai.m_Type = p_Type
     putPai.m_Value = p_Value
     self.m_PutPAIVec.append(putPai)
コード例 #15
0
ファイル: stPAIEx.py プロジェクト: cary-lichi/ZKMJ
 def __init__(self):##牌类型,牌字
    self.m_NewPai = stPAI() #起的新牌
    self.m_PaiNum = 0   #剩余牌数
    self.m_IsHZ = False #是否黄庄
コード例 #16
0
ファイル: CMJManager.py プロジェクト: cary-lichi/ZKMJ
class CMJManage:
    m_baoPai = stPAI()  # 宝牌

    def __init__(self, gamePlay):
        self.m_MJVec = []  #麻将数据列表
        self.m_HZPaiNum = 0  #黄庄的牌数
        self.Heap = Heap()  #牌堆
        self.HandCardNum = 13  #玩家手牌的数目
        self.initGamePlay(gamePlay)

    def InitPai(self, p_HZPaiNum):  ##初始化牌
        self.m_HZPaiNum = p_HZPaiNum
        self.m_MJVec = self.Heap.InitPai()
        self.XiPai()

    def initGamePlay(self, gamePlay):
        for optional in gamePlay.optionals:
            if optional == config_game['gameplay']['optionals']["ybc"]:
                self.HandCardNum = 4

    def GraspPai(self, gamerCache):  #发牌
        # # 清理
        for k, v in gamerCache.iteritems():
            v.cmj.CleanUp()

        # #每人十三张,
        for i in range(0, self.HandCardNum):
            for k, v in gamerCache.iteritems():
                paiEx = self.GetAPai()
                v.onAddPai(paiEx.m_NewPai.m_Type, paiEx.m_NewPai.m_Value)

        # for k,v in gamerCache.iteritems():
        #     for i in range(0, self.HandCardNum):
        #         paiEx = self.GetAPai()
        #         v.onAddPai(paiEx.m_NewPai.m_Type,paiEx.m_NewPai.m_Value)

    def XiPai(self):  ##洗牌
        random.shuffle(self.m_MJVec)

    def GetAPai(self):  ##起牌

        #如果所有牌都起完了
        if len(self.m_MJVec) <= 0:
            return None

        t_Pai = stPAIEx()
        t_Pai.m_NewPai.m_Type = self.m_MJVec[-1].m_Type
        t_Pai.m_NewPai.m_Value = self.m_MJVec[-1].m_Value
        t_Pai.m_PaiNum = len(self.m_MJVec) - 1
        if (t_Pai.m_PaiNum == self.m_HZPaiNum):
            t_Pai.m_IsHZ = True
        else:
            t_Pai.m_IsHZ = False

        self.m_MJVec.pop()
        return t_Pai

    def GetLeftPai(self):  ##获取剩余牌数
        return len(self.m_MJVec)

    def GetLeftCanHuPai(self, pai):  ##获取能胡的牌的剩余牌数
        nLeft = 0
        for k, v in enumerate(self.m_MJVec):
            if v.m_Type == pai.m_Type and v.m_Value == pai.m_Value:
                nLeft = nLeft + 1
        return nLeft

    def IsOver(self):  ##是不是结束了
        return len(self.m_MJVec) <= 0