-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhand.py
More file actions
49 lines (40 loc) · 772 Bytes
/
Copy pathhand.py
File metadata and controls
49 lines (40 loc) · 772 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
45
46
47
48
49
#!/usr/bin/pypy
ranks = '23456789TJQKA'
def ridx(r):
return ranks.index(r)
def idxr(idx):
if idx <= 7:
return '0%s' % ranks[idx]
elif idx == 8:
return '1T'
elif idx == 9:
return '2J'
elif idx == 10:
return '3Q'
elif idx == 11:
return '4K'
elif idx == 12:
return '5A'
class Hand(object):
cards = []
def __init__(self, s):
self.cards = self.parse(s)
def parse(self, s):
suited = False
suit = 0
ret = []
for c in s:
if c == '(':
suited = True
elif c == ')':
suited = False
suit += 1
elif c in ranks:
rank = ridx(c)
card = (rank, suit)
ret.append(card)
if not suited:
suit += 1
else:
break
return ret