-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolveCrazyTurtle.py
75 lines (51 loc) · 1.61 KB
/
SolveCrazyTurtle.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
import sys
from Grid import Grid
from CardSet import CardSet
def iter_for_card(grid, card, verbose=True):
grid.set_card(card, 1, 1)
input = [grid]
for i in range(8):
mid_step = []
if verbose:
print("Debut iteration : %d, nombre grilles input = %d" %
(i + 1, len(input)))
for grid in input:
mid_step += grid.next_step()
if verbose:
print("Mid iteration : %d, nombre grilles mid_step = %d" %
(i + 1, len(mid_step)))
## cleaning step
output = []
for grid in mid_step:
if grid.exist_valid_card_for_all_next_places():
output.append(grid)
input = output
if verbose:
print("Fin iteration : %d, nombre grilles output = %d" %
(i + 1, len(input)))
if len(input) == 0:
return []
if verbose:
print(output[0])
print(output[0].get_cardset())
print("Nombre de cartes restantes : %d" %
(len(output[0].get_cardset())))
return input
if __name__ == "__main__":
verbose = True
g = Grid()
g.init_crazy_turtle_game()
c = CardSet()
c.init_crazy_turtle_cardset_home()
g.set_cardset(c)
all_card = g.get_cardset()
for i, card in enumerate(all_card):
g = Grid()
g.init_crazy_turtle_game()
c = CardSet()
c.init_crazy_turtle_cardset_home()
g.set_cardset(c)
result = iter_for_card(g, card)
if len(result) > 0:
print(result[0])
sys.exit(0)