I'm having trouble getting the functions H and G to function properly. What happens when I run a program, it sometimes finds a better way and sometimes it goes out of the way to get to the place.
Here are some screenshots of what is happening:
Good way finding
Poor path finding
This is my current setup for F, H, and G:
public double f(Node current, Node adj, Node goal)
{
double f = g(current, adj) + h(current, goal);
return f;
}
public double h(Node current, Node goal)
{
double dx = goal.getX() - current.getX();
double dy = goal.getY() - current.getY();
double h = Math.sqrt(dx*dx + dy*dy);
return h;
}
public double g(Node current, Node adj)
{
double dx = adj.getX() - current.getX();
double dy = adj.getY() - current.getY();
double g = Math.sqrt(Math.abs(dx) + Math.abs(dy));
System.out.println("g " + g);
return g;
}
Thank!
source
share