In this assignment, you are asked to complete a Java program that finds the shortest path...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
In this assignment, you are asked to complete a Java program that finds the shortest path that a hare needs to take to go through a grid-shape maze. The hare enters the maze from a specific square (start) and leaves the maze at another specific square (target). 1 Program Input and Maze Map The program starts by asking the user to enter the name of a txt file containing the maze map. The file needs to be a tab-delimited rectangular shape table with multiple rows and columns. Here is an example of input file and the maze it represents: Table 1: Example of input file S\t N\t R2\t N\t D3 N\t R1,D2\t N\t W4\t N N\t DE\t N\t N\t N N\t N\t XR, D2, W2\t D1,R1\t W1 N\t N\t XD\t XR\t N N\t N\t N\t N\t T column 0 column 1 column 2 column 3 column 4 START row 0 row 1 row 2 ↑ ↑ row 3 row 4 row 5 ↑ తత 10.01 - As you see in the example, content of each table cell is a string str that can be interpreted in the following way: str.equals("S"): cell is the start square where hare starts the journey. This cell is always at row 0 and column 0 (unless you want to do the extra-credit part of the assignment). str.equals("T"): cell is the target square where hare ends the journey. This cell is always at the last row and last column (unless you want to do the extra-credit part of the assignment). • str.equals("N"): cell has no special property. Hare can move either one square to the right or one square to the bottom of the map (unless you want to do the extra-credit part of the assignment). str.equals("DE"): cell is a dead-end which means that if hare enters this cell, there is no way out of it. str.contains("W"): cell is a waiting square! If hare enters this cell, it needs to stay and wait in the cell for a specific units of time before leaving it. The length of waiting time is determined by the number that comes after 'W' (e.g. "W5" means that hare needs to stay and wait for 5 consequent steps before moving out of the cell). str.contains("XR"): cell is a no-right square! If hare enters this cell, it can't exit by moving to the right square. • !str.contains(“XR") && str.contains("R"): cell has a ladder on it! If hare enters this cell, it can either move normally (one step to the neighboring squares) or use the ladder to move multiple squares to the right. The length of ladder comes after the letter '‘R' (e.g. "R3" means that there is a horizontal ladder of length 3). str.contains("XD"): cell is a no-down square! If hare enters this cell, it can't exit by moving down. !str.contains("XD") && str.contains(“D”): cell has a ladder on it! If hare enters this cell, it can either move normally (one step to the neighboring squares) or use the ladder to move down multiple squares. The length of ladder comes after the letter 'D' (e.g. "D4" means that there is a vertical ladder of length 4, while “R3,D4" means that there is a ladder that moves hare 3 cells to right and 4 cells to the bottom of the maze). 2 Finding the Shortest Path Given a maze, there may be many paths that allows hare to move from start to the target square. Some paths took longer than others. The goal of the program is to find the shortest path using the "Maze.solve" method available in the starter code. Example of Shortest Path in a Maze Consider the maze given in Table 1. There are many paths from start to target square. Below, you can find some of them and their corresponding lengths: • (0,0) → (1,0) → (2,0) → (3,0) → (4,0) → (5,0) → (5, 1) → (5, 2) · → (5,0) → (5,1) → (5, 2) → (5,3) → (5,4). Length: 9 (0, 0) → (0, 1) → (0, 2) → (0, 4) → (3,4) → (3,4) → (4, 4) → (5,4). Length: 7 • (0,0) → (1,0) → (1,1) → (3,2) → (3,2) → (3,2) → (5, 2) → (5, 3) → (5,4). Length: 8 (0,0) → (1,0) → (1, 1) → (2, 1) dead-end. Length: ∞. After considering all possible paths, the shortest path is the one with length 7 (second path. in the list). Recursive Solution The current draft of the method recursively solves the maze assuming that all of the maze cells with the exception of source and target are normal squares (i.e. hare can move to either the right or bottom neighbors). You need to manipulate the implementation of this method so that it can find the shortest path given a maze containing all kinds of squares (normal, waiting, dead-end, no-right, no- down and squares with ladders). Hint: only focus on manipulating Maze.solveHelper method. 11 12 13 14 15 16 17 again: 18 19 20 21 22 23 24 25 1 import java.io.File; 2 import java.util.ArrayList; 3 import java.util.Scanner; 4 5 public class Main { 6 7 8 9 10 06 1234567 private static Maze maze; private static ArrayList<String[]> readInputFile(Scanner keyboard) { System.out.print( "Please enter the name (including extenstion and possibly path) of the txt file containing the map: "); Scanner file null; ArrayList<String[]> map = new ArrayList<String[]>(); do { try { file = new Scanner(new File(keyboard.nextLine())); } catch (Exception e) { System.out.print("Error: Something is wrong with the input file. Please try "); continue; } while (file.hasNextLine()) { map.add(file.nextLine().split("\t")); if (map.size() > 1 && map.get(map.size() - 2).length != map.get(map.size() - 1).length) { file = null; System.out.println("Error: map does not have a rectangular shape."); break; 26 } 27 } 28 29 30 31 32 null); 33 34 } 35 36 37 38 for (int r = 0; r < maze.getRows(); r++) 39 40 input.get(r)[c]; 41 42 43 44 45 46 47 48 49 else { 50 51 52 53 54 55 56 57 58 59 60 61 } 62 63 64 65 66 67 68 maze.addVerticalJump(r, c, -cell.nextInt()); return false; // wrong format if (map.isEmpty() || map.get(0).length System.out.println("Error: map is empty."); file = null; } while (file == return map; private static boolean interpretMap(ArrayList<String[]> input) { maze = new Maze(input.size(), input.get(0).length); for (int c = 0; c < maze.getColumns(); c++) { String current = if (current.equals("N")) continue; else if (current.equals("S")) maze.addStart(r, c); else if (current.equals("T")) maze.addTarget(r, c); else if (current.equals("DE")) maze.addDeadEnd(r, c); if (current.contains("XD") ) maze.addNoDown(r, c); else if (current.contains("XU")) maze.addNoUp(r, c); else if (current.contains("D")) { Scanner cell = new Scanner(current.substring(current.indexOf("D") + 1)); cell.useDelimiter("[^0-9]"); try { maze.addVerticalJump(r, c, cell.nextInt()); } catch (Exception exp) { return false; // wrong format } else if (current.contains("U")) { Scanner cell = new Scanner(current.substring(current.indexOf("U") + 1)); cell.useDelimiter("[^0-9]"); try { } catch (Exception exp) { == 0 ) { 69 } 70 } 71 if (current.contains("XR")) 72 73 74 75 76 77 maze.addNoRight(r, c); else if (current.contains("XL")) maze.addNoLeft(r, c); else if (current.contains("R")) { Scanner cell = new Scanner(current.substring(current.indexOf("R") + 1)); cell.useDelimiter("[^0-9]"); 78 try { 79 maze.addHorizontalJump(r, c, cell.nextInt()); 80 } catch (Exception exp) { 81 return false; // wrong format 82 } 83 84 85 } else if (current.contains("L")) { Scanner cell = new Scanner(current.substring(current.indexOf("L") + 1)); cell.useDelimiter("[^0-9]"); 86 try { 87 maze.addHorizontalJump(r, c, -cell.nextInt()); 88 } catch (Exception exp) { 89 return false; // wrong format 90 } 91 } 92 93 94 if (current.contains("W")) { Scanner cell = new Scanner(current.substring(current.indexOf("W") + 1)); cell.useDelimiter("[^0-9]"); 95 try { 96 maze.addDelay(r, c, cell.nextInt()); 97 } catch (Exception exp) { 98 return false; // wrong format 99 } 100 } 101 } 102 103 104 } 105 106 107 108 109 do { 110 111 112 readInputFile(keyboard); 113 114 115 116 return true; // correct format public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); ArrayList<String[]> input = null; if (input != null) System.out.println("Error: Input file has wrong format!"); input = } while (!interpretMap(input)); maze.solve(); 117 maze.printSolution(); } 118 119 } 120 1 import java.io.File; 2 import java.util.*; 3 4 public class Maze { 456 class Cell { public boolean deadend = false, noRight = false, noLeft = false, noDown = = false, start = false, 7 8 target = false; public int horizontalJump = 0; 9 10 public int verticalJump public int wait = 0; = 0; 11 public int shortest = -1; // not yet discovered 12 public Cell nextStep; false, noUp 14 15 16 17 13 public int row, col; 3456 Cell(int row, int col) { this.row = row; col; this.col = 18 } 19 20 21 22 23 Cell(int row, int col, int wait) { this.row = row; this.col = col; this.wait = wait; 24 } 25 26 27 if (wait == 0 ) 28 29 public String toString() { II return "(" + row + ", + col + ")"; return new Cell(row, col, wait - 1).toString() + "->(" + row + + col + ")"; 30 } 31 } 32 33 private int rows, columns; 34 private Cell[] [] map; 35 36 public int getRows() { 37 return rows; 38 } 39 40 public int getColumns() { 41 42 } 43 44 45 46 47 48 49 மம 50 51 52 53 return columns; public Maze(int rows, int columns) { this.rows = rows; this.columns = columns; map = new Cell[rows][columns]; for (int r = 0; r < rows; r++) } for (int c = 0; c <columns; c++) map[r][c] = new Cell(r, c); private Cell getStart() { 54 for (int r = 0; r < rows; r++) 55 56 57 58 59 } 60 61 for (int c = 0; c <columns; c++) if (map[r][c].start) return map[r][c]; return null; private Cell getTarget() { 62 for (int r = 0; r < rows; r++) 63 64 65 return map[r][c]; 66 for (int c = 0; c <columns; c++) if (map[r][c].target) return null; 67 } 68 69 70 71 72 Cell start = getStart(), target 73 74 75 } 76 77 78 79 80 81 bottom neighbor 82 82 public void solve() { // Step 1: find the start; it should be the top-left square if you don't do the // extra credit. = getTarget(); // Step 2: call the recursive helper function solveHelper(start, target); private void solveHelper(Cell source, Cell target) { if (source.row == target.row && source.col return; if (source.row < rows cell is not discovered yet! == target.col)// base case == -1)// down 1 && map[source.row + 1] [source.col].shortest solveHelper(map[source.row + 1] [source.col], target); // call it recursively for if (source.col < columns right cell is not discovered - 1 && map[source.row][source.col + 1].shortest == -1)// // yet! solveHelper(map[source.row][source.col + 1], target); // call it recursively for 83 84 right neighbor 85 if (source.row == rows - 1) { 86 source.shortest = map[source.row] [source.col + 1].shortest + 1; 87 source.nextStep = map[source.row] [source.col + 1]; 88 } else if (source.col == = columns -1) { 89 90 source.shortest = source.nextStep = map[source.row + 1] [source.col].shortest + 1; map[source.row + 1] [source.col]; 91 } else { 92 93 94 95 96 Cell rightNeighbor = map[source.row + 1] [source.col]; source.shortest = Math.min (bottomNeighbor.shortest, rightNeighbor.shortest) + 1; bottomNeighbor.shortest + 1) == if (source.shortest source.nextStep = bottomNeighbor; else map[source.row] [source.col + 1], bottomNeighbor = 97 source.nextStep = rightNeighbor; 98 } 99 } 100 101 102 103 public void addTarget (int rowIndex, int columnIndex) { map[rowIndex] [columnIndex].target true; map[rowIndex] [columnIndex]. shortest = 0; 104 105 106 } 107 108 public void addStart(int rowIndex, int columnIndex) { map[rowIndex] [columnIndex].start = true; 109 } 110 111 112 public void addDead End (int rowIndex, int columnIndex) { map[rowIndex] [columnIndex].deadend = true; 113 } 114 115 116 public void addNoDown(int rowIndex, int columnIndex) { map[rowIndex][columnIndex].noDown = true; 117 } 118 119 120 public void addNoUp(int rowIndex, int columnIndex) { map[rowIndex][columnIndex].noUp = true; 121 122 } 123 124 public void addNoLeft(int rowIndex, int columnIndex) { map[rowIndex] [columnIndex].noLeft = true; 125 } 126 127 128 public void addVerticalJump(int rowIndex, int columnIndex, int length) { map[rowIndex][columnIndex].verticalJump = length; 129 130 } 131 132 public void addNoRight(int rowIndex, int columnIndex) { map[rowIndex] [columnIndex].noRight = true; 133 } 134 135 136 137 } 138 139 140 141 } 142 143 144 Cell source = getStart(); 145 public void addHorizontalJump(int rowIndex, int columnIndex, int length) { map[rowIndex][columnIndex].horizontalJump length; public void addDelay(int rowIndex, int columnIndex, int length) { map[rowIndex][columnIndex].wait public void printSolution() { System.out.println("Shortest path of length length; II + source.shortest + : "); 146 Cell current = source; 147 while (current != null) { 148 System.out.print(current + (current.nextStep == null ? || || : "->")); 149 current = current.nextStep; 150 } 151 152 } 153 } 154 In this assignment, you are asked to complete a Java program that finds the shortest path that a hare needs to take to go through a grid-shape maze. The hare enters the maze from a specific square (start) and leaves the maze at another specific square (target). 1 Program Input and Maze Map The program starts by asking the user to enter the name of a txt file containing the maze map. The file needs to be a tab-delimited rectangular shape table with multiple rows and columns. Here is an example of input file and the maze it represents: Table 1: Example of input file S\t N\t R2\t N\t D3 N\t R1,D2\t N\t W4\t N N\t DE\t N\t N\t N N\t N\t XR, D2, W2\t D1,R1\t W1 N\t N\t XD\t XR\t N N\t N\t N\t N\t T column 0 column 1 column 2 column 3 column 4 START row 0 row 1 row 2 ↑ ↑ row 3 row 4 row 5 ↑ తత 10.01 - As you see in the example, content of each table cell is a string str that can be interpreted in the following way: str.equals("S"): cell is the start square where hare starts the journey. This cell is always at row 0 and column 0 (unless you want to do the extra-credit part of the assignment). str.equals("T"): cell is the target square where hare ends the journey. This cell is always at the last row and last column (unless you want to do the extra-credit part of the assignment). • str.equals("N"): cell has no special property. Hare can move either one square to the right or one square to the bottom of the map (unless you want to do the extra-credit part of the assignment). str.equals("DE"): cell is a dead-end which means that if hare enters this cell, there is no way out of it. str.contains("W"): cell is a waiting square! If hare enters this cell, it needs to stay and wait in the cell for a specific units of time before leaving it. The length of waiting time is determined by the number that comes after 'W' (e.g. "W5" means that hare needs to stay and wait for 5 consequent steps before moving out of the cell). str.contains("XR"): cell is a no-right square! If hare enters this cell, it can't exit by moving to the right square. • !str.contains(“XR") && str.contains("R"): cell has a ladder on it! If hare enters this cell, it can either move normally (one step to the neighboring squares) or use the ladder to move multiple squares to the right. The length of ladder comes after the letter '‘R' (e.g. "R3" means that there is a horizontal ladder of length 3). str.contains("XD"): cell is a no-down square! If hare enters this cell, it can't exit by moving down. !str.contains("XD") && str.contains(“D”): cell has a ladder on it! If hare enters this cell, it can either move normally (one step to the neighboring squares) or use the ladder to move down multiple squares. The length of ladder comes after the letter 'D' (e.g. "D4" means that there is a vertical ladder of length 4, while “R3,D4" means that there is a ladder that moves hare 3 cells to right and 4 cells to the bottom of the maze). 2 Finding the Shortest Path Given a maze, there may be many paths that allows hare to move from start to the target square. Some paths took longer than others. The goal of the program is to find the shortest path using the "Maze.solve" method available in the starter code. Example of Shortest Path in a Maze Consider the maze given in Table 1. There are many paths from start to target square. Below, you can find some of them and their corresponding lengths: • (0,0) → (1,0) → (2,0) → (3,0) → (4,0) → (5,0) → (5, 1) → (5, 2) · → (5,0) → (5,1) → (5, 2) → (5,3) → (5,4). Length: 9 (0, 0) → (0, 1) → (0, 2) → (0, 4) → (3,4) → (3,4) → (4, 4) → (5,4). Length: 7 • (0,0) → (1,0) → (1,1) → (3,2) → (3,2) → (3,2) → (5, 2) → (5, 3) → (5,4). Length: 8 (0,0) → (1,0) → (1, 1) → (2, 1) dead-end. Length: ∞. After considering all possible paths, the shortest path is the one with length 7 (second path. in the list). Recursive Solution The current draft of the method recursively solves the maze assuming that all of the maze cells with the exception of source and target are normal squares (i.e. hare can move to either the right or bottom neighbors). You need to manipulate the implementation of this method so that it can find the shortest path given a maze containing all kinds of squares (normal, waiting, dead-end, no-right, no- down and squares with ladders). Hint: only focus on manipulating Maze.solveHelper method. 11 12 13 14 15 16 17 again: 18 19 20 21 22 23 24 25 1 import java.io.File; 2 import java.util.ArrayList; 3 import java.util.Scanner; 4 5 public class Main { 6 7 8 9 10 06 1234567 private static Maze maze; private static ArrayList<String[]> readInputFile(Scanner keyboard) { System.out.print( "Please enter the name (including extenstion and possibly path) of the txt file containing the map: "); Scanner file null; ArrayList<String[]> map = new ArrayList<String[]>(); do { try { file = new Scanner(new File(keyboard.nextLine())); } catch (Exception e) { System.out.print("Error: Something is wrong with the input file. Please try "); continue; } while (file.hasNextLine()) { map.add(file.nextLine().split("\t")); if (map.size() > 1 && map.get(map.size() - 2).length != map.get(map.size() - 1).length) { file = null; System.out.println("Error: map does not have a rectangular shape."); break; 26 } 27 } 28 29 30 31 32 null); 33 34 } 35 36 37 38 for (int r = 0; r < maze.getRows(); r++) 39 40 input.get(r)[c]; 41 42 43 44 45 46 47 48 49 else { 50 51 52 53 54 55 56 57 58 59 60 61 } 62 63 64 65 66 67 68 maze.addVerticalJump(r, c, -cell.nextInt()); return false; // wrong format if (map.isEmpty() || map.get(0).length System.out.println("Error: map is empty."); file = null; } while (file == return map; private static boolean interpretMap(ArrayList<String[]> input) { maze = new Maze(input.size(), input.get(0).length); for (int c = 0; c < maze.getColumns(); c++) { String current = if (current.equals("N")) continue; else if (current.equals("S")) maze.addStart(r, c); else if (current.equals("T")) maze.addTarget(r, c); else if (current.equals("DE")) maze.addDeadEnd(r, c); if (current.contains("XD") ) maze.addNoDown(r, c); else if (current.contains("XU")) maze.addNoUp(r, c); else if (current.contains("D")) { Scanner cell = new Scanner(current.substring(current.indexOf("D") + 1)); cell.useDelimiter("[^0-9]"); try { maze.addVerticalJump(r, c, cell.nextInt()); } catch (Exception exp) { return false; // wrong format } else if (current.contains("U")) { Scanner cell = new Scanner(current.substring(current.indexOf("U") + 1)); cell.useDelimiter("[^0-9]"); try { } catch (Exception exp) { == 0 ) { 69 } 70 } 71 if (current.contains("XR")) 72 73 74 75 76 77 maze.addNoRight(r, c); else if (current.contains("XL")) maze.addNoLeft(r, c); else if (current.contains("R")) { Scanner cell = new Scanner(current.substring(current.indexOf("R") + 1)); cell.useDelimiter("[^0-9]"); 78 try { 79 maze.addHorizontalJump(r, c, cell.nextInt()); 80 } catch (Exception exp) { 81 return false; // wrong format 82 } 83 84 85 } else if (current.contains("L")) { Scanner cell = new Scanner(current.substring(current.indexOf("L") + 1)); cell.useDelimiter("[^0-9]"); 86 try { 87 maze.addHorizontalJump(r, c, -cell.nextInt()); 88 } catch (Exception exp) { 89 return false; // wrong format 90 } 91 } 92 93 94 if (current.contains("W")) { Scanner cell = new Scanner(current.substring(current.indexOf("W") + 1)); cell.useDelimiter("[^0-9]"); 95 try { 96 maze.addDelay(r, c, cell.nextInt()); 97 } catch (Exception exp) { 98 return false; // wrong format 99 } 100 } 101 } 102 103 104 } 105 106 107 108 109 do { 110 111 112 readInputFile(keyboard); 113 114 115 116 return true; // correct format public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); ArrayList<String[]> input = null; if (input != null) System.out.println("Error: Input file has wrong format!"); input = } while (!interpretMap(input)); maze.solve(); 117 maze.printSolution(); } 118 119 } 120 1 import java.io.File; 2 import java.util.*; 3 4 public class Maze { 456 class Cell { public boolean deadend = false, noRight = false, noLeft = false, noDown = = false, start = false, 7 8 target = false; public int horizontalJump = 0; 9 10 public int verticalJump public int wait = 0; = 0; 11 public int shortest = -1; // not yet discovered 12 public Cell nextStep; false, noUp 14 15 16 17 13 public int row, col; 3456 Cell(int row, int col) { this.row = row; col; this.col = 18 } 19 20 21 22 23 Cell(int row, int col, int wait) { this.row = row; this.col = col; this.wait = wait; 24 } 25 26 27 if (wait == 0 ) 28 29 public String toString() { II return "(" + row + ", + col + ")"; return new Cell(row, col, wait - 1).toString() + "->(" + row + + col + ")"; 30 } 31 } 32 33 private int rows, columns; 34 private Cell[] [] map; 35 36 public int getRows() { 37 return rows; 38 } 39 40 public int getColumns() { 41 42 } 43 44 45 46 47 48 49 மம 50 51 52 53 return columns; public Maze(int rows, int columns) { this.rows = rows; this.columns = columns; map = new Cell[rows][columns]; for (int r = 0; r < rows; r++) } for (int c = 0; c <columns; c++) map[r][c] = new Cell(r, c); private Cell getStart() { 54 for (int r = 0; r < rows; r++) 55 56 57 58 59 } 60 61 for (int c = 0; c <columns; c++) if (map[r][c].start) return map[r][c]; return null; private Cell getTarget() { 62 for (int r = 0; r < rows; r++) 63 64 65 return map[r][c]; 66 for (int c = 0; c <columns; c++) if (map[r][c].target) return null; 67 } 68 69 70 71 72 Cell start = getStart(), target 73 74 75 } 76 77 78 79 80 81 bottom neighbor 82 82 public void solve() { // Step 1: find the start; it should be the top-left square if you don't do the // extra credit. = getTarget(); // Step 2: call the recursive helper function solveHelper(start, target); private void solveHelper(Cell source, Cell target) { if (source.row == target.row && source.col return; if (source.row < rows cell is not discovered yet! == target.col)// base case == -1)// down 1 && map[source.row + 1] [source.col].shortest solveHelper(map[source.row + 1] [source.col], target); // call it recursively for if (source.col < columns right cell is not discovered - 1 && map[source.row][source.col + 1].shortest == -1)// // yet! solveHelper(map[source.row][source.col + 1], target); // call it recursively for 83 84 right neighbor 85 if (source.row == rows - 1) { 86 source.shortest = map[source.row] [source.col + 1].shortest + 1; 87 source.nextStep = map[source.row] [source.col + 1]; 88 } else if (source.col == = columns -1) { 89 90 source.shortest = source.nextStep = map[source.row + 1] [source.col].shortest + 1; map[source.row + 1] [source.col]; 91 } else { 92 93 94 95 96 Cell rightNeighbor = map[source.row + 1] [source.col]; source.shortest = Math.min (bottomNeighbor.shortest, rightNeighbor.shortest) + 1; bottomNeighbor.shortest + 1) == if (source.shortest source.nextStep = bottomNeighbor; else map[source.row] [source.col + 1], bottomNeighbor = 97 source.nextStep = rightNeighbor; 98 } 99 } 100 101 102 103 public void addTarget (int rowIndex, int columnIndex) { map[rowIndex] [columnIndex].target true; map[rowIndex] [columnIndex]. shortest = 0; 104 105 106 } 107 108 public void addStart(int rowIndex, int columnIndex) { map[rowIndex] [columnIndex].start = true; 109 } 110 111 112 public void addDead End (int rowIndex, int columnIndex) { map[rowIndex] [columnIndex].deadend = true; 113 } 114 115 116 public void addNoDown(int rowIndex, int columnIndex) { map[rowIndex][columnIndex].noDown = true; 117 } 118 119 120 public void addNoUp(int rowIndex, int columnIndex) { map[rowIndex][columnIndex].noUp = true; 121 122 } 123 124 public void addNoLeft(int rowIndex, int columnIndex) { map[rowIndex] [columnIndex].noLeft = true; 125 } 126 127 128 public void addVerticalJump(int rowIndex, int columnIndex, int length) { map[rowIndex][columnIndex].verticalJump = length; 129 130 } 131 132 public void addNoRight(int rowIndex, int columnIndex) { map[rowIndex] [columnIndex].noRight = true; 133 } 134 135 136 137 } 138 139 140 141 } 142 143 144 Cell source = getStart(); 145 public void addHorizontalJump(int rowIndex, int columnIndex, int length) { map[rowIndex][columnIndex].horizontalJump length; public void addDelay(int rowIndex, int columnIndex, int length) { map[rowIndex][columnIndex].wait public void printSolution() { System.out.println("Shortest path of length length; II + source.shortest + : "); 146 Cell current = source; 147 while (current != null) { 148 System.out.print(current + (current.nextStep == null ? || || : "->")); 149 current = current.nextStep; 150 } 151 152 } 153 } 154
Expert Answer:
Answer rating: 100% (QA)
Given A maze map stored in a tabdelimited rectangular shape table in a txt file Objective To complete the Java program to find the shortest path for a hare to navigate through the maze from the start ... View the full answer
Related Book For
Introduction to Data Mining
ISBN: 978-0321321367
1st edition
Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar
Posted Date:
Students also viewed these programming questions
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Visit http://www.swisswireless.org/wlan_calc_en.html and go to the Antenna section. Observe the dynamics between the signal frequency, antenna diameter, and antenna gain of a parabolic antenna. 1....
-
1. Dependence of business on environment (Define) 2. Business and environment ethics (Define) 3. Ethical behaviour includes 1) 2) 3) Business and Ecological (environmental ethics)
-
(a) Objects A and B have the same mass of 3.0 kg. They melt when 3.0 104 J of heat is added to object A and when 9.0 104 J is added to object B. Determine the latent heat of fusion for the...
-
Siamak's Shoe Repairs is run by Siamak Rubaiyat in the local shopping arcade. The business prepared the following unadjusted and adjusted trial balances at 30 June 2025. Required Prepare the...
-
Suppose college students are given two options. With option A, the price a student pays for a class is always the equilibrium price. For example, if the equilibrium price to take Economics 101 is...
-
1. Given the fact that Rick has only $15,000 to invest, explain why he should consider investing in mutual funds rather than individual stocks. 2. In what type(s) of stock mutual fund(s) would you...
-
(a) X Ltd. is studying the possible acquisition of Y Ltd. by way of merger. The following data are available in respect of both the companies. Particulars Market Capitalization (Rs.) Gross Profit...
-
Consider the following string of page references 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2. Complete a figure similar to Figure 8.14, showing the frame allocation for: a. FIFO (first-in-first-out) b. LRU...
-
What are some of the challenges and benefits that cultural workers face in the current market? How have corporate and artistic practices shifted due to new technologies? Do you agree with the idea...
-
Prompt Your risk management and ethical analysis should analyze the prevalent risks associated with "Apple Inc" corporation, the challenges financial managers face in trying to attain short- and...
-
World Bridge Corporation manufactures a telecommunications device. During its first year of operations, the company started and completed 50 devices at a cost of $60,000 per unit. Of these, 48 were...
-
A company develops a new product at a cost of $400,000. It is anticipated that the product will experience high demand for a period of four years. Annual production of the product for the next four...
-
i. Measure the distance between the sources, and the path distance from each of the sources to the nodal point shown on the diagram. Show the complete calculation for wavelength. ii. Measure the path...
-
Q14. Suppose A and B are defined as follows. A = 6 -5 -3 4 -2 4 -3 3 7 B: 4 -5 -3 6 -6 -5 Compute C22 in the matrix product, C, defined as C = BA.
-
An organ pipe has two successive harmonics with frequencies 1372 and 1764 Hz. Part A Is this an open or a stopped pipe? open pipe O stopped pipe Part B What two harmonics are these? O n = 7 and n = 9...
-
The column shown in the figure is fixed at the base and free at the upper end. A compressive load P acts at the top of the column with an eccentricity e from the axis of the column. Beginning with...
-
(a) If support is defined in terms of induced subgraph relationship, show that the confidence of the rule g1 g2 can be greater than 1 if g1 and g2 are allowed to have overlapping vertex sets. (b)...
-
If the probability that a normal object is classified as an anomaly is 0.01 and the probability that an anomalous object is classified as anomalous is 0.99, then what is the false alarm rate and...
-
Clusters of documents can be summarized by finding the top terms (words) for the documents in the cluster, e.g., by taking the most frequent k terms, where k is a constant, say 10, or by taking all...
-
Which of the following is a discrete probability distribution? Approach In a discrete probability distribution, the sum of the probabilities must equal 1, and all probabilities must be between 0 and...
-
Graph the discrete probability distribution given in Table 1 from Example 2. Approach In the graph of a discrete probability distribution, the horizontal axis represents the values of the discrete...
-
Compute the mean of the discrete random variable given in Table 1 from Example 2. Approach Find the mean of a discrete random variable by multiplying each value of the random variable by its...
Study smarter with the SolutionInn App