-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdfs.py
35 lines (26 loc) · 860 Bytes
/
dfs.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
from taquin import Taquin
if __name__ == '__main__':
taq = Taquin()
taq.init_state()
opened_nodes = []
closed_nodes = set()
while not taq.final_state():
if taq not in closed_nodes:
print(taq)
if taq.can_move_down():
opened_nodes.append(taq.move_down())
if taq.can_move_right():
opened_nodes.append(taq.move_right())
if taq.can_move_up():
opened_nodes.append(taq.move_up())
if taq.can_move_left():
opened_nodes.append(taq.move_left())
closed_nodes.add(taq)
if len(opened_nodes) != 0:
taq = opened_nodes.pop()
else:
print("no result")
break
print("visited nodes = ", len(closed_nodes))
print("cost = ", taq.depth)
print(taq)