python 编写一个港式梭哈,发牌时的程序

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_37083038/article/details/95612489

 港式梭哈共28张牌,每次发牌前需要将牌打乱。

我了解的发牌顺序是,给每个玩家发两张,然后每人再一人一张,直至发够五张为止。

所以我发牌的顺序是基于我了解的玩法编写的。

当然我不是计算机专业的,写出来的代码可能比较麻烦。

# -*- coding: utf-8 -*-
"""
Created on Thu Jul 11 14:59:10 2019

@author: leslie lee
"""

import random

suits=['Club','Diamond','Spade','Heart']
ranks=['8','9','T','J','Q','K','A']




def init_hands():
    """将28张牌混合好,并发给两个玩家"""
    hands=[]
    
    for rank in ranks:
        for suit in suits:
            hands.append('{0} {1}'.format(rank,suit))    
    random.shuffle(hands)        
        
    """将牌发给玩家"""
    player1=[]
    player2=[]
    
    player1.append(hands[0])
    player1.append(hands[1])
    player1.append(hands[4])
    player1.append(hands[6])
    player1.append(hands[8]) 
      
    player2.append(hands[2])
    player2.append(hands[3])
    player2.append(hands[5])
    player2.append(hands[7])
    player2.append(hands[9])
    
    #print(hands)
    #print(player1)
    #print(player2)
        
    return player1,player2

如要使用程序,请加上我的名字 leslie lee。

猜你喜欢

转载自blog.csdn.net/qq_37083038/article/details/95612489