I am working on a Maze Solver, but I encounted an ArrayOutOfBoundsException on this line:
wasHere[row][col] = false;
I don't see how there could possibly be such error, since the width and height (number of rows and columns) as represented in the maze, wasHere, and correctPath are all the same. All arrays show 7 columns and 4 rows.
private static int[][] maze = {{2, 2, 2, 2, 1, 2, 2}, {2, 2, 2, 2, 1, 2, 2},
{2, 2, 2, 2, 1, 2, 2}, {2, 1, 1, 1, 1, 2, 2}}; // The maze
private static boolean[][] wasHere = new boolean[7][4];
private static boolean[][] correctPath = new boolean[7][4]; // Solution
for (int row = 0; row < maze.length; row++)
{
// Sets boolean arrays to false
for (int col = 0; col < maze[row].length; col++)
{
wasHere[row][col] = false;
correctPath[row][col] = false;
}
}
Aucun commentaire:
Enregistrer un commentaire