Beispiel #1
0
 def compare(cardlist, cards, gamerules):
     """
     :斗牛牛比牌
     :param cardlist:
     :param cards:
     :param gamerules:
     :return:
     """
     banker_value = Niuniu.get_card_value(cardlist, gamerules)
     banker_array_cards = sorted(cardlist, cmp=Niuniu.reversed_cmp)
     user_value = Niuniu.get_card_value(cards, gamerules)
     if user_value < banker_value:
         return 1
     elif user_value > banker_value:
         return -1
     else:
         user_array_cards = sorted(cards, cmp=Niuniu.reversed_cmp)
         if ZhipaiCardUtils.get_card_value(
                 banker_array_cards[4]) > ZhipaiCardUtils.get_card_value(
                     user_array_cards[4]):
             return 1
         elif ZhipaiCardUtils.get_card_value(
                 banker_array_cards[4]) < ZhipaiCardUtils.get_card_value(
                     user_array_cards[4]):
             return -1
         elif banker_array_cards[4] > user_array_cards[4]:
             return 1
         else:
             return -1
Beispiel #2
0
 def settle(self, request, context):
     """
     :结算
     :param request:
     :param context:
     :return:
     """
     settle = SettleResult()
     data = NiuniuSettleData()
     data.ParseFromString(request.extraData)
     if 0 == request.banker:
         maxUser = request.userSettleData[0]
         max_value = Niuniu.get_card_value(maxUser.cardlist, data.gameRules)
         for u in request.userSettleData:
             user_value = Niuniu.get_card_value(u.cardlist, data.gameRules)
             if user_value > max_value:
                 max_value = user_value
                 maxUser = u
             if user_value == max_value:
                 max_array_card = sorted(maxUser.cardlist, cmp=Niuniu.reversed_cmp)
                 user_array_card = sorted(u.cardlist, cmp=Niuniu.reversed_cmp)
                 if ZhipaiCardUtils.get_card_value(max_array_card[4]) < ZhipaiCardUtils.get_card_value(
                         user_array_card[4]) or (
                         ZhipaiCardUtils.get_card_value(max_array_card[4]) == ZhipaiCardUtils.get_card_value(
                         user_array_card[4]) and max_array_card[4] < user_array_card[4]):
                     max_value = user_value
                     maxUser = u
     for b in request.userSettleData:
         if b.userId == request.banker:
             compareToBanker(data, request, settle, b)
             break
     return settle
Beispiel #3
0
 def isWuhuaniu(cardlist):
     """
     : 五花牛
     :param cardlist:
     :return:
     """
     return ZhipaiCardUtils.get_card_value(
         cardlist[0]) > 10 and ZhipaiCardUtils.get_card_value(
             cardlist[0]) != 14
Beispiel #4
0
 def isSameThree(cardlist):
     """
     :豹子
     :param cardlist:
     """
     return ZhipaiCardUtils.get_card_value(
         cardlist[0]) == ZhipaiCardUtils.get_card_value(
             cardlist[1]) and ZhipaiCardUtils.get_card_value(
                 cardlist[0]) == ZhipaiCardUtils.get_card_value(cardlist[2])
Beispiel #5
0
 def isWuxiaoniu(cardlist):
     """
     : 无小牛
     :param cardlist:
     :return:
     """
     return ZhipaiCardUtils.get_card_value(
         cardlist[4]) < 6 and ZhipaiCardUtils.get_card_value(
             sum(cardlist)) < 11
Beispiel #6
0
 def isSameColor(cardlist):
     """
     :金花
     :param cardlist:
     """
     return ZhipaiCardUtils.get_card_color(
         cardlist[0]) == ZhipaiCardUtils.get_card_color(
             cardlist[1]) and ZhipaiCardUtils.get_card_color(
                 cardlist[0]) == ZhipaiCardUtils.get_card_color(cardlist[2])
Beispiel #7
0
 def isZhadanniu(cardlist):
     """
     : 炸弹牛
     :param cardlist:
     :return:
     """
     return (ZhipaiCardUtils.get_card_value(
         cardlist[0]) == ZhipaiCardUtils.get_card_value(cardlist[3])
             or ZhipaiCardUtils.get_card_value(cardlist[1])
             == ZhipaiCardUtils.get_card_value(cardlist[4]))
Beispiel #8
0
 def isShunziniu(cardlist):
     """
     : 顺子牛
     :param cardlist:
     :return:
     """
     return (ZhipaiCardUtils.get_card_value(cardlist[0]) == (ZhipaiCardUtils.get_card_value(cardlist[1])) - 1
             or ZhipaiCardUtils.get_card_value(cardlist[0]) == (ZhipaiCardUtils.get_card_value(cardlist[1])) - 9) and \
            ZhipaiCardUtils.get_card_value(cardlist[1]) == (ZhipaiCardUtils.get_card_value(cardlist[2])) - 1 and \
            ZhipaiCardUtils.get_card_value(cardlist[2]) == (
                ZhipaiCardUtils.get_card_value(cardlist[3])) - 1 and ZhipaiCardUtils.get_card_value(cardlist[3]) == (
                ZhipaiCardUtils.get_card_value(cardlist[4])) - 1
Beispiel #9
0
 def sameColor(cardlist):
     """
     : 同花牛
     :param cardlist:
     :return:
     """
     sameColorTemp = list()
     sameColorTemp.extend(cardlist)
     sameColorTemp = sorted(sameColorTemp)
     return ZhipaiCardUtils.get_card_color(
         sameColorTemp[0]) == ZhipaiCardUtils.get_card_color(
             sameColorTemp[4])
Beispiel #10
0
 def isStraight(cardlist):
     """
     :顺子
     :param cardlist:
     """
     values = [
         ZhipaiCardUtils.get_card_value(cardlist[0]),
         ZhipaiCardUtils.get_card_value(cardlist[1]),
         ZhipaiCardUtils.get_card_value(cardlist[2])
     ]
     values = sorted(values)
     if values[0] == 2 and values[1] == 3 and values[2] == 14:
         return True
     return values[0] == values[1] - 1 and values[1] == values[2] - 1
Beispiel #11
0
def compareToBanker(data, request, settle, b):
    """
    : 和庄家比牌
    :param data:
    :param request:
    :param settle:
    :param b:
    :return:
    """
    banker_value = Niuniu.get_card_value(b.cardlist, data.gameRules)
    banker_multiple = Niuniu.get_multiple(banker_value, data.gameRules)
    banker_multiple *= b.grab
    win = 0
    banker_array_cards = sorted(b.cardlist, cmp=Niuniu.reversed_cmp)
    for u in request.userSettleData:
        if u.userId != request.banker:
            userSettleResult = settle.userSettleResule.add()
            user_value = Niuniu.get_card_value(u.cardlist, data.gameRules)
            userSettleResult.userId = u.userId
            userSettleResult.cardValue = user_value
            user_multiple = Niuniu.get_multiple(user_value, data.gameRules)
            user_multiple *= b.grab
            if user_value < banker_value:
                userSettleResult.win = -banker_multiple * u.score
                win += banker_multiple * u.score
            elif user_value > banker_value:
                userSettleResult.win = user_multiple * u.score
                win -= user_multiple * u.score
            else:
                user_array_cards = sorted(u.cardlist, cmp=Niuniu.reversed_cmp)
                if ZhipaiCardUtils.get_card_value(banker_array_cards[4]) > ZhipaiCardUtils.get_card_value(
                        user_array_cards[4]):
                    userSettleResult.win = -banker_multiple * u.score
                    win += banker_multiple * u.score
                elif ZhipaiCardUtils.get_card_value(banker_array_cards[4]) < ZhipaiCardUtils.get_card_value(
                        user_array_cards[4]):
                    userSettleResult.win = user_multiple * u.score
                    win -= user_multiple * u.score
                elif banker_array_cards[4] > user_array_cards[4]:
                    userSettleResult.win = -banker_multiple * u.score
                    win += banker_multiple * u.score
                else:
                    userSettleResult.win = user_multiple * u.score
                    win -= user_multiple * u.score
    userSettleResult = settle.userSettleResule.add()
    userSettleResult.userId = b.userId
    userSettleResult.cardValue = banker_value
    userSettleResult.win = win
Beispiel #12
0
    def getShunDouValue(cardlist):
        """
        : 顺斗
        :param cardlist:
        :return:
        """
        shunvalue = 0
        shundoutemp = list()
        for c in cardlist:
            if ZhipaiCardUtils.get_card_value(c) == 14:
                shundoutemp.append(ZhipaiCardUtils.get_card_value(c - 13))
            else:
                shundoutemp.append(ZhipaiCardUtils.get_card_value(c))
        shundoutemp = sorted(shundoutemp, cmp=Niuniu.reversed_cmp)

        for i in range(0, 3):
            if shundoutemp[i] + 1 in shundoutemp and shundoutemp[
                    i] + 2 in shundoutemp:
                shundouvtemp = list()
                shundouvtemp.extend(shundoutemp)
                shundouvtemp.remove(shundoutemp[i])
                shundouvtemp.remove(shundoutemp[i] + 1)
                shundouvtemp.remove(shundoutemp[i] + 2)
                value1 = 10 if shundouvtemp[0] > 10 else shundouvtemp[0]
                value2 = 10 if shundouvtemp[1] > 10 else shundouvtemp[1]
                tempvalue = value1 + value2
                if tempvalue > 10:
                    tempvalue -= 10
                if tempvalue > shunvalue:
                    shunvalue = tempvalue
        shundouvtemp = list()
        shundouvtemp.extend(shundoutemp)
        if 1 in shundouvtemp and 12 in shundouvtemp and 13 in shundouvtemp:
            shundouvtemp = list()
            shundouvtemp.extend(shundoutemp)
            shundouvtemp.remove(1)
            shundouvtemp.remove(12)
            shundouvtemp.remove(13)
            value1 = 10 if shundouvtemp[0] > 10 else shundouvtemp[0]
            value2 = 10 if shundouvtemp[1] > 10 else shundouvtemp[1]
            tempvalue = value1 + value2
            if tempvalue > 10:
                tempvalue -= 10
            if tempvalue > shunvalue:
                shunvalue = tempvalue
        return shunvalue
Beispiel #13
0
 def isHuluniu(cardlist):
     """
     : 葫芦牛
     :param cardlist:
     :return:
     """
     return ((ZhipaiCardUtils.get_card_value(
         cardlist[0]) == ZhipaiCardUtils.get_card_value(cardlist[1])
              and ZhipaiCardUtils.get_card_value(cardlist[2])
              == ZhipaiCardUtils.get_card_value(cardlist[4]))
             or (ZhipaiCardUtils.get_card_value(
                 cardlist[0]) == ZhipaiCardUtils.get_card_value(cardlist[2])
                 and ZhipaiCardUtils.get_card_value(cardlist[3])
                 == ZhipaiCardUtils.get_card_value(cardlist[4])))
Beispiel #14
0
 def reversed_cmp(x, y):
     """
     :牛牛排序方法
     :param x:
     :param y:
     :return:
     """
     if ZhipaiCardUtils.get_card_value(x) == 14:
         x1 = x - 13
     else:
         x1 = x
     if ZhipaiCardUtils.get_card_value(y) == 14:
         y1 = y - 13
     else:
         y1 = y
     if ZhipaiCardUtils.get_card_value(x1) > ZhipaiCardUtils.get_card_value(
             y1):
         return 1
     if ZhipaiCardUtils.get_card_value(x1) < ZhipaiCardUtils.get_card_value(
             y1):
         return -1
     if x > y:
         return 1
     if x < y:
         return -1
     return 0
Beispiel #15
0
 def isDouble(cardlist):
     """
     :对子
     :param cardlist:
     """
     return ZhipaiCardUtils.get_card_value(
         cardlist[0]) == ZhipaiCardUtils.get_card_value(
             cardlist[1]) or ZhipaiCardUtils.get_card_value(
                 cardlist[0]) == ZhipaiCardUtils.get_card_value(
                     cardlist[2]) or (ZhipaiCardUtils.get_card_value(
                         cardlist[1]) == ZhipaiCardUtils.get_card_value(
                             cardlist[2]))
Beispiel #16
0
 def getCardValue(cardlist, cardtype):
     """
     :param cardlist:
     :param cardtype:
     """
     cardlist_values = list()
     for card in cardlist:
         cardlist_values.append(ZhipaiCardUtils.get_card_value(card))
     cardlist_values = sorted(cardlist_values)
     if cardtype == Zhajinhua.CARDTYPE_SHUNJIN or cardtype == Zhajinhua.CARDTYPE_SHUNZI:
         if cardlist_values[0] == 2 and cardlist_values[2] == 14:
             return [3]
         else:
             return [cardlist_values[2]]
     elif cardtype == Zhajinhua.CARDTYPE_DUIZI:
         if cardlist_values[0] == cardlist_values[1]:
             return [cardlist_values[0], cardlist_values[2]]
         else:
             return [cardlist_values[2], cardlist_values[0]]
     else:
         return [cardlist_values[2], cardlist_values[1], cardlist_values[0]]
Beispiel #17
0
    def get_card_value(cardlist, gamerules):
        """
        :获取牌值
        :param cardlist:牌
        :param gamerules:
        :return:
        """
        sum_val = 0
        temp = list()
        for c in cardlist:
            if ZhipaiCardUtils.get_card_value(c) == 14:
                temp.append(c - 13)
                sum_val += 1
            else:
                temp.append(c)
                sum_val += 0 if ZhipaiCardUtils.get_card_value(c) > 10 else c
        temp = sorted(temp, cmp=Niuniu.reversed_cmp)

        # 心悦
        if (gamerules >> 3) % 2 == 1:
            # 同花顺
            if Niuniu.sameColor(temp) and Niuniu.isShunziniu(temp):
                return 17
            # 五小牛
            if Niuniu.isWuxiaoniu(temp):
                return 16
            # 炸弹牛
            if Niuniu.isZhadanniu(temp):
                return 15
            # 葫芦牛
            if Niuniu.isHuluniu(temp):
                return 14
            # 同花牛
            if Niuniu.sameColor(temp):
                return 13
            # 顺子牛
            if Niuniu.isShunziniu(temp):
                return 12
            # 五花牛
            if Niuniu.isWuhuaniu(temp):
                return 11
        else:
            # 五小牛
            if Niuniu.isWuxiaoniu(temp):
                return 16
            # 炸弹牛
            if Niuniu.isZhadanniu(temp):
                return 15
            # 五花牛
            if Niuniu.isWuhuaniu(temp):
                return 11
        val1 = 0
        for i in range(0, 4):
            for j in range(i + 1, 5):
                temp1 = 0 if ZhipaiCardUtils.get_card_value(
                    temp[i]) > 10 else ZhipaiCardUtils.get_card_value(temp[i])
                temp2 = 0 if ZhipaiCardUtils.get_card_value(
                    temp[j]) > 10 else ZhipaiCardUtils.get_card_value(temp[j])
                if (temp1 + temp2) % 10 == sum_val % 10:
                    val1 = (10 if sum_val % 10 == 0 else sum_val % 10)
        # 坎顺斗
        valuetemp = list()
        for t in temp:
            valuetemp.append(10 if (ZhipaiCardUtils.get_card_value(t)) > 10
                             else (ZhipaiCardUtils.get_card_value(t)))
        if gamerules % 2 == 1:
            shunvalue = Niuniu.getShunDouValue(cardlist)
            if val1 < shunvalue:
                val1 = shunvalue
            tempval = valuetemp[3] + valuetemp[4]
            if tempval % 10 == 0:
                tempval = 10
            else:
                tempval %= 10
            if ZhipaiCardUtils.get_card_value(
                    temp[0]) == ZhipaiCardUtils.get_card_value(
                        temp[2]) and tempval > val1:
                val1 = tempval
            tempval = valuetemp[0] + valuetemp[4]
            if tempval % 10 == 0:
                tempval = 10
            else:
                tempval %= 10
            if ZhipaiCardUtils.get_card_value(
                    temp[1]) == ZhipaiCardUtils.get_card_value(
                        temp[3]) and tempval > val1:
                val1 = tempval
            tempval = valuetemp[0] + valuetemp[1]
            if tempval % 10 == 0:
                tempval = 10
            else:
                tempval %= 10
            if ZhipaiCardUtils.get_card_value(
                    temp[2]) == ZhipaiCardUtils.get_card_value(
                        temp[4]) and tempval > val1:
                val1 = tempval
        return val1