Guest User

Untitled

a guest
Jul 17th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. """
  2. Homework 3c: Recursive Graphs
  3. Anya Palkowski
  4. """
  5. import hw3util
  6. import comp211coll
  7. import time
  8.  
  9. def dfs_rec(m, mv, curr_cell, visited, sleeptime):
  10. NESW = [0, 1, 2, 3]
  11. mv.set_color(curr_cell, '#888888', draw=True)
  12. time.sleep(sleeptime)
  13. if curr_cell == m.get_end_cell():
  14. return (curr_cell)
  15. else:
  16. for direction in NESW:
  17. if not m.has_wall(curr_cell, direction):
  18. if m.get_neighbor(curr_cell, direction) not in visited:
  19. curr_cell = m.get_neighbor(curr_cell, direction)
  20. visited.append(curr_cell)
  21. mv.set_color(curr_cell, '#CCCCCC', draw=True)
  22. time.sleep(sleeptime)
  23. p = dfs_rec(m, mv, curr_cell, visited, sleeptime)
  24. if p != ():
  25. return (curr_cell, ) + p
  26. else:
  27. mv.set_color(curr_cell, '#888888', draw=True)
  28. time.sleep(sleeptime)
  29. return ()
  30. else:
  31. mv.set_color(curr_cell, '#888888', draw=True)
  32. time.sleep(sleeptime)
  33. return ()
  34. list = []
  35. list += dfs_rec(m, mv, curr_cell, visited, sleeptime)
  36. return list
  37.  
  38. def solve_rec(m, mv, sleeptime=.05):
  39. visited = []
  40. return dfs_rec(m, mv, m.get_start_cell(), visited, sleeptime)
Add Comment
Please, Sign In to add comment