MCPcopy Create free account
hub / github.com/geekcomputers/Python / Deck

Class Deck

BlackJack_game/blackjack_simulate.py:67–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65
66
67class Deck:
68 def __init__(self, num=1):
69 """
70 :param num: the number of deck
71 """
72 self.num = num
73 self.cards = []
74 self.built()
75
76 def __repr__(self):
77 return "\n".join([str(card) for card in self.cards])
78
79 def __len__(self):
80 return len(self.cards)
81
82 def built(self):
83 for _ in range(self.num):
84 ranks = [x for x in range(1, 14)]
85 suits = "Spades Heart Clubs Diamonds".split()
86 for suit in suits:
87 for rank in ranks:
88 card = Card(suit, rank)
89 self.cards.append(card)
90
91 def shuffle(self):
92 for _ in range(self.num):
93 for index in range(len(self.cards)):
94 i = random.randint(0, 51)
95 self.cards[index], self.cards[i] = self.cards[i], self.cards[index]
96
97 def rebuilt(self):
98 self.cards.clear()
99 self.built()
100
101 def deliver(self):
102 return self.cards.pop()
103
104
105class Chips:

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected