I have some troubles with solving of a particular problem that is to find the shortest path in the maze graph. Probably, I'm stucked because of the fact that the maze is initialized by a four dimensional array like
adjacent = new boolean[height][width][height][width];
The first and second pair of indices specify a location in the graph in row/column formation. The graph looks like this:
XXXXXXXXXXXXX
..........X.X
X.XXX.XXX.X.X
X.X.X...X.X.X
X.X.XXX.XXX.X
X...X.....X..
XXXXXXXXXXXXX
The ArrayList must hold the locations of the vertices in the path, in order from start to end inclusive.
I've already written the constructor and connection method; however, I have trouble with the finding shortest path method. Here is the example of how I create the maze graph:
final int edges[][] = {{1, 0, 1, 1}, {1, 1, 1, 2}, {1, 1, 2, 1},
{1, 2, 1, 3}, {1, 3, 1, 4}, {1, 4, 1, 5}, {1, 5, 1, 6},
{1, 5, 2, 5}, {1, 6, 1, 7}, {1, 7, 1, 8}, {1, 8, 1, 9},
{1, 9, 2, 9}, {1, 11, 2, 11}, {2, 1, 3, 1}, {2, 5, 3, 5},
{2, 9, 3, 9}, {2, 11, 3, 11}, {3, 1, 4, 1}, {3, 3, 4, 3},
{3, 5, 3, 6}, {3, 6, 3, 7}, {3, 7, 4, 7}, {3, 11, 4, 11},
{4, 1, 5, 1}, {4, 3, 5, 3}, {4, 7, 5, 7}, {4, 11, 5, 11},
{5, 1, 5, 2}, {5, 2, 5, 3}, {5, 5, 5, 6}, {5, 6, 5, 7},
{5, 7, 5, 8}, {5, 8, 5, 9}, {5, 11, 5, 12}};
MazeGraph maze = new MazeGraph(13, 7);
for (int[] edge : edges)
maze.connect(new Location(edge[0], edge[1]), new Location(edge[2], edge[3]));