ModDB Wiki
ModDB Wiki

Template:Rewrite

If you create a game with pathfinding(RTS game, Adventure, RPG or sometimes boardgames), then you need to know a algorithm.
Pathfinding algorithms are different: If you make a game with tiles you can use a accurate algorithm what can examine all tiles. But a continous game environment need a quicklier algorithm. Here is the A* algorithm, remember don't grow angry if it doesn't work. It's pseudo code you know.
I've converted this code to qbasic and it works (in a textbased environment with a size of 80x50 tiles, but very quick.)

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.,