-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_35.py
More file actions
64 lines (56 loc) · 1.7 KB
/
test_35.py
File metadata and controls
64 lines (56 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from enum import Enum
import random
class Suite(Enum):
"""花色(枚举)"""
SPADE, HEART, CLUB, DIAMOND = range(4)
class Card:
"""牌"""
def __init__(self, suite, face):
self.suite = suite
self.face = face
def __repr__(self):
suites = '♠♥♣♦'
faces = ['', 'A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']
return f'{suites[self.suite.value]}{faces[self.face]}' # 返回牌的花色和点数
def __lt__(self, other):
if self.suite == other.suite:
return self.face < other.face # 同花色比点数
return self.suite.value < other.suite.value # 异花色比点数
class Poker:
def __init__(self):
self.cards = [Card(suite, face)
for suite in Suite
for face in range(1, 14)]
self.current = 0
def shuffle(self):
'''洗牌'''
self.current = 0
random.shuffle(self.cards)
def deal(self):
'''发牌'''
card = self.cards[self.current]
self.current += 1
return card
@property
def has_next(self):
'''还有没有牌可发'''
return self.current < len(self.cards)
class Player:
def __init__(self, name):
self.name = name
self.cards = []
def get_one(self, card):
'''摸牌'''
self.cards.append(card)
def arrange(self):
self.cards.sort()
poker = Poker()
poker.shuffle()
players = [Player('LY'), Player('SL'), Player('ND'), Player('BG')]
for _ in range(13):
for player in players:
player.get_one(poker.deal())
for player in players:
player.arrange()
print(f'{player.name}:', end='')
print(player.cards)