Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. grid = [[0, 0, 0, 0, 0, '#'],
  2. ['#', '#', 0, 0, 0, '#'],
  3. [0, 0, 0, '#', 0, 0],
  4. [0, '#', '#', 0, 0, '#'],
  5. [0, '#', 0, 0, '#', 0],
  6. [0, '#', 0, 0, 0, 'g']]
  7.  
  8.  
  9. def printMaze(char, x, y):
  10. if char == "success":
  11. print grid
  12. return
  13. grid[x][y] = char
  14.  
  15.  
  16.  
  17. def search(x, y):
  18. if grid[x][y] == 'g':
  19. print 'found it !'
  20. printMaze('success', 0, 0)
  21. return True
  22. elif grid[x][y] == '#':
  23. printMaze('#', x, y)
  24. return False
  25. elif grid[x][y] == '.':
  26. printMaze('.', x, y)
  27. return False
  28.  
  29. print 'visiting ...'
  30.  
  31. #mark the current step as visited
  32. grid[x][y] = '.'
  33.  
  34. if ((x < len(grid)-1 and search(x + 1, y))
  35. or (y > 0 and search (x, y-1))
  36. or (x > 0 and search (x-1, y))
  37. or (y < len(grid) -1 and search(x, y+1))):
  38. return True
  39. return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement