-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHandRanking.py
158 lines (148 loc) · 3.34 KB
/
HandRanking.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import Card
class HandRanking:
royalFlushes = [[Card.Card(Card.suits[z], Card.numbers[x]) for x in range(8, 13)] for z in range(4)]
def __init__(self, cards):
self.cards = cards
def analyzeRank(self):
"""Returns the rank of the players cards"""
if self.isRoyal():
return 'ROYAL_FLUSH'
if self.isQuad():
return 'QUADS'
if self.isStraightFlush():
return 'STRAIGHT_FLUSH'
i = self.cards
if self.isFullHouse():
return 'FULL_HOUSE'
self.cards = i
if self.isFlush():
return 'FLUSH'
if self.isStraight():
return 'STRAIGHT'
if self.isTrips():
return 'TRIPS'
if self.isTwoPair():
return 'TWO_PAIR'
if self.isOnePair():
return 'ONE_PAIR'
return 'HIGH_CARD'
def isRoyal(self):
for item in self.royalFlushes:
if self.cards[2:] != item:
return False
return True
def isQuad(self):
for x in range(0, 4):
curCard = self.cards[x]
allGood = False
for y in range(x, x + 4):
if x != y:
checkCard = self.cards[y]
if curCard.number != checkCard.number:
allGood = False
break
else:
allGood = True
if allGood:
return True
return False
def isStraightFlush(self):
for x in range(0, 3):
curCard = self.cards[x]
allGood = False
for y in range(x, x + 5):
if x != y:
checkCard = self.cards[y]
if curCard.suit != checkCard.suit or not curCard.is1Less(checkCard):
allGood = False
break
else:
allGood = True
curCard = self.cards[y]
if allGood:
return allGood
return False
def isFullHouse(self):
x = self.isTrips(True)
if x:
return self.isOnePair(True)
return False
def isFlush(self):
toCount = {Card.suits[x]: 0 for x in range(4)}
for item in self.cards:
toCount[item.suit] += 1
for key, val in toCount.items():
if val > 4:
return True
return False
def isStraight(self):
for x in range(0, 3):
curCard = self.cards[x]
allGood = False
for y in range(x, x + 5):
if x != y:
checkCard = self.cards[y]
if not curCard.is1Less(checkCard):
allGood = False
break
else:
allGood = True
curCard = self.cards[y]
if allGood:
return True
return False
def isTrips(self, remove = False):
for x in range(0, 5):
curCard = self.cards[x]
allGood = False
for y in range(x, x + 3):
if x != y:
checkCard = self.cards[y]
if curCard.number != checkCard.number:
allGood = False
break
else:
allGood = True
curCard = self.cards[y]
if allGood:
if remove:
new = self.cards[:x]+self.cards[y:]
self.cards = new
return True
return False
def isTwoPair(self):
count = 0
for x in range(0, 6):
curCard = self.cards[x]
allGood = False
for y in range(x, x + 2):
if x != y:
checkCard = self.cards[y]
if curCard.number != checkCard.number:
allGood = False
break
else:
allGood = True
curCard = self.cards[y]
if allGood:
count += 1
return count >= 2
def isOnePair(self, removed = False):
upper = 6
if removed:
upper = 3
for x in range(0, upper):
curCard = self.cards[x]
allGood = False
for y in range(x, x + 2):
if x != y:
checkCard = self.cards[y]
if curCard.number != checkCard.number:
allGood = False
break
else:
allGood = True
curCard = self.cards[y]
if allGood:
return True
return False