Question: I have the following code, I need to finish the return statement in the findSolution method package maze; import java.io . FileNotFoundException; import java.io .
I have the following code, I need to finish the return statement in the findSolution method package maze;
import java.ioFileNotFoundException;
import java.ioFileReader;
import java.util.Scanner;
MazeSolver is a backtracking version of MazeGame.
@author Mitch Parry
@author Willow Sapphire
@version
public class MazeSolver
The height of game maps.
private final static int HEIGHT ;
The width of game maps.
private final static int WIDTH ;
The game map, as a D array of booleans.
True indicates the spot is blocked.
private boolean wall;
The visited tiles on the board.
True indicates the spot has been visited.
boolean visited;
Constructor sets up the maps and the path list.
@param mazeFile name of the file containing the map.
public MazeSolverString mazeFile
loadMazemazeFile;
Loads the data from the maze file and creates the map
D array.
@param mazeFile the input maze file.
private void loadMazeString mazeFile
wall new booleanHEIGHTWIDTH;
Scanner mazeScanner;
try
mazeScanner new Scannernew FileReadermazeFile;
for int i ; i HEIGHT; i
for int j ; j WIDTH; j
if mazeScannernextequals
wallij true;
mazeScanner.close;
catch FileNotFoundException e
System.out.printlnFile not found: mazeFile;
Prints the map.
public void printMap
for int i ; i HEIGHT; i
for int j ; j WIDTH; j
if wallij
System.out.printX;
else
System.out.print;
System.out.println;
System.out.println;
private String backtrackint row, int col, String pathSoFar
if row HEIGHT && col WIDTH
return pathSoFar;
if row col row HEIGHT col
WIDTH wallrowcol visitedrowcol
return null;
visitedrowcol true;
String posPath up "down", "left", "right";
int moves ;
for int i ; i ; i
String result backtrackrow movesi
col movesi pathSoFar posPathi;
if result null
return result;
visitedrowcol false;
return null;
public String findSolution
backtrack;
return toString;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
