Path finder

Find paths through 2D mazes.

File:
PathFinder.lib
Version:
1.0
Author:
John Master

Contents

Details
Constants
Sub routines


Details

With this library you can find the closest path between two points in a discrete map.


Constants

Directions

Name
Description
PF_DOWN
Down.
PF_UP
Up.
PF_LEFT
Left.
PF_RIGHT
Right.


Subroutines

Name
Parameters
Brief description
procedure
SetMaxPathSteps
steps
Set max number of steps to be generated.
function
FindPath[][]
&map[][], srcX, srcY, dstX, dstY
Return path.
function
GetStepDirection
&path[][], step
Return step direction.


Subroutine documentation

procedure SetMaxPathSteps ( steps )

Set the maximum number of steps that may be produced while walking between the two points. If more steps are required, the algorithm will abort, telling the caller that no path could be found. The default value is 128 steps.

Parameter
Mode
Description
steps
In
Max number of steps.

[ Back ]


function FindPath[][] ( &map[][], srcX, srcY, dstX, dstY )

Return path between '(srxX, srcY)' and '(dstX, dstY') in 'map' as a 2D integer array. The array will have the form [step][x, y], where either 'x' or 'y' changes between 'step' and 'step' + 1. Anything but 0 in 'map' is treated as an obstacle.

Parameter
Mode
Description
map
In
Map where first dimension represents x and second y.
srcX
In
Source x-coordinate.
srcY
In
Source x-coordinate.
dstX
In
Destination x-coordinate.
dstY
In
Destination y-coordinate.

Return value
Path between the two points or an empty array if no path was found.

[ Back ]


function GetStepDirection ( &path[][], step )

Return the direction in path returned from 'FindPath' between 'step' and 'step' + 1. The function will return 'PF_DOWN', 'PF_UP', 'PF_LEFT' or 'PF_RIGHT', or 0 on error.

Parameter
Mode
Description
path
In
Path returned from 'FindPath'.
step
In
Step to examine.

Return value
Direction between 'step' and 'step' + 1.

[ Back ]


Generated with NLDoc 20140630.