-
Notifications
You must be signed in to change notification settings - Fork 0
/
tester_script_v2.py
206 lines (163 loc) · 4.87 KB
/
tester_script_v2.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
'''
New version of the tester script.
Main change is a more tolerant checking function for the 'taboo_cells' function.
Look at the 'same_multi_line_strings' function to see how multi-line strings will be compared.
added functions
same_multi_line_strings(s1,s2)
test_check_macro_action_seq
A similar script (with different inputs) will be used for marking your code.
Make sure that your code runs without errors with this script.
'''
from __future__ import print_function
from __future__ import division
from sokoban import Warehouse
from mySokobanSolver import my_team, taboo_cells, SokobanPuzzle, check_action_seq
from mySokobanSolver import solve_sokoban_elem, can_go_there, solve_sokoban_macro
import time
puzzle_t1 ='''
#######
#@ $. #
#######'''
puzzle_t2 ='''
#######
# #
# .$. #
## $@$ #
# .$. #
# #
########
'''
puzzle_t3 ='''
#######
#@ $ .#
#. $ #
#######'''
expected_answer_3 ='''
#######
#X #
# X#
#######'''
expected_answer_1 ='''
####
# .#
# ###
#* #
# $@#
# ###
####
'''
def same_multi_line_strings(s1,s2):
'''
Auxiliary function to test two multi line string representing warehouses
'''
L1 = [s.rstrip() for s in s1.strip().split('\n')]
L2 = [s.rstrip() for s in s2.strip().split('\n')]
S1 = '\n'.join(L1)
S2 = '\n'.join(L2)
return S1==S2
def test_warehouse_1():
wh = Warehouse()
# read the puzzle from the multiline string
wh.extract_locations(puzzle_t2.split(sep='\n'))
print("\nPuzzle from multiline string")
print(wh)
def test_warehouse_2():
problem_file = "./warehouses/warehouse_01.txt"
wh = Warehouse()
wh.read_warehouse_file(problem_file)
print("\nPuzzle from file")
print(wh)
print(wh.worker) # x,y coords !!
print(wh.walls) # x,y coords !!
def test_taboo_cells():
problem_file = "./warehouses/warehouse_59.txt"
wh = Warehouse()
wh.read_warehouse_file(problem_file)
answer = taboo_cells(wh)
# begin debug
print("Taboo Cells")
print(answer)
print(wh)
print(len(answer))
#print(expected_answer_3)
#print(len(expected_answer_3))
# end debug
if same_multi_line_strings(answer,expected_answer_3):
print('Test taboo_cells passed\n')
else:
print('** Test taboo_cells failed\n')
# assert( answer.strip() == expected_answer_3.strip() )
def test_check_elem_action_seq():
problem_file = "./warehouses/warehouse_01.txt"
wh = Warehouse()
wh.read_warehouse_file(problem_file)
print('Initial state \n', wh ,'\n')
answer = check_action_seq(wh, ['Right', 'Right','Down'])
if same_multi_line_strings(answer,expected_answer_1):
print('Test check_elem_action_seq passed\n')
else:
print('** Test check_elem_action_seq failed\n')
def test_solve_sokoban_elem():
problem_file = "./warehouses/warehouse_01.txt"
wh = Warehouse()
wh.read_warehouse_file(problem_file)
#wh.extract_locations(puzzle_t2.split(sep='\n'))
# print(wh)
#rint(wh.walls)
print('\nElementary solution')
start = time.time()
answer = solve_sokoban_elem(wh)
end = time.time()
print(end - start)
# print("STOP")
# print(answer)
# if answer == ['Right', 'Right']:
# print('Test solve_sokoban_elem passed\n')
# else:
# print('** Test solve_sokoban_elem failed\n')
def test_can_go_there():
problem_file = "./warehouses/warehouse_205.txt"
wh = Warehouse()
wh.read_warehouse_file(problem_file)
print(wh)
answer = can_go_there(wh,(30,2))
assert( answer == False)
print("TEST 1 PASSED")
print("worker:")
print(wh.worker)
answer = can_go_there(wh, (2,3))
assert( answer == False)
print("TEST 2 PASSED")
def test_solve_sokoban_macro():
problem_file = "./warehouses/warehouse_75.txt"
wh = Warehouse()
wh.read_warehouse_file(problem_file)
print(wh)
answer = solve_sokoban_macro(wh)
print(answer)
# assert( answer == [ ((2,3),'Right'), ((2,4),'Right'), ((3,3),'Left') , ((3,2),'Left') ] )
# print(wh.worker) # x,y coords !!
# print(wh.boxes) # x,y coords !!
def test_check_macro_action_seq():
problem_file = "./warehouses/warehouse_01.txt"
wh = Warehouse()
wh.read_warehouse_file(problem_file)
print(wh)
answer = solve_sokoban_macro(wh.copy())
print("Macro answer")
print(answer)
#print("\ntesting [((2, 3), 'Right')]")
#print( check_macro_action_seq(wh.copy(),[((2, 3), 'Right')]) )
#print("\ntesting [((2, 3), 'Left')]")
#print( check_macro_action_seq(wh.copy(), [((2, 3), 'Left')]) )
if __name__ == "__main__":
pass
# test_warehouse_1() # test Warehouse
# test_warehouse_2() # test Warehouse
# print(my_team()) # should print your team
# test_check_elem_action_seq()
test_solve_sokoban_elem()
# test_taboo_cells()
# test_can_go_there()
# test_solve_sokoban_macro()
# test_check_macro_action_seq()