Question: Write a function maze runner (maze, start, exit) that takes three inputs: maze (a 2-dimensional matrix representing a maze, a nested list) and start

Write a function maze runner (maze, start, exit) that takes three inputs: maze (a 2-dimensional matrix representing a maze, a nested list) and start and exit coordinates (the x and y coordinates where the maze runner starts and where the runner should finish, a tuple containing 2 integers). The maze is filled with numbers indicating different environments: "0" is a safe area the runner can go on. "1" is a hostile area or blocked area that the runner cannot go to. The function returns True if the runner can escape, else return False. Maze search is actually a difficult task. To simplify, there will always be one path from start to end if it exists. For example, we have a 4x4 maze = [[0, 1, 1, 1], [0, 0, 1, 0], [1, 0, 1, 1], [1, 0, 0, 0]] and start = (0, 0) and exit = (3, 3), then we have: 1. visit the start and check other locations to go: visited = [(0, 0)], unvisited = [(1, 0)] 2. visit the next unvisited location: visited = [(0, 0), (1, 0)], unvisited = [(1, 1)] 3. visit the next unvisited location: visited = [(0, 0), (1, 0), (1, 1)], unvisited = [(2, 1)] 4. visit the next unvisited location: visited = [(0, 0), (1, 0), (1, 1), (2, 1)], unvisited = [(3, 1)] 5. visit the next unvisited location: visited = [(0, 0), (1, 0), (1, 1), (2, 1), (3, 1)], unvisited = [(3,2)] 6. visit the next unvisited location: visited = [(0, 0), (1, 0), (1, 1), (2, 1), (3, 1), (3,2)], unvisited = [(3, 3)] 7. the next visiting location is the exit, so return True However, if the start is (1, 3) from the above example, there is no path to the exit, so it would return False. Note: The runner will always spawn at a safe location (i.e., 0), same for the exit, and they will never be at the same location. Note 2: the maze will always be a square (the number of rows and columns are the same). Hint: you need to keep track of both visited and unvisited locations. For example: Test Result maze[[0, 1, 1, 1], True [0, 0, 1, 0], [1, 0, 1, 1], [1, 0, 0, 0]] start = (0, 0) exit = (3, 3) print(maze runner (maze, start, exit))
Step by Step Solution
There are 3 Steps involved in it
Heres a Python function mazerunner that implements th... View full answer
Get step-by-step solutions from verified subject matter experts
