-
Notifications
You must be signed in to change notification settings - Fork 3
/
hand.py
40 lines (26 loc) · 820 Bytes
/
hand.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
38
class Hand():
def __init__(self):
self.cards = []
def is_soft(self):
value = 0
has_ace = False
for card in self.cards:
if card.is_ace():
has_ace = True
value += card.value()
return has_ace and value <= 11
def value(self):
value = 0
has_ace = False
for card in self.cards:
value += card.value()
if card.is_ace():
has_ace = True
if has_ace and value <= 11:
value += 10
return value
def __unicode__(self):
soft = ' soft ' if self.is_soft() else ' '
return u"[%s] (value:%s%s)" % (', '.join(map(unicode, self.cards)), soft, self.value())
def __str__(self):
return unicode(self).encode('utf-8')