-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeck.py
More file actions
44 lines (34 loc) · 893 Bytes
/
deck.py
File metadata and controls
44 lines (34 loc) · 893 Bytes
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
import random
from card import Card
class Deck:
def __init__(self, exclude_values=None, contracts={}):
self.cards = []
possible_colors = [ "D", "S", "H", "C" ]
possible_values = [ "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3", "2" ]
# TODO : joker
# TODO : chien
# Build the Deck
for c in possible_colors:
for v in possible_values:
if exclude_values:
if v in exclude_values:
continue
self.cards.append( Card(c, v, contracts) )
def __str__(self):
s = ""
for c in self.cards:
s+=c+" "
return s
def __repr__(self):
return self.__str__()
def __add__(self, other):
return str(self) + other
def __radd__(self, other):
return other + str(self)
def shuffle(self):
random.shuffle(self.cards)
def distribute(self, players):
p = players[ 0 ]
for c in self.cards:
p.addCardToHand(c)
p = p.nextPlayer()