-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_DresSokobanSolver.py
executable file
·98 lines (77 loc) · 2.79 KB
/
run_DresSokobanSolver.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
#!/usr/bin/python3
import search
import sokoban
import time
import os
import sys
from functools import partial
from threading import Thread
from puzzler import *
_orig_print = print
def print(*args, **kwargs):
_orig_print(*args, flush=True, **kwargs)
def cls():os.system('clear')
def print_goal():
print('''
_____/\\\\\\\\\\\\\\\\\\\\\\\\_______/\\\\\\\\\\__________/\\\\\\\\\\\\\\\\\\_____/\\\\\\_____________
___/\\\\\\//////////______/\\\\\\///\\\\\\______/\\\\\\\\\\\\\\\\\\\\\\\\\\__\\/\\\\\\_____________
__/\\\\\\_______________/\\\\\\/__\\///\\\\\\___/\\\\\\/////////\\\\\\_\\/\\\\\\_____________
_\\/\\\\\\____/\\\\\\\\\\\\\\__/\\\\\\______\\//\\\\\\_\\/\\\\\\_______\\/\\\\\\_\\/\\\\\\_____________
_\\/\\\\\\___\\/////\\\\\\_\\/\\\\\\_______\\/\\\\\\_\\/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\_\\/\\\\\\_____________
_\\/\\\\\\_______\\/\\\\\\_\\//\\\\\\______/\\\\\\__\\/\\\\\\/////////\\\\\\_\\/\\\\\\_____________
_\\/\\\\\\_______\\/\\\\\\__\\///\\\\\\__/\\\\\\____\\/\\\\\\_______\\/\\\\\\_\\/\\\\\\_____________
_\\//\\\\\\\\\\\\\\\\\\\\\\\\/_____\\///\\\\\\\\\\/_____\\/\\\\\\_______\\/\\\\\\_\\/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\_
__\\////////////_________\\/////_______\\///________\\///__\\///////////////__
''')
class Solver(Thread):
def __init__(self,wh_file):
super().__init__()
self.warehouse = sokoban.Warehouse()
self.warehouse.read_warehouse_file(
'./warehouses/'+str(wh_file))
self.puzzle = SokobanPuzzle(self.warehouse)
self.solution = None
self.path = []
self.started = False
def run(self):
self.solution = search.breadth_first_graph_search(self.puzzle)
self.path = [x for x in self.puzzle.goal_path(self.solution)]
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
warehouses = sorted(os.listdir('./warehouses/'))
solutions = {}
for wh_file in warehouses:
try:
solutions[wh_file] = Solver(wh_file)
except AssertionError:
print(wh_file)
continue
for wh_file in warehouses[:12]:
solutions[wh_file].start()
print('started a billion threads')
for w in warehouses[:10]:
cls()
print("AI Sokuban Solver! ~", w)
print("warehouse:",solutions[w].warehouse)
print()
print("Ready?, ",end='')
for i in range(4):
time.sleep(0.3)
print('{}.. '.format(3-i),end='')
animated_solution = solutions[w].path
if not animated_solution:
#wait for solution to finish up
print('....err, sorry, taking a bit longer than I thought..')
solutions[w].join(3)
animated_solution = solutions[w].path
if not animated_solution:
print('.. ok well I had a hard time with this one, but continuing..')
time.sleep(1)
continue
#we should have an animated solution
for node in animated_solution:
cls()
print(str(node.state))
time.sleep(0.1)
cls()
print_goal()
time.sleep(1)