Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. def reverse_maze(maze):
  2. new_maze = []
  3. for i in range(len(maze) - 1, -1, -1):
  4. temp_array = []
  5. for j in range(len(maze[i]) - 1, -1, -1):
  6. temp_array.append(maze[i][j])
  7. new_maze.append(temp_array)
  8. return new_maze
  9.  
  10.  
  11. directions = [
  12. [+1, 0], #Down
  13. [0, +1], #Right
  14. [-1, 0], #Up
  15. [0, -1] #Left
  16. ]
  17.  
  18.  
  19. def crate_matrix(map):
  20. matrix = []
  21. for i in range(len(map)):
  22. matrix.append([-1] * len(map[i]))
  23. return matrix
  24.  
  25.  
  26. def solve(map, miner, exit):
  27. map = reverse_maze(map)
  28.  
  29. check = crate_matrix(map)
  30.  
  31. queue = Queue()
  32. queue.enqueue([miner["x"], miner["y"]])
  33. check[miner["x"]][miner["y"]] = 0
  34.  
  35. while not queue.empty():
  36. x = queue.peek()[0]
  37. y = queue.peek()[1]
  38.  
  39. for i in range(4):
  40. new_x = x + directions[i][0]
  41. new_y = y + directions[i][1]
  42.  
  43. if new_x < len(map) and new_y < len(map[0]) and map[new_x][new_y] and check[new_x][new_y] == -1:
  44. queue.enqueue([new_x, new_y])
  45. check[new_x][new_y] = check[x][y] + 1
  46.  
  47. queue.dequeue()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement