0

I need pathfinding in a project with only 4 directions. So I looked at the A* algorythm, and I tried to draw something to understand how it's going to work.

But I noticed that there are multiple paths that are the 'same' to get to my endpoint, my question is: How is the algorythm going to choose between all these paths that cost the same, and Isn't there a way to modify this algorythm to optimize it specifically for 4 directions and no diagonals?

Here's a little drawing of the result: enter image description here

EDIT: basically what I think may suit my implementation, is to add a T value to each node which will represent the number of 'turns' needed from the starting node. With this, when checking adjacent nodes, if some of them have the same F value, move to the node with the lowest T value.

EDIT2: well it's a little trickier than that It might work if I assign a higher value for each turn and then calculate F = G + H + T

user3813360
  • 566
  • 9
  • 25
  • Do you prefer a specific one of these paths? – harold Sep 17 '17 at 09:05
  • well, It'd be better if the path was the straightest. – user3813360 Sep 17 '17 at 09:09
  • 1
    Possible duplicate of [Efficient Path finding algorithm avoiding zigzag's](https://stackoverflow.com/questions/26302126/efficient-path-finding-algorithm-avoiding-zigzags) – Progman Sep 17 '17 at 09:17
  • what do you assume to be "straightest" on a grid? The path with the least amount of turns or the path closest to the diagonal? – tofro Sep 17 '17 at 09:53
  • @tofro The path with the least amount of turns. – user3813360 Sep 17 '17 at 09:54
  • Note that if you do add a #turns, the coordinates of a node have to be extended with a direction otherwise nodes with equal (x,y) would be merged but paths that go through (x,y) in different directions are fundamentally different once you count turns. – harold Sep 17 '17 at 12:39

0 Answers0