This repository has been archived by the owner on Sep 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
play.py
219 lines (151 loc) · 5.5 KB
/
play.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
def play(hand, table):
result_hand = []
result_table = []
# determine series
_series = series(hand)
# determine stairs
_stairs = stairs(hand)
# determine table's stairs
_table_stairs = [x for x in enumerate(table) if not is_serial(x[1])]
# determine table's series
_table_series = [x for x in enumerate(table) if is_serial(x[1])]
# determine stairs can be appended
_app_stairs = appending_stairs(hand, _table_stairs)
# determine series can be appended
_app_series = appending_series(hand, _table_series)
# determine stairs can be separated
_split_stairs = splitting_stairs(_table_stairs)
# determine all series with more than 3 tiles
_big_series = popping_series(_table_series)
# determine all stairs with more than 3 tiles
_big_stairs = popping_stairs(_table_stairs)
# determine all possible jokers substitutions
_jokers_substitutions = jokers_substitution(hand, table)
for serial in _series:
# remove tiles from hand
new_hand = [x for x in hand]
new_hand = []
# add serial to table
new_table = [x for x in table]
new_table.append(serial)
play(new_hand, new_table)
for stair in _stairs:
# remove tiles from hand
new_hand = [x for x in hand]
new_hand = []
# add stair to table
new_table = [x for x in table]
new_table.append(stair)
play(new_hand, new_table)
for app_serial in _app_series:
# remove tile from hand
new_hand = [x for x in hand]
new_hand = []
# add tile to serial in table
new_table = [x for x in table]
new_table = []
play(new_hand, new_table)
for app_stair in _app_stairs:
# remove tile from hand
new_hand = [x for x in hand]
new_hand = []
# add tile to stair in table
new_table = [x for x in table]
new_table = []
play(new_hand, new_table)
for split_stair in _split_stairs:
# remove the stair from table
new_table = [x for x in table]
new_table = []
# split stair
stair1 = []
stair2 = []
# add the new two stairs to the table
new_table.append(stair1)
new_table.append(stair2)
play(hand, new_table)
for big_serial in _big_series:
# remove tile from table's serial
new_table = [x for x in table]
new_table = []
# add tile to the hand
new_hand = [x for x in hand]
new_hand = []
play(new_hand, new_table)
for big_stair in _big_stairs:
# remove tile from table's stair
new_table = [x for x in table]
new_table = []
# add tile to the hand
new_hand = [x for x in hand]
new_hand = []
play(new_hand, new_table)
for joker_substitution in _jokers_substitutions:
# replace joker from table's combination
new_table = [x for x in table]
new_table = []
# add joker to the hand
new_hand = [x for x in hand]
new_hand.append((0, 0))
play(new_hand, new_table)
return result_hand, result_table
def appending_stairs(hand, stairs):
# returns all table's stairs indexes and the tile's index can be added to it
result = []
# determine tiles can be added to any stair in stairs list
possible_tiles = []
for stair in stairs:
color = stair[1][0]
min_value = stair[1][0][0] if stair[1][0][0] != 0 else stair[1][1][0] - 1
max_value = stair[1][-1][0] if stair[1][-1][0] != 0 else stair[1][-2][0] + 1
if min_value != 1 and max_value != 13:
possible_tiles.append((stair[0], [(min_value - 1, color), (max_value + 1, color)]))
elif min_value != 1:
possible_tiles.append((stair[0], [(min_value - 1, color)]))
elif max_value != 13:
possible_tiles.append((stair[0], [(max_value + 1, color)]))
# determine the hand's tiles present in possible_tiles
for tile in hand:
for p_tiles in possible_tiles:
for t in p_tiles[1]:
if tile == t:
result.append((p_tiles[0], t))
return result
def appending_series(hand, series):
# returns all table's series indexes and the tile's index can be added to it
result = []
# determine tiles can be added to any srial in series list
possible_tiles = []
for serial in
return [(0, 0)]
def splitting_stairs(stairs):
# returns all table's stairs indexes can be separated and the index to do that
return [0]
def popping_stairs(stairs):
# returns all table's stairs indexes with more than 3 elements
return [(0, 0)]
def popping_series(series):
# returns all table's series indexes with more than 3 elements
return [0]
def jokers_substitution(hand, table):
# returns all table's combinations indexes with a joker can be replaced with a hand's tile
return [(0, 0)]
def series(hand):
return []
def stairs(hand):
return []
def get_series(combinations):
# returns a sub-set of combinations with the series only
return 0
def get_stairs(combinations):
# returns a sub-set of combinations with the stairs only
return 0
def is_serial(table_combination):
# determine if table_combination is a serial
# get the different values
values = [x[0] for x in table_combination]
if len(values) > 2:
return False
elif len(values) == 2:
return sorted(values)[0] == 0
return True