-
Notifications
You must be signed in to change notification settings - Fork 0
/
matchs.py
167 lines (122 loc) · 4.75 KB
/
matchs.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
159
160
161
162
163
164
165
166
167
from abc import abstractmethod
from const import _Const
#######################################################
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# Gokberk Gulgun #
# Psychic Poker #
# #
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#######################################################
CONST = _Const()
class Matchs(object):
@abstractmethod
def match(self, hand):
pass
@abstractmethod
def rank(self):
pass
class StraightFlushHand(Matchs):
"""
Straight Flush Hand
"""
def match(self, cards):
return self.is_straight(cards) and self.is_flush(cards)
def is_straight(self, cards):
if cards[1].getCardValue() == (cards[0].getCardValue() + 1) % 15 and cards[2].getCardValue() == (
cards[0].getCardValue() + 2) % 15 and cards[3].getCardValue() == (cards[0].getCardValue() + 3) % 15 and cards[4].getCardValue() == (cards[0].getCardValue() + 4) % 15:
return True
if cards[0].getCardValue() == 1 and cards[1].getCardValue() == (cards[0].getCardValue() + 24) % 15 and cards[2].getCardValue() == (
cards[1].getCardValue() + 1) % 15 and cards[3].getCardValue() == (cards[1].getCardValue() + 2) % 15 and cards[4].getCardValue() == (cards[1].getCardValue() + 3) % 15 :
return True
return False
def is_flush(self, cards):
for i in range(1, CONST.get_size_of_hand):
if cards[i].getCardType() != cards[0].getCardType():
return False
return True
def rank(self):
return 8
class FourOfKindHand(Matchs):
"""
Four of a kind
"""
def match(self, cards):
for i in range(0, CONST.get_size_of_hand - 3):
if cards[i].getCardValue() == cards[i + 1].getCardValue() and cards[i].getCardValue() == cards[i + 2].getCardValue() and cards[i].getCardValue() == cards[i + 3].getCardValue():
return True
return False
def rank(self):
return 7
class FullHouseHand(Matchs):
"""
Full house
"""
def match(self, cards):
if (cards[0].getCardValue() == cards[1].getCardValue() and cards[0].getCardValue() == cards[2].getCardValue()) and (cards[3].getCardValue() == cards[4].getCardValue()):
return True
return False
def rank(self):
return 6
class FlushHand(Matchs):
"""
Flush
"""
def match(self, cards):
for i in range(1, CONST.get_size_of_hand):
if cards[i].getCardType() != cards[0].getCardType():
return False
return True
def rank(self):
return 5
class StraightHand(Matchs):
"""
Straight
"""
def match(self, cards):
if cards[1].getCardValue() == (cards[0].getCardValue() + 1) % 15 and cards[2].getCardValue() == (cards[0].getCardValue() + 2) % 15 and cards[3].getCardValue() == (cards[0].getCardValue() + 3) % 15 and cards[
4].getCardValue() == (cards[0].getCardValue() + 4) % 15:
return True
if cards[0].getCardValue() == 1 and cards[1].getCardValue() == (cards[0].getCardValue() + 24) % 15 and cards[2].getCardValue() == (
cards[1].getCardValue() + 1) % 15 and cards[3].getCardValue() == (cards[1].getCardValue() + 2) % 15 and cards[4].getCardValue() == (cards[1].getCardValue() + 3) % 15 :
return True
return False
def rank(self):
return 4
class ThreeOfKindHand(Matchs):
"""
Three of a kind
"""
def match(self,cards):
for i in range(0, CONST.get_size_of_hand - 2):
if cards[i].getCardValue() == cards[i + 1].getCardValue() and cards[i].getCardValue() == cards[i + 2].getCardValue():
return True
return False
def rank(self):
return 3
class TwoPairsHand(Matchs):
"""
Two Pairs
"""
def match(self,cards):
for i in range(0, CONST.get_size_of_hand - 1):
if cards[i].getCardValue() == cards[i + 1].getCardValue():
for j in range(i + 2, CONST.get_size_of_hand - 1):
if cards[j].getCardValue() == cards[j + 1].getCardValue():
return True
return False
def rank(self):
return 2
class OnePairHand(Matchs):
"""
One pair
"""
def match(self, cards):
for i in range(0, CONST.get_size_of_hand - 1):
if cards[i].getCardValue() == cards[i + 1].getCardValue():
return True
return False
def rank(self):
return 1
matchs = (OnePairHand,
TwoPairsHand,
ThreeOfKindHand,StraightHand,FlushHand,FullHouseHand,FourOfKindHand,StraightFlushHand)