Basic Shortest Path algorithm

To conclude with this introductory lesson to maze solving algorithms, we will investigate another way to find the exit. The buggle in this lesson is a special buggle: he is a jedi. He can feel the Force. This means he is able to feel his environment.

Without even leaving his position, he can retrieve information about the world he is leaving in, with the following functions:

It has to be noted that it is not possible to build a wall on the bottom edge or on the right edge of a cell. Therefore when such wall exists, it means it was built on a sibling cells -- as a top (respectively left) wall on the cell that is located below (respectively at the right of) the current cell.

Traguardo dell'esercizio

Your buggle should first write the distance to the exit on each cell (or at least the useful ones).
For that, find the exit and write 0 there. Then, write 1 on every neighboring cells that is not separated from the exit with a wall. And then mark every cells from which you can reach the exit in 2 steps, and iterate for all cells until all cells are marked.

Once the cells are marked, get your jedi buggle to follow the shortest path. Basically the buggle has only to walk on each case with the lesser distance from the exit. You can use the method setDirection(direction) to make your buggle look at the specific direction such as [!scala|java|python]Direction.[/!]NORTH or [!scala|java|python]Direction.[/!]EAST.

Use the Force, Luke!