Fight the landlord with the next neighbor while the old king is not there

These days I am free and itchy, so I want to find my next neighbor to play with the landowner and have some fun while the old king is away from home.
Now, every time I play, I get distracted by my neighbor's clothes, and I wonder if I can use python to get this fight landowner, and then let me focus on my neighbor, oh no, the neighbor's card.

Basic Rules

A deck of playing cards consists of 54 cards, consisting of 3~A, 4 cards each, 1 little king and 1 big king.Cards are represented from smallest to largest with the following characters and strings (where the lowercase Joker is king and the uppercase JOKER is king).

1. Each hand of cards may be entered as a pair, a pair, a sequence of five, three, a bomb (four) and one of the Kings. There is no other case.
2. In addition to the Bomb and King being able to compare with all cards, other types of cards can only be compared with the same type of cards (e.g., pair versus pair, three versus three), regardless of the situation of the cards being split (e.g., split the sub into pieces).

3. Size rules are the same as the common rules you usually know: size, pairs, three comparisons of card sizes; smallest card size in Shunzi; bombs larger than all the cards in front, and card sizes between bombs; the largest card for King;

4. The two hand cards entered will not be equal

Enter a description

Enter two hand cards, connected by'-', each card of each hand is separated by a space, with no space on either side of'-'

Rough ideas

1. First, because there is no number for the suit card and the king of size, it is necessary to convert the suit card and the king of size into numbers.Here J, Q, K, A, 2, joker, JOKER are 11-17, respectively.

#  Convert each J, Q, K, A, 2,joker,JOKER to a specific number 11-17
def replaceFlower(nums):
    nums = nums.replace('JOKER','17')
    nums = nums.replace('joker','16')
    nums = nums.replace('2','15')
    nums = nums.replace('A','14')
    nums = nums.replace('K','13')
    nums = nums.replace('Q','12')
    nums = nums.replace('J','11')
    return nums

2. Convert the converted number into an int array for easy calculation of values

# How to convert an array of strings into an integer array to facilitate comparison of maximum and minimum values
firstChange =  list(map(int,firstChange))
secondChange = list(map(int,secondChange))

3. Determine if it is a bomb

# Determine if it's a bomb
def isBomb(nums):
    # If it's four digits and it's the same value, it's a bomb
    if len(nums) == 4 and min(nums) == max(nums):
        return True

    # If there are 2 cards, the total is 33, that is Wang Fried
    if len(nums) == 2 and sum(nums) == 33:
        return True
    return False

If the number is less than 4 or 5, only a single, paired, three or four, i.e. the maximum and minimum values must be the same to be valid; if the number is 5, consider whether it is a cistron or not.

# Determine if the value entered is correct
def isValidNums(nums):
    # If the number is less than 5, only a single, paired, three or four, that is, the maximum and minimum values must be the same to be valid.
    if len(nums) > 0 and len(nums) < 5 and (max(nums) == min(nums)):
        return True
    # 5 digits, consider whether it is cistron
    elif len(nums) == 5:
        return isContinuous(nums)

    return False

def isContinuous(nums):
    # Sort numbers
    nums.sort()

    for i in range(len(nums) - 1):
        # Two adjacent numbers are the same, certainly not CIS
        if nums[i] == nums[i + 1]:
            return False

        # The latter one is 1 more than the previous one, continue execution
        if nums[i + 1] == nums[i] + 1:
            continue
        else:
            return False

    return True

5. Compare the sizes of two arrays by summing the values of each array to get the results of the array.

def isContinuous(nums):
    # Sort numbers
    nums.sort()

    for i in range(len(nums) - 1):
        # Two adjacent numbers are the same, certainly not CIS
        if nums[i] == nums[i + 1]:
            return False

        # The latter one is 1 more than the previous one, continue execution
        if nums[i + 1] == nums[i] + 1:
            continue
        else:
            return False

    return True

6. The last step is to compare size logic.

def compareNums(firstChange, secondChange, first, second):
    if sum(firstChange) > sum(secondChange):
        print(first)
    else:
        print(second)

Okay, it still looks a bit complicated, and it takes six steps to go back and forth to complete a process.It seems that more thought is needed if you want to fight a landowner against a neighbor.After all, our ticket money can't go with you.

Perform size comparison

When all the above steps have been split up, the natural thing to do now is to apply the split code.Whether it is legal input, whether it takes the bomb process, whether it takes the comparison process, and so on.

# To determine if the two inputs are equal, if they are not, you need to determine whether they are explosive or not, otherwise the direct output is wrong
if len(firstChange) != len(secondChange):
    if isBomb(firstChange) or isBomb(secondChange):
        compareNums(firstChange, secondChange, first, second)
    else:
        print("You input is Error")

else:
    # Determine whether it is legal data
    if isValidNums(firstChange) == False:
        print("You first input is Error " + str(firstChange))

    elif isValidNums(secondChange) == False:
        print("You second input is Error " + str(secondChange))
    else:
        # Legal data, then output results
        compareNums(firstChange, secondChange, first, second)

Now, please enter a few sets of data and see.For example, for A VS 2, cistron 34 5 6 7 VS 6 7 8 9 10

A A-2 2
2 2

Enter the cards you want to play, separated by -
3 4 5 6 7-6 7 8 9 10
6 7 8 9 10

The code was arranged and the result was executed, but my heart was still floating next to me.

There's only one person left now...Only in this way can I feel the value of my own existence, which is interesting.

Pay attention to the public number "Python Column". More fun and interesting Pythons are waiting for you to

Keywords: Python less

Added by DigitalExpl0it on Tue, 06 Aug 2019 01:11:40 +0300