-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEscape the Mines !.py
54 lines (41 loc) · 1.28 KB
/
Escape the Mines !.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
def solve(map, miner, exit):
path = []
width = len(map)
height = len(map[0])
was = []
for i in range(width):
was_line = []
for j in range(height):
was_line.append(False)
was.append(was_line)
def find(pos):
if (pos['x'] == exit['x']) & (pos['y'] == exit['y']):
return True
if (pos['x'] < 0) | (pos['y'] < 0) | (pos['x'] >= width) | (pos['y'] >= height):
return False
if (not map[pos['x']][pos['y']]):
return False
if was[pos['x']][pos['y']]:
return False
was[pos['x']][pos['y']] = True
path.append('right')
if find({'x' : pos['x'] + 1, 'y' : pos['y']}):
return True
path.pop()
path.append('left')
if find({'x': pos['x'] - 1, 'y': pos['y']}):
return True
path.pop()
path.append('up')
if find({'x': pos['x'], 'y': pos['y'] - 1}):
return True
path.pop()
path.append('down')
if find({'x': pos['x'], 'y': pos['y'] + 1}):
return True
path.pop()
was[pos['x']][pos['y']] = False
find(miner)
return path
minemap = [[True], [True], [True], [True]]
print(solve(minemap, {'x':0,'y':0}, {'x':3,'y':0}))