My next solution to the problem
was to try to implement different metrics along with the variation for
the Rapidly Exploring Random Tree in order to reach the goal.
The first metric I chose was to pick five points at random. Then I would check to see which point was closest to the goal. I would choose that point and then use that point to pick the next 5 random points. This metric only worked for very simple examples. It would get caught in local minimums. The following picture shows an example of this.
It was very difficult to
try to come up with an algorithm that would allow the worm to come out
of the local minimum. The worm could not turn over 90 degrees on either
side otherwise it would run into itself. Since the biggest difficulty was
getting the worm out away from the obstacle. The next thing I tried
was to calculate the distance the worm was from the obstacles. If the distance
was less than so many units (15) and the goal was not close by (more than
20 units away) then that point would not be selected even if it was the
closest to the goal.
This improved the performance of the program, but the program still did not work for all cases. This method just basically increased the area of the local minimum.
Other things that I tried that did not solve the problem was implementing a random walk for 30 steps when the worm was stuck in a local minimum. Again the problem was the worm being too close to the obstacles to be able to get far enough away from the local minimum.
The final method that I implemented was when the worm was only 15 units away from an obstacle in the x direction, I would have it move to the left 90 degrees (so that it would go up), and if the worm was only 15 units away from an in the y direction, I would have it move to the right 90 degrees. This solved some of the local minimum problems.
Second Example (has three apples)
Third Example This example
shows how the worm follows the edge of the obstacle to escape the local
minimum. When the worm is going from apple 1 to apple 2.