-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboardTexture.py
194 lines (184 loc) · 6.85 KB
/
boardTexture.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
from enum import Enum
from poker_card import Player
from collections import Counter
class boardTexture(Enum):
No_Salient = 0
Flush_Possible = 1
Straight_Possible = 2
Flush_Possible_Straight_Possible = 3
Straight_High_Possible = 4
Flush_Possible_Straight_High_Possible = 5
Flush_High_Possible = 6
Flush_High_Possible_Straight_Possible = 7
Flush_High_Possible_Straight_High_Possible = 8
def getBoardTexture():
card_list = []
suit_list = []
flush = 0
straight = 0
if isinstance(Player.public_card[4], tuple):
card_list = [Player.public_card[0][0], Player.public_card[1][0], Player.public_card[2][0],
Player.public_card[3][0], Player.public_card[4][0]]
card_list.sort()
suit_list = [Player.public_card[0][1], Player.public_card[1][1], Player.public_card[2][1],
Player.public_card[3][1], Player.public_card[4][1]]
straight = find_straight(card_list)
flush = find_flush(card_list)
if straight > 2:
if flush < 3:
return boardTexture.No_Salient
elif flush == 3:
return boardTexture.Flush_Possible
elif flush > 3:
return boardTexture.Flush_High_Possible
elif straight == 2:
if flush < 3:
return boardTexture.Straight_Possible
elif flush == 3:
return boardTexture.Flush_Possible_Straight_Possible
elif flush > 3:
return boardTexture.Flush_High_Possible_Straight_Possible
elif straight < 2:
if flush < 3:
return boardTexture.Straight_High_Possible
elif flush == 3:
return boardTexture.Flush_Possible_Straight_High_Possible
elif flush > 3:
return boardTexture.Flush_High_Possible_Straight_High_Possible
elif isinstance(Player.public_card[3], tuple):
card_list = [Player.public_card[0][0], Player.public_card[1][0], Player.public_card[2][0],
Player.public_card[3][0]]
card_list.sort()
suit_list = [Player.public_card[0][1], Player.public_card[1][1], Player.public_card[2][1],
Player.public_card[3][1]]
straight = find_straight(card_list)
flush = find_flush(card_list)
if straight > 2:
if flush < 3:
return boardTexture.No_Salient
elif flush == 3:
return boardTexture.Flush_Possible
elif flush > 3:
return boardTexture.Flush_High_Possible
elif straight == 2:
if flush < 3:
return boardTexture.Straight_Possible
elif flush == 3:
return boardTexture.Flush_Possible_Straight_Possible
elif flush > 3:
return boardTexture.Flush_High_Possible_Straight_Possible
elif straight < 2:
if flush < 3:
return boardTexture.Straight_High_Possible
elif flush == 3:
return boardTexture.Flush_Possible_Straight_High_Possible
elif flush > 3:
return boardTexture.Flush_High_Possible_Straight_High_Possible
elif isinstance(Player.public_card[2], tuple):
card_list = [Player.public_card[0][0], Player.public_card[1][0], Player.public_card[2][0]]
card_list.sort()
suit_list = [Player.public_card[0][1], Player.public_card[1][1], Player.public_card[2][1]]
straight = find_straight(card_list)
flush = find_flush(card_list)
if straight > 2:
if flush < 3:
return boardTexture.No_Salient
elif flush == 3:
return boardTexture.Flush_Possible
elif straight == 2:
if flush < 3:
return boardTexture.Straight_Possible
elif flush == 3:
return boardTexture.Flush_Possible_Straight_Possible
else:
return boardTexture.No_Salient
def find_straight(card_list):
temp_list = card_list.copy()
if len(card_list) == 5:
# 差0张
if all_straight(card_list) or card_list == [2, 3, 4, 5, 14]:
return 0
# 差1张 / 两张
for i in range(5):
temp_list = card_list.copy()
temp_list.remove(temp_list[i])
straight = find_straight(temp_list)
if straight < 3:
return straight
return 3
elif len(card_list) == 4:
# 差1张
# 1或5号位
if all_straight(card_list) or card_list == [3, 4, 5, 14]:
return 1
# 2号位
temp_list = card_list.copy()
temp_list[0] += 1
if all_straight(temp_list) or temp_list == [3, 4, 5, 14]:
return 1
# 3号位
temp_list = card_list.copy()
temp_list[0] += 1
temp_list[1] += 1
if all_straight(temp_list) or temp_list == [3, 4, 5, 14]:
return 1
# 4号位
temp_list = card_list.copy()
temp_list[3] -= 1
if all_straight(temp_list) or temp_list == [2, 3, 4, 13]:
return 1
# 差两张
for i in range(4):
temp_list = card_list.copy()
temp_list.remove(temp_list[i])
if find_straight(temp_list) == 2:
return 2
return 3
elif len(card_list) == 3:
# 差两张
# 012 123 234
if all_straight(card_list) or card_list == [4, 5, 14]:
return 2
# 013
temp_list = [card_list[0], card_list[1], card_list[2]-1]
if all_straight(temp_list):
return 2
# 014
temp_list = [card_list[0], card_list[1], card_list[2]-2]
if all_straight(temp_list) or temp_list == [2, 3, 12]:
return 2
# 023
temp_list = [card_list[0]+1, card_list[1], card_list[2]]
if all_straight(temp_list):
return 2
# 024
temp_list = [card_list[0]+1, card_list[1], card_list[2]-1]
if all_straight(temp_list) or temp_list == [3, 4, 13]:
return 2
# 034
temp_list = [card_list[0]+2, card_list[1], card_list[2]]
if all_straight(temp_list) or temp_list == [4, 5, 14]:
return 2
# 124
temp_list = [card_list[0], card_list[1], card_list[2]-1]
if all_straight(temp_list) or temp_list == [3, 4, 13]:
return 2
# 134
temp_list = [card_list[0]+1, card_list[1], card_list[2]]
if all_straight(temp_list) or temp_list == [4, 5, 14]:
return 2
return 3
def all_straight(card_list):
flag = True
for i in range(len(card_list)-1):
if card_list[i + 1] != card_list[i] + 1:
flag = False
break
return flag
def find_flush(card_list):
c = Counter(card_list)
max = 0
for i in c.values():
if i > max:
max = i
return max