Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- grid = [[0, 0, 0, 0, 0, '#'],
- ['#', '#', 0, 0, 0, '#'],
- [0, 0, 0, '#', 0, 0],
- [0, '#', '#', 0, 0, '#'],
- [0, '#', 0, 0, '#', 0],
- [0, '#', 0, 0, 0, 'g']]
- def printMaze(char, x, y):
- if char == "success":
- print grid
- return
- grid[x][y] = char
- def search(x, y):
- if grid[x][y] == 'g':
- print 'found it !'
- printMaze('success', 0, 0)
- return True
- elif grid[x][y] == '#':
- printMaze('#', x, y)
- return False
- elif grid[x][y] == '.':
- printMaze('.', x, y)
- return False
- print 'visiting ...'
- #mark the current step as visited
- grid[x][y] = '.'
- if ((x < len(grid)-1 and search(x + 1, y))
- or (y > 0 and search (x, y-1))
- or (x > 0 and search (x-1, y))
- or (y < len(grid) -1 and search(x, y+1))):
- return True
- return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement