I\'ve been assigned with the task of creating a maze solver in Java. Here\'s the assignment:
Write an application that finds a path through a maze.
The maze sh
I submitted a similar answer here Maze Solving Algorithm in C++.
To have a chance in solving it, you ought to:
Solve()
routine and recursively call itself:
Solve
has succeeded in finding a solutionHere's some pseudo code for the solution.
boolean solve(int X, int Y)
{
if (mazeSolved(X, Y))
{
return true;
}
// Test for (X + 1, Y)
if (canMove(X + 1, Y))
{
placeDude(X + 1, Y);
if (solve(X + 1, Y)) return true;
eraseDude(X + 1, Y);
}
// Repeat Test for (X - 1, Y), (X, Y - 1) and (X, Y + 1)
// ...
// Otherwise force a back track.
return false;
}