Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def reverse_maze(maze):
- new_maze = []
- for i in range(len(maze) - 1, -1, -1):
- temp_array = []
- for j in range(len(maze[i]) - 1, -1, -1):
- temp_array.append(maze[i][j])
- new_maze.append(temp_array)
- return new_maze
- directions = [
- [+1, 0], #Down
- [0, +1], #Right
- [-1, 0], #Up
- [0, -1] #Left
- ]
- def crate_matrix(map):
- matrix = []
- for i in range(len(map)):
- matrix.append([-1] * len(map[i]))
- return matrix
- def solve(map, miner, exit):
- map = reverse_maze(map)
- check = crate_matrix(map)
- queue = Queue()
- queue.enqueue([miner["x"], miner["y"]])
- check[miner["x"]][miner["y"]] = 0
- while not queue.empty():
- x = queue.peek()[0]
- y = queue.peek()[1]
- for i in range(4):
- new_x = x + directions[i][0]
- new_y = y + directions[i][1]
- if new_x < len(map) and new_y < len(map[0]) and map[new_x][new_y] and check[new_x][new_y] == -1:
- queue.enqueue([new_x, new_y])
- check[new_x][new_y] = check[x][y] + 1
- queue.dequeue()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement