Given this basic assumption, each destination cell has a value of zero because each is at zero distance from a destination. All neighboring cells (not counting diagonal ones) of a destination have values of 1 because they are one cell away from a destination. Similarly, all reachable neighboring cells of cells of value 1 have values of 2 because they are two cells away from a destination.
But what if we don't know the entire configuration of the maze? This is not a problem. If you have not explored a region, we simply assume there is no wall in that region. This means the algorithm is ``greedy'', it always make the most optimistic guess when information is insufficient.
While this approach may sound silly at first, it actually is a wise one. This is because the robot will look for the shortest path using this method. The proof is fairly long and complicated, but the basic idea is as follows:
If there exists a shorter path than the taken path, the robot would have explored the shorter path to begin with. Therefore, it is not possible for the robot to first find a longer path.
This claim, however, does not guarantee that the robot will find the shortest path in the first pass. This is because the robot may be tricked to take ``short paths'', while each new mapped wall actually reveals the taken path is less than optimal. This claim only says that if there is a shorter path, the algorithm will find it.