This example is shared for you python Specific code for simulating the licensing of landlords , For your reference , The details are as follows

subject ： Interesting topic of fighting the landlord

Playing cards is a very popular game , There are many poker related games in the computer . for example , stay Windows Cards under the operating system , Heart wars, etc . In poker games , Shuffling is often required , Is to completely disrupt a deck of cards , Make the arrangement irregular .

requirement ：

1,54 A card of cards 3 Players , farmer 17 Zhang , landlord 20 Zhang .

2, Automatically generate a deck of playing cards ; shuffle the cards ; Deal cards to players ; Arrange the playing cards in the player's hand according to the color and size .**

'''

Interesting questions - Playing cards - fight against landlords

Version: 0.1

Author: jasn

Date: 2020-01-01

Main knowledge points ：random Usage of , Class definition and call

Main function points ： use Python Class implements the initialization of landlords , shuffle the cards , Licensing , Rob the landlord , Manage cards , Color correspondence . The code is as follows

'''

import random

class doudizhu:

# definition 54 Card

def __init__(self):

self.a=[]

for i in range(54):

self.a.append(i)

# shuffle the cards

def xipai(self):

random.shuffle(self.a) # shuffle the cards

n = random.randint(1, 54)

b = self.a[:n] # from n Position cut

c = self.a[n:]

self.a = b + c

# Licensing

def fapai(self):

self.user1=self.a[0:-3:3] # game player 1, The order of getting cards is 0,3,6,9...

self.user2=self.a[1:-3:3] # game player 2, The order of getting cards is 1,4,7,10...

self.user3=self.a[2:-3:3] # game player 3, The order of getting cards is 2,5,8,11...

self.user4=self.a[-3:] # a hand , The order is 51,52,53

# Rob the landlord

def qiangdizhu(self):

i=random.randint(1,3)

self.dizhu=i # Define an instance of a landlord

if i == 1:

self.user1+=self.user4

if i == 2:

self.user2+=self.user4

if i == 3:

self.user3+=self.user4

# Code card

def mapai(self):

self.user1.sort(reverse=True) ## From small to large

self.user2.sort(reverse=True)

self.user3.sort(reverse=True)

# The card sequence corresponds to the suit one by one

def yingshe(self):

huase = [(0, ' Square slice 3'), (1, ' Plum blossom 3'), (2, ' heart 3'), (3, ' spade 3'),

(4, ' Square slice 4'), (5, ' Plum blossom 4'), (6, ' heart 4'), (7, ' spade 4'),

(8, ' Square slice 5'), (9, ' Plum blossom 5'), (10, ' heart 5'), (11, ' spade 5'),

(12, ' Square slice 6'), (13, ' Plum blossom 6'), (14, ' heart 6'), (15, ' spade 6'),

(16, ' Square slice 7'), (17, ' Plum blossom 7'), (18, ' heart 7'), (19, ' spade 7'),

(20, ' Square slice 8'), (21, ' Plum blossom 8'), (22, ' heart 8'), (23, ' spade 8'),

(24, ' Square slice 9'), (25, ' Plum blossom 9'), (26, ' heart 9'), (27, ' spade 9'),

(28, ' Square slice 10'), (29, ' Plum blossom 10'), (30, ' heart 10'), (31, ' spade 10'),

(32, ' Square slice J'), (33, ' Plum blossom J'), (34, ' heart J'), (35, ' spade J'),

(36, ' Square slice Q'), (37, ' Plum blossom Q'), (38, ' heart Q'), (39, ' spade Q'),

(40, ' Square slice K'), (41, ' Plum blossom K'), (42, ' heart K'), (43, ' spade K'),

(44, ' Square slice A'), (45, ' Plum blossom A'), (46, ' heart A'), (47, ' spade A'),

(48, ' Square slice 2'), (49, ' Plum blossom 2'), (50, ' heart 2'), (51, ' spade 2'),

(52, 'BlackJoker'), (53, 'RedJoker')]

zdpai = dict(huase)

paiuser1=''

for i in range(len(self.user1)):

paiuser1+=zdpai[self.user1[i]]+' ' # Store cards as strings

paiuser2 = ''

for i in range(len(self.user2)):

paiuser2 += zdpai[self.user2[i]] + ' '

paiuser3 = ''

for i in range(len(self.user3)):

paiuser3 += zdpai[self.user3[i]] + ' '

paiuser4 = ''

for i in range(len(self.user4)):

paiuser4 += zdpai[self.user4[i]] + ' '

self.user1 = paiuser1 # Reassign the sequence of cards corresponding to the suit to the instance attribute of three players

self.user2 = paiuser2

self.user3 = paiuser3

self.user4 = paiuser4

if __name__ == '__main__':

Player=doudizhu() # Class helper to playes, Convenient call

Player.xipai()

Player.fapai()

Player.qiangdizhu()

Player.mapai()

Player.yingshe()

print(' The landlord of this Council is ： game player {}'.format(Player.dizhu))

print(' a hand ：',Player.user4)

print(' Player one ：',Player.user1)

print(' Player 2 ：',Player.user2)

print(' Playboy ：',Player.user3)

The above is the whole content of this paper , I hope it will be helpful to everyone's study , I also hope you can support Jumi college .

Technology
Daily Recommendation