The examples in this article share the specific code of python simulation of landlord licensing for your reference. The specific content is as follows
**Topic: **Fun with a hundred questions about the landlord
Poker is a very popular game. There are many games related to playing cards in the computer. For example, Solitaire, Hearts War, etc. that come with Windows operating system. In poker games, it is often necessary to perform a shuffling operation, which is to completely shuffle a deck of cards to make their arrangement irregular.
Claim:
1、54 Three playing cards are dealt to 3 players, 17 for farmers and 20 for landlords.
2、 Automatically generate a poker deck; shuffle the cards; distribute the cards to the players; arrange the poker cards in the players' hands according to suit size. **
'''
Hundreds of Fun-Dealing playing cards-Landlord
Please program to distribute playing cards
Version:0.1
Author: jasn
Date:2020-01-01
Main knowledge points: usage of random, definition and call of class
Main function points: Use Python classes to realize the initialization, shuffling, dealing of cards, grabbing the landlords, managing cards, and matching suits. code show as below
'''
import random
classdoudizhu:
# Define 54 cards
def __init__(self):
self.a=[]for i inrange(54):
self.a.append(i)
# Shuffle
def xipai(self):
random.shuffle(self.a) #Shuffle
n = random.randint(1,54)
b = self.a[:n] #Cut cards from position n
c = self.a[n:]
self.a = b + c
# Licensing
def fapai(self):
self.user1=self.a[0:-3:3] #Player 1, the order of getting the cards is 0, 3, 6, 9...
self.user2=self.a[1:-3:3] #Player 2, the order of getting the cards is 1, 4, 7, 10...
self.user3=self.a[2:-3:3] #Player 3, the order of getting the cards is 2, 5, 8, 11...
self.user4=self.a[-3:] #Hole cards, the order is 51, 52, 53
# 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
# Number plate
def mapai(self):
self.user1.sort(reverse=True) ##From small to large
self.user2.sort(reverse=True)
self.user3.sort(reverse=True)
# One-to-one correspondence between card sequence and suit
def yingshe(self):
huase =[(0,'Square Piece 3'),(1,'Plum 3'),(2,'Heart 3'),(3,'3 of spades'),(4,'Square Piece 4'),(5,'Plum 4'),(6,'Heart 4'),(7,'4 of spades'),(8,'Square Piece 5'),(9,'Plum 5'),(10,'5 of hearts'),(11,'5 of spades'),(12,'Square Piece 6'),(13,'Plum 6'),(14,'Heart 6'),(15,'6 of spades'),(16,'Square Piece 7'),(17,'Plum 7'),(18,'7 of hearts'),(19,'7 of spades'),(20,'Square Piece 8'),(21,'Plum 8'),(22,'Heart 8'),(23,'8 of spades'),(24,'Square Piece 9'),(25,'Plum 9'),(26,'9 of hearts'),(27,'9 of spades'),(28,'Square Piece 10'),(29,'Plum 10'),(30,'10 of hearts'),(31,'10 of spades'),(32,'Square Piece J'),(33,'Plum J'),(34,'Heart J'),(35,'J of Spades'),(36,'Square Piece Q'),(37,'Plum Q'),(38,'Heart Q'),(39,'Spades Q'),(40,'Square K'),(41,'Plum K'),(42,'Heart K'),(43,'King of Spades'),(44,'Square Piece A'),(45,'Plum A'),(46,'Ace of Hearts'),(47,'Ace of Spades'),(48,'Square Piece 2'),(49,'Plum 2'),(50,'Heart 2'),(51,'2 of spades'),(52,'BlackJoker'),(53,'RedJoker')]
zdpai =dict(huase)
paiuser1=''for i inrange(len(self.user1)):
paiuser1+=zdpai[self.user1[i]]+' ' #Store the cards in the form of strings
paiuser2 =''for i inrange(len(self.user2)):
paiuser2 += zdpai[self.user2[i]]+' '
paiuser3 =''for i inrange(len(self.user3)):
paiuser3 += zdpai[self.user3[i]]+' '
paiuser4 =''for i inrange(len(self.user4)):
paiuser4 += zdpai[self.user4[i]]+' '
self.user1 = paiuser1 #Re-assign the sequence of cards corresponding to the suit to the instance attributes of the three players
self.user2 = paiuser2
self.user3 = paiuser3
self.user4 = paiuser4
if __name__ =='__main__':
Player=doudizhu() #Assist the class to playes,Easy to call
Player.xipai()
Player.fapai()
Player.qiangdizhu()
Player.mapai()
Player.yingshe()print('The landlord of this game is: player{}'.format(Player.dizhu))print('Hole cards:',Player.user4)print('Player one:',Player.user1)print('Player two:',Player.user2)print('Player three:',Player.user3)
The above is the whole content of this article, I hope it will be helpful to everyone's study.
Recommended Posts