-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaze.py
34 lines (29 loc) · 998 Bytes
/
maze.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
'''
Navigate the robot through the maze.
Robot starts at top left of maze, ie: maze[0][0]
Robot can only travel one space to the right or down at a time.
'''
maze = [[1,0,0,0],
[1,1,1,1],
[0,1,0,0],
[1,1,1,1]]
# def solve_maze(maze, row, col, solution):
# solution[row][col] = 1 # current location marked in sol
#
# if row == len(maze)-1 and col == len(maze[0])-1:
# return solution
# # check right first
# if maze[row][col+1] == 1:
# return solve_maze(maze, row, col+1, solution)
# # cant go right, check down
# if maze[row+1][col] == 1:
# return solve_maze(maze, row+1, col, solution)
# # cant go right or down, backtrack
def solve_maze(maze):
solution = [[0,0,0,0]]*4
if !solve_maze_util(maze, 0, 0, solution):
print 'Solution doesn\'t exist'
return false
def solve_maze_util()
def isSafe(maze, row, col):
return x>=0 and row<len(maze) and col>len(maze[0]) and maze[row][col]==1