Out of ideas for optimizing A* search, got any?

Started by
23 comments, last by ferrous 6 years, 7 months ago
On 9/19/2017 at 4:26 PM, ntroPi said:

Creating an "8 direction manhattan style estimate" between two points should be no big deal. (dist = min(xDiff, yDiff) * sqrt(2) + abs(xDiff - yDiff))

This can't be right, xDiff=0, yDiff=-200 gives a path -200 * sqrt(2) + 200 is about -200 * 0.4

Advertisement

I should have written explicitly, that the diffs are supposed to be absolute values. Wanted to keep it short, as it is only a minor point of my post.


Manhattan_8(Point P1, Point P2)
{
	xDiff = abs(P1.x - P2.x);
	yDiff = abs(P1.y - P2.y);
	return min(xDiff, yDiff) * sqrt(2) + abs(xDiff - yDiff);
}

So it would come out to xDiff = 0, yDiff = 200 in your example, which gives the expected result (200).

Thx for the feedback :-)

Thanks for the discussions, they've gone towards improvements in my code and understanding of pathfinding.  Now I am having problems with local avoidance but that's a problem for another thread :)

What does your GridNode look like?  You might try to shrink it down as much as possible.  You might even get a benefit from pulling out the visited index to its own array.

GetNeighbors, is that doing a copy?  That could potentially be doing some goofiness.

You also have a minor potential bug, as you never check for overflow in your searchindex.  (Shouldn't happen that often, but it's not a tough fix.)

 

I'm also curious if rewriting the whole thing in C++ and importing that into Unity would be faster still.

This topic is closed to new replies.

Advertisement