// Allison Obourn // CSE 143 - lecture 18 // Solves a maze using recursive backtracking. // INCOMPLETE! We will finish this code on Friday import java.io.*; import java.util.*; public class SolveMaze { public static void main(String[] args) throws FileNotFoundException { String fileText = ""; Scanner input = new Scanner(new File("maze1.txt")); while (input.hasNextLine()) { fileText += input.nextLine() + "\n"; } Maze maze = new Maze(fileText); maze.setAnimated(true); System.out.println(maze); System.out.println(); int startRow = 1; int startCol = 6; System.out.println("Start from (" + startRow + ", " + startCol + ")"); solve(maze, startRow, startCol); } // Finds a pathway out of the given maze from the given start location. // Pre: maze != null and startRow/Col are within the maze public static void solve(Maze maze, int row, int col) { if(maze.isEscaped()) { // found the exit! } else if (maze.isWall(row, col) || maze.isExplored(row, col)) { // give up! } else { maze.setExplored(row, col); solve(maze, row - 1, col); solve(maze, row + 1, col); solve(maze, row, col - 1); solve(maze, row, col + 1); } } }