Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A* manhattan distance

I searched for the algorithm/pseudocode of A* I followed it and coded it. I used Manhattan distance for h(n). ( f(n) = g(n) + h(n) ) And this is the result,

This always happen when there are no walls blocking the way, but when I put a lot of walls, it seems that it's taking the shortest path. Is this one the shortest path? I mean why is it not like this one below?

This one is also A* Manhattan, and they have the same size (19x19). This is from http://qiao.github.com/PathFinding.js/visual/

like image 474
Zik Avatar asked Jun 15 '12 07:06

Zik


1 Answers

Both paths have the same manhattan distance. Therefore, it is implementation dependant which path is chosen. To tell why this specific part was chosen, we would have to look at the code of this specific A* implementation.

Hint: Every path from a source to a target cell that uses only Von Neumann neighborhood(i.e., does not walk diagonally) and does not take a step into the "wrong" direction (i.e., never walks up or left in your example) has the same manhattan distance. So, if you are in New York, it doesn't matter which crossroads you take to reach a certain place in Manhattan :)

like image 108
gexicide Avatar answered Sep 28 '22 05:09

gexicide