ArcBasicDocs
2DPathfindingArcBasic extension

FindGridPath

Finds the shortest path; returns the number of steps (-1 if none).

FindGridPath ( grid,from_x,from_y,to_x,to_y )

Parameters

grid
the grid's handle.
from_x
the starting cell's column.
from_y
the starting cell's row.
to_x
the target cell's column.
to_y
the target cell's row.

Description

Finds the shortest path through a grid from one cell to another, going round walls and costly cells, and gives back how many steps it takes. Read each step's cell with GridPathX and GridPathY, from step 1, the first cell to move to, up to the last, which is the target. It gives back 0 when the two cells are the same, and -1 when there is no way through, or the target is a wall.

Moving one step and finding the path again each turn makes a chaser that follows its target wherever it goes. Paths are found with the A* method, which is quick: a path across a grid of a million cells takes a few hundredths of a second.

Example

FindGridPath.abs
steps = FindGridPath(grid, ghostX, ghostY, playerX, playerY)If steps > 0 Then    ghostX = GridPathX(1)    ghostY = GridPathY(1)EndIf

See also