Hi!
I started working on a Class (in AS2) which implements the AStar algorithm for pathfinding in tile-based games and stuff.
It takes a map (2D Array) as an argument and then calling the function
findPath(p1:Point, p2:Point)
it returns an array holding in order the points to follow.
It supports Horizontal/Vertical movement and Diagonal (allowed by a Boolean variable). You can also set the index in the map array from which it is counted as a non-walkeable tile.
It is now an ITERATIVE algorithm, cause it was, in some cases, exceeding the maximum level of recursion allowed. Now it WILL work with problematic map configurations posted hereā¦
It still needs some adjustements but you can check an example HERE
INSTRUCTIONS:
- Click a tile to change from walk to non-walkeable and viceversa.
- Press SPACE to switch allowDiagonal (true/false)
- It always check for the path between the top/left and bottom/right corners
- It starts now with a blank map so its easier to edit
Tell me what you think !!
PS: Heres the previous example in case you want to check it out, when it was Recursive: HERE