Introduction to landlords ：
Landlords are played by three people , Two men fight one landlord , landlord 20 Card . Farmers per person 17 Card .
Wang fried ： king + Xiao Wang It's the biggest card , You can blow up other people's arbitrary cards , Leaflet words The king is bigger than Xiao Wang , Both can replace any card type .
The second is the bomb ： from 2 spot A spot K Push this class to 3 Point explosion , The four cards together are bombs , You can blow up each other's company cards , Single card , Pair , Three generations and one
A plane means three threes and three fours , Or three tens and three J Three and two together are called planes , Aircraft with wings means that aircraft with two single cards is called aircraft with wings .
Three with one means three identical cards , You can bring a single card. It's called three with one
Four belt two ： Four identical cards with two different or identical cards .
The combination of even pairs is three three pairs of cards, which are called even pairs , such as 556677,88991010,QQKKAA This is called Lian right .
Shunzi is composed of five separate cards called shunzi , Minimum five cards , Up to 3-A.
You can play single or double cards , The size of a single card is king - Xiao Wang -2-A-K-Q-J-10-9-8-7-6-5-4-3 Order of .
To achieve Python to write , The following functions have to be realized in turn ：
Generate a deck of cards , shuffle the cards , Licensing , Sort cards , Call the landlord , Judgment of card playing rationality , Card size comparison And so on .
The following figure shows the general process ：
Generate a deck of cards and shuffle
import random pokers1 = ['2','3','4','5','6','7','8','9','10','J','Q','K','A']
pokers2 = [' king ',' Xiao Wang '] pokers_color = [' heart ',' spade ',' Plum blossom ',' block '] pokers =
['%s%s'%(i,j) for i in pokers_color for j in pokers1] + pokers2 # Generate a pair 54 The whole card
random.shuffle(pokers) # shuffle the cards
robot1 =  robot2 =  player =  # Player's card while len(pokers) > 3:# stay 3 Cards i =
pokers.pop() robot1.append(i) j = pokers.pop() robot2.append(j) k =
Sort cards （ Bubble sorting method is used ）
It is estimated that it can be simplified
def poker_sort(a):# Card sorting function a1,a2 = , for i in range(len(a)):# Pick out digital and non digital cards
str_list = list(a[i]) if len(str_list) == 2 or str_list[-1] in
['J','Q','K','A']:# Pick out non digital cards a2.append(a[i]) else: a1.append(a[i]) #print(a1)
#print(a2) i = 0 while 1:# First use bubble sorting method for digital brand for j in range(len(a1)-1-i): str_list
= list(a1[j]) str_list1 = list(a1[j+1]) if len(str_list) == 4:# The card value is 10 The length of the converted list is 4
str_list = '10' if len(str_list1) == 4: str_list1 = '10' if
int(str_list) > int(str_list1): t =a1[j+1] a1[j+1] = a1[j] a1[j] = t i +=
1 if len(a1)-1-i == 1: break #print(a1) i = 0 while 1:# Bubble sorting is used for non digital brands for j in
range(len(a2)-1-i): str_list = list(a2[j]) str_list1 = list(a2[j+1]) if
str_list[-1] == 'J': str_list[-1] = '11' elif str_list[-1] == 'Q': str_list[-1]
= '12' elif str_list[-1] == 'K': str_list[-1] = '13' else: str_list[-1] = '14'
if str_list1[-1] == 'J': str_list1[-1] = '11' elif str_list1[-1] == 'Q':
str_list1[-1] = '12' elif str_list1[-1] == 'K': str_list1[-1] = '13' else:
str_list1[-1] = '14' if str_list == ' Small ' : str_list[-1] = '50'# Xiao Wang Yong 50 replace if
str_list1 == ' Small ' : str_list1[-1] = '50' if str_list == ' large ': str_list[-1]
= '100'# King use 100 replace if str_list1 == ' large ': str_list1[-1] = '100' if
int(str_list[-1]) > int(str_list1[-1]): t =a2[j+1] a2[j+1] = a2[j] a2[j] = t i
+= 1 if len(a2)-1-i == 1: break #print(a2) a = a1 + a2 #print(a) return a
Call the landlord
name = input(' Please enter player name ：\n')# The game character adds two robots to one player print(' Welcome players '+name+'!') # Call the landlord key =
input(' Ask the player '+name+' Call the landlord （y/n）：\n') if key =='y': player = player + pokers player
= poker_sort(player)# Card sorting function from 2 reach A, Xiao Wang , king print(name+' Now the landlord , Card for ：\n',player) else:
robot1 = robot1 + pokers robot1 = poker_sort(robot1) print('robot1 Now the landlord !')
Judgment of card playing rationality
Verification card type Look, it's a single card , Double card , Three with one , aircraft , Shunzi , bomb , Which is the connection peer
Card size comparison
That is, the other party played a card Compare whether you have bigger cards than each other , Come out when you have it , No .