Pathfinding
From GPWiki
The wiki is now hosted by GameDev.NET at wiki.gamedev.net. All gpwiki.org content has been moved to the new server. However, the GPWiki forums are still active! Come say hello. If you create a game with pathfinding(RTS game, Adventure, RPG or sometimes boardgames), then you need to know a algorithm. class PSEUDO_CODE_PATHFINDING_IN*A { int list(XSiz,YSiz) ;Declare the tile-list contains the information, if a tile is open,closed,or not examined. int fromX,fromY(XSiz,YSiz); array that stores the parent tile position of the current tile in it int Yx,Yy ;Your position int Tx,Ty ;Targets position int map(XSiz,YSiz);Declare the map-array contains information about the map (unpassable,open terrain etc.) int pathx(length_path) int pathy(length_path) repeat for(x 1 to XSiz) for(y 1 to YSiz) if list x ,y is open then check all adjacent tiles if adjacent tile is not examined and map x,y is open too then that tile is open set the position of the parent_tile in array fromXY if xy = txy then end the loop next y next x until Target_pos_reached function createpath(x1,y1,x2,y2) repeat pathx(count)=x pathy(count)=y x2=fromx(x2,y2) y2=fromy(x2,y2) count++ until x=x2,y=y2 } Tadaa! Here is your path, if it is converted correctly., |


