-
Notifications
You must be signed in to change notification settings - Fork 0
/
Deck.py
37 lines (34 loc) · 1.17 KB
/
Deck.py
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
import random
from card import Card
class Deck:
def __init__(self):
self.cards = []
suits = ["Spades", "Clubs", "Hearts", "Diamonds"]
ranks = [
{"rank": "A", "value": 11},
{"rank": "2", "value": 2},
{"rank": "3", "value": 3},
{"rank": "4", "value": 4},
{"rank": "5", "value": 5},
{"rank": "6", "value": 6},
{"rank": "7", "value": 7},
{"rank": "8", "value": 8},
{"rank": "9", "value": 9},
{"rank": "10", "value": 10},
{"rank": "J", "value": 10},
{"rank": "Q", "value": 10},
{"rank": "K", "value": 10},
]
for suit in suits:
for rank in ranks:
self.cards.append(Card(suit, rank))
def shuffle(self):
if len(self.cards) > 1:
random.shuffle(self.cards)
def deal(self, number):
cards_dealt = []
for x in range(number):
if len(self.cards) > 0:
card = self.cards.pop()
cards_dealt.append(card)
return cards_dealt