-
Notifications
You must be signed in to change notification settings - Fork 0
/
Muze.py
38 lines (33 loc) · 1002 Bytes
/
Muze.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
def Muze(grid, x, y):
"""
:type grid: numpy.matrix
:type x: int
:type y: int
:return: boolean
"""
if grid[x][y] == 2:
print('Found at x : {0} - y : {1}'.format(x, y))
return True
elif grid[x][y] == 1:
print('Visit Wall at x : {0} - y : {1}'.format(x, y))
return False
elif grid[x][y] == 3:
print('visited at x : {0} - y : {1}'.format(x, y))
return False
print('visiting x : {0} - y : {1}'.format(x, y))
# set as visited
grid[x][y] = 3
if ((y < len(grid) - 1 and Muze(grid, x, y + 1)) or
(x < len(grid) - 1 and Muze(grid, x + 1, y)) or
(0 < y and Muze(grid, x, y - 1)) or
(0 < x and Muze(grid, x - 1, y))):
return True
return False
# test
grid = [[0, 0, 0, 0, 0, 1],
[1, 1, 0, 0, 0, 1],
[0, 0, 0, 1, 0, 0],
[0, 1, 1, 0, 0, 1],
[0, 1, 0, 0, 1, 0],
[0, 1, 0, 0, 0, 2]]
Muze(grid, 0, 0)