Question: Write python program Write a Python program that reads from a text file named maze.txt a position (i, j) in the maze and a plan
Write a Python program that reads from a text file named maze.txt a position (i, j) in the maze and a plan of the maze then it displays all the paths leading to existing exits in the maze. See Figure 1. A maze is made of positions, consisting of walls (represented by,spaces (represented by 'S) and exits (represented by E'), where it's allowed to move through the spaces to the exit, but it's not allowed to traverse walls. Requirements: 1. The data in the file maze.txt are separated by space 2. Coordinates of the maze start from top to down(i0..M-1) and from left to right (N-0...N-1) 3. lan adequate error message should be displayed if the initial position corresponds to a wall or is outside the maze area f the initial position corresponds to an exit or a space, all the paths connecting the position (i, j) to all the exits should be displayed. 5. The file should be read either from the main() or a dedicated function readFile) called from the main() 6. Beside the main() function, you may use a non-recursive function called solveMaze(maze, i, that calls a recursive helper function named recSolveMaze(...) that returns all the possible paths to the existing exits. Hint 1. Apply the strategy discussed in the class. This may require to use a function generatePaths(..) that generates 4 extensions to the currentPath (by adding the right neighbor, the left neighbor, the neighbor in the previous row and the neighbor in the following row). See Figure 2 2. You may need to set any position in the maze that has been visited in a previous path, to 'V in order to avoid visiting it later through another path. Figure 3 shows a sample run of the program when using the data saved maze.txt shown if Figure 1 1 6 S SSSE 2E Figure 1: Sample contents of maze.txt Figure 2: The 4 allowed movements from a position (j)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
