Ejemplo n.º 1
0
def Compare(Cardlist1=[], Cardlist2=[]):
    flag1 = Judge(Cardlist1)
    flag2 = Judge(Cardlist2)
    list_count1 = CommonCardsType.GetList_count(Cardlist1)
    list_count2 = CommonCardsType.GetList_count(Cardlist2)
    bigCard1 = -1
    bigCard2 = -2
    if (flag2 > flag1):
        return True
    elif (flag1 == flag2):
        if (flag1 == flag2 == 7):
            for i in range(15):
                if (list_count1[i] == 3):
                    bigCard1 = i
                if (list_count2[i] == 3):
                    bigCard2 = i
            if (bigCard2 >= bigCard1):
                return True
            else:
                return False
        else:
            bigCard1 = FindBiggestCard(Cardlist1)
            bigCard2 = FindBiggestCard(Cardlist2)
            if (bigCard2 >= bigCard1):
                return True
            else:
                return False
    else:
        return False
Ejemplo n.º 2
0
def IsSanshunzi(Cardlist=[]):
    temp_Sanshunzi = []  # 存放在查找过程中可能存在的三顺子的一部分
    list_list = list.copy(Cardlist)  # Cardlist的副本
    Sanshunzi = []
    temp_list1 = []  # 存放去掉一个顺子后的手牌
    temp_list2 = []  # 存放去掉两个顺子后的手牌
    Shunzi1 = []  # 第一层循环中所有的顺子
    Shunzi2 = []  # 第二层循环中所有的顺子
    Shunzi1 = CommonCardsType.FindShunzi(list_list)
    if (Shunzi1 != []):
        for item1 in Shunzi1:
            temp_list1 = PlayCards.CalculateSub(list_list, item1)
            Shunzi2 = CommonCardsType.FindShunzi(temp_list1)
            if (Shunzi2 != []):
                for item2 in Shunzi2:
                    temp_list2 = PlayCards.CalculateSub(temp_list1, item2)
                    temp_list2.sort()
                    if (temp_list2[0][0] + 1 == temp_list2[1][0]
                            and temp_list2[1][0] + 1 == temp_list2[2][0]):
                        temp_Sanshunzi.append(temp_list2)
                        if (item1[4][0] >= item2[4][0]):
                            temp_Sanshunzi.append(item2)
                            temp_Sanshunzi.append(item1)
                        else:
                            temp_Sanshunzi.append(item1)
                            temp_Sanshunzi.append(item2)
                        if temp_Sanshunzi not in Sanshunzi:
                            Sanshunzi.append(temp_Sanshunzi)
                            temp_Sanshunzi = []
    if (Sanshunzi != []):
        return True
    else:
        return False
Ejemplo n.º 3
0
def IsSantonghuashun(Cardlist=[]):
    temp_Sanshunzi = []  # 存放在查找过程中可能存在的三顺子的一部分
    list_list = list.copy(Cardlist)  # Cardlist的副本
    Sanshunzi = []
    SanTonghuashun = []
    temp_list1 = []  # 存放去掉一个顺子后的手牌
    temp_list2 = []  # 存放去掉两个顺子后的手牌
    Shunzi1 = []  # 第一层循环中所有的顺子
    Shunzi2 = []  # 第二层循环中所有的顺子
    Shunzi1 = CommonCardsType.FindShunzi(list_list)
    if (Shunzi1 != []):
        for item1 in Shunzi1:
            temp_list1 = PlayCards.CalculateSub(list_list, item1)
            Shunzi2 = CommonCardsType.FindShunzi(temp_list1)
            if (Shunzi2 != []):
                for item2 in Shunzi2:
                    temp_list2 = PlayCards.CalculateSub(temp_list1, item2)
                    temp_list2.sort()
                    if (temp_list2[0][0] + 1 == temp_list2[1][0]
                            and temp_list2[1][0] + 1 == temp_list2[2][0]):
                        temp_Sanshunzi.append(temp_list2)
                        if (item1[4][0] >= item2[4][0]):
                            temp_Sanshunzi.append(item2)
                            temp_Sanshunzi.append(item1)
                        else:
                            temp_Sanshunzi.append(item1)
                            temp_Sanshunzi.append(item2)
                        if temp_Sanshunzi not in Sanshunzi:
                            Sanshunzi.append(temp_Sanshunzi)
                            temp_Sanshunzi = []
    if (Sanshunzi != []):
        for item in Sanshunzi:  # item是一个三顺子
            flag = 1  # flag=0时表示这一个三顺子不是三同花顺
            for dun in item:  # dun是一个墩
                for i in range(len(dun) - 1):  # i是墩中的一张牌的下标
                    if (dun[i][1] != dun[i + 1][1]):
                        flag = 0
            if (flag == 1):
                SanTonghuashun.append(item)
    if (SanTonghuashun != []):
        return True
    else:
        return False
Ejemplo n.º 4
0
def FindAllCardsCombination(Cardlist=[]):
    temp_Cardlist = list.copy(Cardlist)
    AllCardsCombination = []
    temp_list = []
    temp_list = CommonCardsType.FindTonghuashun(temp_Cardlist)
    if (temp_list != []):
        for item in temp_list:
            AllCardsCombination.append(item)
    temp_list = CommonCardsType.FindZhadan(temp_Cardlist)
    if (temp_list != []):
        for item in temp_list:
            AllCardsCombination.append(item)
    temp_list = CommonCardsType.FindHulu(temp_Cardlist)
    if (temp_list != []):
        for item in temp_list:
            AllCardsCombination.append(item)
    temp_list = CommonCardsType.FindTonghua(temp_Cardlist)
    if (temp_list != []):
        for item in temp_list:
            AllCardsCombination.append(item)
    temp_list = CommonCardsType.FindShunzi(temp_Cardlist)
    if (temp_list != []):
        for item in temp_list:
            AllCardsCombination.append(item)
    temp_list = CommonCardsType.FindSantiao(temp_Cardlist)
    if (temp_list != []):
        for item in temp_list:
            AllCardsCombination.append(item)
    temp_list = CommonCardsType.FindLiandui(temp_Cardlist)
    if (temp_list != []):
        for item in temp_list:
            AllCardsCombination.append(item)
    temp_list = CommonCardsType.FindErdui(temp_Cardlist)
    if (temp_list != []):
        for item in temp_list:
            AllCardsCombination.append(item)
    temp_list = CommonCardsType.FindDuizi(temp_Cardlist)
    if (temp_list != []):
        for item in temp_list:
            AllCardsCombination.append(item)
    return AllCardsCombination
Ejemplo n.º 5
0
def Judge(Cardlist=[]):
    temp_Cardlist = list.copy(Cardlist)
    if (CommonCardsType.FindTonghuashun(temp_Cardlist) != []):
        return 9
    elif (CommonCardsType.FindZhadan(temp_Cardlist) != []):
        return 8
    elif (CommonCardsType.FindHulu(temp_Cardlist) != []):
        return 7
    elif (CommonCardsType.FindTonghua(temp_Cardlist) != []):
        return 6
    elif (CommonCardsType.FindShunzi(temp_Cardlist) != []):
        return 5
    elif (CommonCardsType.FindSantiao(temp_Cardlist) != []):
        return 4
    elif (CommonCardsType.FindLiandui(temp_Cardlist) != []):
        return 3
    elif (CommonCardsType.FindErdui(temp_Cardlist) != []):
        return 2
    elif (CommonCardsType.FindDuizi(temp_Cardlist) != []):
        return 1
    else:
        return 0
Ejemplo n.º 6
0
def PostCards(str_data):
    Cardlist = GetCardlist(str_data)
    temp_Cardlist = list.copy(Cardlist)
    # 接下来开始按权值最大原则墩牌
    Weight_All = 0  # 某一种出牌方式的权值
    Post_Cards = []  # 最后返回的列表
    Weight_Qiandun = 0  # 前墩的权值
    Weight_Zhongdun = 0  # 中墩的权值
    Weight_Houdun = 0  # 后墩的权值
    Cards_Qiandun = []  # 前墩的牌
    Cards_Zhongdun = []  # 中墩的牌
    Cards_Houdun = []  # 后墩的牌
    AllCardsCombination_AfterTakeHoudun = []  # 拿出后墩牌后剩下的牌所有对子以上的牌型
    AllCardsCombination_AfterTakeZhongdun = []  # 拿出中墩牌后剩下的牌所有对子、三条的列表
    Cardlist_AfterTakeHoudun = []  # 拿出后墩后剩下的牌
    Cardlist_AfterTakeZhongdun = []  # 拿出中墩、后墩后剩下的牌
    Cardlist_AfterTakeQiandun = []  # 拿出中墩、后墩、前墩后剩下的牌,因为拿出的中墩、后墩、前墩不是完整的
    AllCardsCombination_FromAllcards = []  # 13张牌中所有对子及以上的牌型
    AllCardsCombination_FromAllcards = FindAllCardsCombination(temp_Cardlist)
    for item1 in AllCardsCombination_FromAllcards:  # 先拿出后墩
        Cardlist_AfterTakeHoudun = CalculateSub(temp_Cardlist, item1)
        AllCardsCombination_AfterTakeHoudun = FindAllCardsCombination(Cardlist_AfterTakeHoudun)
        if (AllCardsCombination_AfterTakeHoudun != []):
            for item2 in AllCardsCombination_AfterTakeHoudun:
                Cardlist_AfterTakeZhongdun = CalculateSub(Cardlist_AfterTakeHoudun, item2)
                AllCardsCombination_AfterTakeZhongdun = CommonCardsType.FindDuizi(
                    Cardlist_AfterTakeZhongdun) + CommonCardsType.FindSantiao(Cardlist_AfterTakeZhongdun)
                if (AllCardsCombination_AfterTakeZhongdun != []):
                    for item3 in AllCardsCombination_AfterTakeZhongdun:
                        Cardlist_AfterTakeQiandun = CalculateSub(Cardlist_AfterTakeZhongdun, item3)
                        Cards_Qiandun = list.copy(item3)
                        Cards_Zhongdun = list.copy(item2)
                        Cards_Houdun = list.copy(item1)
                        Weight_Qiandun = Getweight_Qiandun(Cards_Qiandun)
                        Weight_Zhongdun = GetWeight_Zhongdun(Cards_Zhongdun)
                        Weight_Houdun = GetWeight_Houdun(Cards_Houdun)
                        if (Weight_Qiandun + Weight_Zhongdun + Weight_Houdun > Weight_All
                                and Compare(Cards_Qiandun, Cards_Zhongdun) and Compare(Cards_Zhongdun, Cards_Houdun)):
                            Weight_All = Weight_Qiandun + Weight_Zhongdun + Weight_Houdun
                            if (Cardlist_AfterTakeQiandun != []):
                                for card in Cardlist_AfterTakeQiandun:
                                    if (len(Cards_Qiandun) < 3):
                                        Cards_Qiandun.append(card)
                                    elif (len(Cards_Zhongdun) < 5):
                                        Cards_Zhongdun.append(card)
                                    else:
                                        Cards_Houdun.append(card)
                            Post_Cards = []
                            Post_Cards.append(Cards_Qiandun)
                            Post_Cards.append(Cards_Zhongdun)
                            Post_Cards.append(Cards_Houdun)
                        Cards_Qiandun = []
                        Cards_Zhongdun = []
                        Cards_Houdun = []
                else:
                    Cards_Qiandun.append(FindBiggestCard(Cardlist_AfterTakeZhongdun))
                    Cardlist_AfterTakeQiandun = CalculateSub(Cardlist_AfterTakeZhongdun, Cards_Qiandun)
                    Cards_Houdun = list.copy(item1)
                    Cards_Zhongdun = list.copy(item2)
                    Weight_Houdun = GetWeight_Houdun(Cards_Houdun)
                    Weight_Zhongdun = GetWeight_Zhongdun(Cards_Zhongdun)
                    Weight_Qiandun = Getweight_Qiandun(Cards_Qiandun)
                    if (Weight_Qiandun + Weight_Zhongdun + Weight_Houdun > Weight_All
                            and Compare(Cards_Qiandun, Cards_Zhongdun) and Compare(Cards_Zhongdun, Cards_Houdun)):
                        Weight_All = Weight_Qiandun + Weight_Zhongdun + Weight_Houdun
                        if (Cardlist_AfterTakeQiandun != []):
                            for card in Cardlist_AfterTakeQiandun:
                                if (len(Cards_Qiandun) < 3):
                                    Cards_Qiandun.append(card)
                                elif (len(Cards_Zhongdun) < 5):
                                    Cards_Zhongdun.append(card)
                                else:
                                    Cards_Houdun.append(card)
                        Post_Cards = []
                        Post_Cards.append(Cards_Qiandun)
                        Post_Cards.append(Cards_Zhongdun)
                        Post_Cards.append(Cards_Houdun)
                    Cards_Qiandun = []
                    Cards_Zhongdun = []
                    Cards_Houdun = []

        else:
            Cards_Zhongdun.append(FindBiggestCard(Cardlist_AfterTakeHoudun))
            Weight_Zhongdun = GetWeight_Zhongdun(Cards_Zhongdun)
            Cardlist_AfterTakeZhongdun = CalculateSub(Cardlist_AfterTakeHoudun, Cards_Zhongdun)
            Cards_Qiandun.append(FindBiggestCard(Cardlist_AfterTakeZhongdun))
            Weight_Qiandun = Getweight_Qiandun(Cards_Qiandun)
            Cardlist_AfterTakeQiandun = CalculateSub(Cardlist_AfterTakeZhongdun, Cards_Qiandun)
            Cards_Houdun = list.copy(item1)
            Weight_Houdun = GetWeight_Houdun(Cards_Houdun)
            if (Weight_Qiandun + Weight_Zhongdun + Weight_Houdun > Weight_All
                    and Compare(Cards_Qiandun, Cards_Zhongdun) and Compare(Cards_Zhongdun, Cards_Houdun)):
                Weight_All = Weight_Qiandun + Weight_Zhongdun + Weight_Houdun
                if (Cardlist_AfterTakeQiandun != []):
                    for card in Cardlist_AfterTakeQiandun:
                        if (len(Cards_Qiandun) < 3):
                            Cards_Qiandun.append(card)
                        elif (len(Cards_Zhongdun) < 5):
                            Cards_Zhongdun.append(card)
                        else:
                            Cards_Houdun.append(card)
                Post_Cards = []
                Post_Cards.append(Cards_Qiandun)
                Post_Cards.append(Cards_Zhongdun)
                Post_Cards.append(Cards_Houdun)
            Cards_Qiandun = []
            Cards_Zhongdun = []
    return Post_Cards
Ejemplo n.º 7
0
def PostCards(str_data):
    Cardlist = GetCardlist(str_data)
    temp_Cardlist = list.copy(Cardlist)
    '''
    # 以下是判断是否出现特殊牌型,如果是,直接返回原列表
    if (SpecialCardsType.IsZhizhunqinglong(temp_Cardlist)):
        print("至尊清龙")
        return temp_Cardlist
    elif (SpecialCardsType.IsYitiaolong(temp_Cardlist)):
        print("一条龙")
        return temp_Cardlist
    elif (SpecialCardsType.IsShierhuangzu(temp_Cardlist)):
        print("十二皇族")
        return temp_Cardlist
    elif (SpecialCardsType.IsSantonghuashun(temp_Cardlist)):
        print("三同花顺")
        return temp_Cardlist
    elif (SpecialCardsType.IsSanfentianxia(temp_Cardlist)):
        print("三分天下")
        return temp_Cardlist
    elif (SpecialCardsType.IsQuanda(temp_Cardlist)):
        print("全大")
        return temp_Cardlist
    elif (SpecialCardsType.IsQuanxiao(temp_Cardlist)):
        print("全小")
        return temp_Cardlist
    elif (SpecialCardsType.IsCouyise(temp_Cardlist)):
        print("凑一色")
        return temp_Cardlist
    elif (SpecialCardsType.IsShuangguaichongsan(temp_Cardlist)):
        print("双怪冲三")
        return temp_Cardlist
    elif (SpecialCardsType.IsSitaosantiao(temp_Cardlist)):
        print("四套三条")
        return temp_Cardlist
    elif (SpecialCardsType.IsWuduisantiao(temp_Cardlist)):
        print("五对三条")
        return temp_Cardlist
    elif (SpecialCardsType.IsLiuduiban(temp_Cardlist)):
        print("六对半")
        return temp_Cardlist
    elif (SpecialCardsType.IsSanshunzi(temp_Cardlist)):
        print("三顺子")
        return temp_Cardlist
    elif (SpecialCardsType.IsSantonghua(temp_Cardlist)):
        print("三同花")
        return temp_Cardlist'''
    # 接下来开始按权值最大原则墩牌
    Weight_All = 0  # 某一种出牌方式的权值
    Post_Cards = []  # 最后返回的列表
    Weight_Qiandun = 0  # 前墩的权值
    Weight_Zhongdun = 0  # 中墩的权值
    Weight_Houdun = 0  # 后墩的权值
    Cards_Qiandun = []  # 前墩的牌
    Cards_Zhongdun = []  # 中墩的牌
    Cards_Houdun = []  # 后墩的牌
    AllCardsCombination_AfterTakeHoudun = []  # 拿出后墩牌后剩下的牌所有对子以上的牌型
    AllCardsCombination_AfterTakeZhongdun = []  # 拿出中墩牌后剩下的牌所有对子、三条的列表
    Cardlist_AfterTakeHoudun = []  # 拿出后墩后剩下的牌
    Cardlist_AfterTakeZhongdun = []  # 拿出中墩、后墩后剩下的牌
    Cardlist_AfterTakeQiandun = []  # 拿出中墩、后墩、前墩后剩下的牌,因为拿出的中墩、后墩、前墩不是完整的
    AllCardsCombination_FromAllcards = []  # 13张牌中所有对子及以上的牌型
    AllCardsCombination_FromAllcards = FindAllCardsCombination(temp_Cardlist)
    for item1 in AllCardsCombination_FromAllcards:  # 先拿出后墩
        Cardlist_AfterTakeHoudun = CalculateSub(temp_Cardlist, item1)
        AllCardsCombination_AfterTakeHoudun = FindAllCardsCombination(Cardlist_AfterTakeHoudun)
        if (AllCardsCombination_AfterTakeHoudun != []):
            for item2 in AllCardsCombination_AfterTakeHoudun:
                Cardlist_AfterTakeZhongdun = CalculateSub(Cardlist_AfterTakeHoudun, item2)
                AllCardsCombination_AfterTakeZhongdun = CommonCardsType.FindDuizi(
                    Cardlist_AfterTakeZhongdun) + CommonCardsType.FindSantiao(Cardlist_AfterTakeZhongdun)
                if (AllCardsCombination_AfterTakeZhongdun != []):
                    for item3 in AllCardsCombination_AfterTakeZhongdun:
                        Cardlist_AfterTakeQiandun = CalculateSub(Cardlist_AfterTakeZhongdun, item3)
                        Cards_Qiandun = list.copy(item3)
                        Cards_Zhongdun = list.copy(item2)
                        Cards_Houdun = list.copy(item1)
                        Weight_Qiandun = Getweight_Qiandun(Cards_Qiandun)
                        Weight_Zhongdun = GetWeight_Zhongdun(Cards_Zhongdun)
                        Weight_Houdun = GetWeight_Houdun(Cards_Houdun)
                        if (Weight_Qiandun + Weight_Zhongdun + Weight_Houdun > Weight_All
                                and Compare(Cards_Qiandun, Cards_Zhongdun) and Compare(Cards_Zhongdun, Cards_Houdun)):
                            Weight_All = Weight_Qiandun + Weight_Zhongdun + Weight_Houdun
                            if (Cardlist_AfterTakeQiandun != []):
                                for card in Cardlist_AfterTakeQiandun:
                                    if (len(Cards_Qiandun) < 3):
                                        Cards_Qiandun.append(card)
                                    elif (len(Cards_Zhongdun) < 5):
                                        Cards_Zhongdun.append(card)
                                    else:
                                        Cards_Houdun.append(card)
                            Post_Cards = []
                            Post_Cards.append(Cards_Qiandun)
                            Post_Cards.append(Cards_Zhongdun)
                            Post_Cards.append(Cards_Houdun)
                        Cards_Qiandun = []
                        Cards_Zhongdun = []
                        Cards_Houdun = []
                else:
                    Cards_Qiandun.append(FindBiggestCard(Cardlist_AfterTakeZhongdun))
                    Cardlist_AfterTakeQiandun = CalculateSub(Cardlist_AfterTakeZhongdun, Cards_Qiandun)
                    Cards_Houdun = list.copy(item1)
                    Cards_Zhongdun = list.copy(item2)
                    Weight_Houdun = GetWeight_Houdun(Cards_Houdun)
                    Weight_Zhongdun = GetWeight_Zhongdun(Cards_Zhongdun)
                    Weight_Qiandun = Getweight_Qiandun(Cards_Qiandun)
                    if (Weight_Qiandun + Weight_Zhongdun + Weight_Houdun > Weight_All
                            and Compare(Cards_Qiandun, Cards_Zhongdun) and Compare(Cards_Zhongdun, Cards_Houdun)):
                        Weight_All = Weight_Qiandun + Weight_Zhongdun + Weight_Houdun
                        if (Cardlist_AfterTakeQiandun != []):
                            for card in Cardlist_AfterTakeQiandun:
                                if (len(Cards_Qiandun) < 3):
                                    Cards_Qiandun.append(card)
                                elif (len(Cards_Zhongdun) < 5):
                                    Cards_Zhongdun.append(card)
                                else:
                                    Cards_Houdun.append(card)
                        Post_Cards = []
                        Post_Cards.append(Cards_Qiandun)
                        Post_Cards.append(Cards_Zhongdun)
                        Post_Cards.append(Cards_Houdun)
                    Cards_Qiandun = []
                    Cards_Zhongdun = []
                    Cards_Houdun = []

        else:
            Cards_Zhongdun.append(FindBiggestCard(Cardlist_AfterTakeHoudun))
            Weight_Zhongdun = GetWeight_Zhongdun(Cards_Zhongdun)
            Cardlist_AfterTakeZhongdun = CalculateSub(Cardlist_AfterTakeHoudun, Cards_Zhongdun)
            Cards_Qiandun.append(FindBiggestCard(Cardlist_AfterTakeZhongdun))
            Weight_Qiandun = Getweight_Qiandun(Cards_Qiandun)
            Cardlist_AfterTakeQiandun = CalculateSub(Cardlist_AfterTakeZhongdun, Cards_Qiandun)
            Cards_Houdun = list.copy(item1)
            Weight_Houdun = GetWeight_Houdun(Cards_Houdun)
            if (Weight_Qiandun + Weight_Zhongdun + Weight_Houdun > Weight_All
                    and Compare(Cards_Qiandun, Cards_Zhongdun) and Compare(Cards_Zhongdun, Cards_Houdun)):
                Weight_All = Weight_Qiandun + Weight_Zhongdun + Weight_Houdun
                if (Cardlist_AfterTakeQiandun != []):
                    for card in Cardlist_AfterTakeQiandun:
                        if (len(Cards_Qiandun) < 3):
                            Cards_Qiandun.append(card)
                        elif (len(Cards_Zhongdun) < 5):
                            Cards_Zhongdun.append(card)
                        else:
                            Cards_Houdun.append(card)
                Post_Cards = []
                Post_Cards.append(Cards_Qiandun)
                Post_Cards.append(Cards_Zhongdun)
                Post_Cards.append(Cards_Houdun)
            Cards_Qiandun = []
            Cards_Zhongdun = []
    return Post_Cards