-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|593|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Snippet Home -> AI and Movement


 
HoboBen
Created : 07 March 2010
Edited : 09 March 2010
Language : Cobra

A* Path finding - Cobra



wikipedia had a great bit of psuedo code for A* Pathfinding, I quickly translated it into cobra:

Required file: (save as map.png)





Colour-coded source code + screenshot


Edit: This is just a simple example - solutions near to best-case are very fast but for a worst-case solution it may prove too slow for real-time so you should combine it with specific optimisations that suit your modelled environment. For example, an in-door map will benefit if you link up all doors or exits to a node map, build a list of doors to pass through, and use A* path-finding to find the path from door-to-door.

Edit 2: Compiled example.

 

Comments