A* poathfinding

Blitz3D Forums/Blitz3D Programming/A* poathfinding

slenkar(Posted 2005) [#1]
Im using A* and it works fine but I need to penalize nodes that involve a change of direction,
has anyone done this?


3D(Posted 2005) [#2]
Is the A* code what you have written.
And i am not to sure what you mean.
Can you clarify a bit


WolRon(Posted 2005) [#3]
You will probably have to write your own version of A* then, I suppose.


Robert(Posted 2005) [#4]
Hi Slenkar,

I had to do this for a project recently, my implementation only allows 90-degree turns (no diagonals), but I hope this is still helpful:

What I did is to have an integer variable which stores the current direction (0 for across, 1 for down).

In each iteration of the main A* loop, you reassign the current node to which ever one on the open list has the lowest f score (gone + heuristic). Just before I reassign the current node, I store a reference to the previous 'current' node in another variable.

After setting the new 'current' node, I compare the co-ordinates of the 'previous' and 'current' nodes. If their x-coordinates are the same, that means that we are going down, if their y-coordinates are the same, that means that we are going across.

When looking at each of the nodes adjacent to the current node, I look at the direction from the 'current' node to the adjacent node. If the direction is the same (ie. the direction from the previous to the current node is the same as from the current node to the adjacent one), I set the 'gone' cost of the adjacent node to 1, if the direction is different, I set the 'gone' cost of the adjacent node to 2.


slenkar(Posted 2005) [#5]
thanks robert thats the kind of thing I needed