![]() |
The modified flood-fill algorithm The modified flood-fill algorithm is similar to the regular flood-fill algorithm in that the mouse uses distance values to move about the maze. The distance values, wich represent how far the mouse is from the destination cell, are followed in decending order until the mouse reaches its goal.
As the MicroMouse finds new walls during its exploration, the distance values need to be updated. Instead of flooding the entire maze with values, as is the case with the regular flood-fill, the modified flood-fill only changes those values which need to be changed. Let's say our mouse moves forward one cell and discovers a wall:
The robot cannot go West and it cannot go East, it can only travel North or South. But going North or South means going up in distance values which we do not want to do. So the cell values need to be updated. When we encounter this, we follow this rule:
In the example above, the minimum value of its open neighbors is 3. Adding 1 to this value results in 3 + 1 = 4. The maze now looks like this:
There are times when updating a cell's value will cause its neighbors to violate the "1 + minimum value" rule and so they must be checked as well. We can see in our example above that the cells to the North and to the South have neighbors whose minimum value is 2. Adding a 1 to this value results in 2 + 1 = 3 therefore the cells to the North and to the South do not violate the rule and the updating routine is done. Now that the cell values have been updated, the mouse can once again follow the distance values in decending order. So our modified flood-fill procedure for updating the distance values is:
Summary: Most of the time, the modified flood-fill is faster than the regular flood-fill. By updating only those values which need to be updated, the mouse can make its next move much quicker. Every time it arrives in a cell, have the mouse:
|