Python simulation of the landlord deal

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

Python simulation of the landlord deal
Consolidate the foundation of Python (4)
Consolidate the foundation of Python(7)
Consolidate the foundation of Python(6)
Consolidate the foundation of Python(5)
Consolidate the foundation of Python (3)
Python simulation to realize the distribution of playing cards
The usage of wheel in python
Python handles the 4 wheels of Chinese
What is the use of Python
Scrapy simulation login of Python crawler
The premise of Python string pooling
Secrets of the new features of Python 3.8
The father of Python joins Microsoft
The operation of python access hdfs
The usage of tuples in python
End the method of running python
Understanding the meaning of rb in python
Can Python implement the structure of the stack?
Learn the basics of python interactive mode
Logistic regression at the bottom of python
Solve the conflict of multiple versions of python
Python implements the sum of fractional sequences
What is the id function of python
Where is the pip path of python3
The essence of Python language: Itertools library
What are the advantages of python language
The specific method of python instantiation object
python3 realizes the function of mask drawing
What is the prospect of python development
What is the function body of python
The specific method of python import library
Solve the conflict of multiple versions of python
7 features of Python3.9
2.1 The Python Interpreter (python interpreter)
What is the function of adb in python
Detailed explanation of the principle of Python super() method
The difference between the syntax of java and python
Python realizes the development of student management system
Python implements the shuffling of the cards in Doudizhu
The meaning and usage of lists in python
Solve the problem of python running startup error
Can the value of the python dictionary be modified?
Python implements the source code of the snake game
Detailed explanation of the usage of Python decimal module
How about learning python at the age of 27?
The consequences of uninstalling python in ubuntu, very
Python writes the game implementation of fishing master
[898] python get the intersection of two lists | union | difference
Detailed explanation of the principle of Python function parameter classification
What is the advantage of python over corporate language
A brief summary of the difference between Python2 and Python3
Detailed explanation of the principle of Python timer thread pool
Solve the problem of python compiling and installing ssl
Detailed explanation of the implementation steps of Python interface development
How does python call the key of a dictionary
Python crawls the full set of skins of the king pesticide
How to understand the introduction of packages in Python
Basics of Python syntax
Solve the problem of convex hull based on python
Basic syntax of Python