MATLAB: Algorithm that finds way out (global and no global view)

labyrinthmaze

A labyrinth is given as an n × n array A in which each element can be either 0 (white) or 1 (black). A knight in the labyrinth is at an initial position ( i,j ) which is given. The numbers i,j satisfy 1 < i < n , 1 < j < n , n > 4. The knight may move to a neighbouring cell ( i ± 1, j ) or ( i, j ± 1 ) if such a cell is open (white). The knight is out once he has reached a cell on the boundary, see Figure 1 below.
I have to write a code that determines the minimum length of this path. If the path does not exist this length should be 0.
How to write an algorithm that finds a way out (if possible). Assuming that the knight can look globally at his labyrinth (which is of course not true in real life) And what is the strategy if the knight does not have a global view?
You create an array, for example 10×10 consisting of only 1 and 0's. Matlab has to search for all the zeros, because then he will found a way out.
I hope someone can help me with this problem, I really have no idea how to begin, since I am a real beginner.

Best Answer

Figure 1 was not attached.
MATLAB has functions shortestpath() and bwdistgeodesic() which can solve mazes. You can write a wrapper around those.
Related Question