-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcomparator.py
executable file
·122 lines (97 loc) · 2.92 KB
/
comparator.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
from random import choice
from cards import *
class Flush:
def __str__(self):
return "Flush"
def check(cards):
suits = {c.suit for c in cards}
return len(suits) == 1
class Pair:
def __str__(self):
return "Pair"
def check(cards):
nom = {}
for v in map(lambda x: x.value.value, cards):
nom[v] = nom.get(v, 0) + 1
return len(nom) == 4
class TwoPairs:
def __str__(self):
return "TwoPairs"
def check(cards):
nom = {}
for v in map(lambda x: x.value.value, cards):
nom[v] = nom.get(v, 0) + 1
return len(nom) == 3 and max(nom.values()) == 2 and min(nom.values()) == 1
class Set:
def __str__(self):
return "Set"
def check(cards):
nom = {}
for v in map(lambda x: x.value.value, cards):
nom[v] = nom.get(v, 0) + 1
return len(nom) == 3 and max(nom.values()) == 3 and min(nom.values()) == 1
class FullHouse:
def __str__(self):
return "FullHouse"
def check(cards):
nom = {}
for v in map(lambda x: x.value.value, cards):
nom[v] = nom.get(v, 0) + 1
return len(nom) == 2 and max(nom.values()) == 3
class Quads:
def __str__(self):
return "Quads"
def check(cards):
nom = {}
for v in map(lambda x: x.value.value, cards):
nom[v] = nom.get(v, 0) + 1
return len(nom) == 2 and max(nom.values()) == 4
class Straight:
def __str__(self):
return "Straight"
def check(cards):
s = list(map(lambda x: x.value.value, cards))
return not Pair.check(cards) and max(s) - min(s) == 4
class High:
def check(cards):
return True
class StraightFlush():
def __str__(self):
return "StraightFlush"
def check(cards):
return Straight.check(cards) and Flush.check(cards)
combinations = [StraightFlush, Quads, FullHouse, Flush, Straight, Set, TwoPairs, Pair, High]
class Comparator:
def combine(self, cards):
r = []
for i in range(6):
for j in range(i + 1, 7):
r.append(cards[:i] + cards[i + 1: j] + cards[j + 1:])
return r
def compare(self, clients, table):
res = {}
for client_id, cards in clients:
res[max(map(max_combine, combine(cards + table)))].append(client_id)
ans = []
for key in sorted(res):
ans.append(res[key])
return ans
def max_combine(cards):
for c in combinations:
if c.check(cards):
return c()
Suits = [Diamonds, Clubs, Hearts, Spades]
cards = [
Card(2, Diamonds),
Card(5, Diamonds),
Card(9, Diamonds),
Card(11, Diamonds),
Card(0, Diamonds),
Card(2, Hearts),
Card(5, Hearts),
Card(5, Clubs),
Card(5, Clubs),
Card(2, Clubs)
]
#cards = [Card(i, Diamonds) for i in range(2, 7)]
print(*cards)