Import std.algo.grid
std.algo.grid
Searches on grids of cells, each a Vec2i from (0, 0) to (width - 1, height - 1): the cells next to one, the path between two by A*, and flow fields, which give every cell its way to the nearest goal at once, for many agents going to the same places. A step goes along an axis, or diagonally too, which costs the square root of 2 times as much and doesn't cut a corner a wall is on.
std/algo/grid.fb
Types
FlowField
class
Public Class FlowField
A flow field over a grid: each cell's cheapest way to the nearest of its goals, worked out once from the goals outward, so any number of agents follow it with no search of their own. Entering a cell costs what cost gives for it, and a cell it gives Null for is a wall that no path goes through; a step along an axis costs that, and a diagonal one the square root of 2 times it.
-
@PanicsAtCaller Public New(width: Int, height: Int, goals: Vec2i[], cost: Func(Vec2i): Double?, diagonal: Bool = False)constructor #A flow field over a grid of
widthbyheightto thegoals, through the cellscostgives a cost for, along the axes, or diagonally too. A goal thatcostgives Null for isn't one. A negative size, a goal off the grid, or a cost that's negative or NaN panics. -
How many cells wide its grid is.
-
How many cells high its grid is.
-
Whether the
cellhas a way to a goal, the goals included. A cell off the grid panics. -
The cost from the
cellto its nearest goal, 0 at a goal, or Null where it has no way to one. A cell off the grid panics. -
The
cellto step to from this one on its cheapest way to a goal, or Null at a goal or where there's no way to one. A cell off the grid panics. -
Which way to go from the
cell, of length 1, toward its next cell: the zero vector at a goal or where there's no way to one. A cell off the grid panics.
Functions
GridNeighbors
function
@PanicsAtCaller Public Function GridNeighbors(width: Int, height: Int, cell: Vec2i, diagonal: Bool = False): Vec2i[]
The cells next to cell on a grid of width by height, those on it only: the four along the
axes, right, down, left, and up, then, when diagonal, the four corners. A negative size, or a
cell off the grid, panics.
GridPath
function
@PanicsAtCaller Public Function GridPath(width: Int, height: Int, start: Vec2i, goal: Vec2i, passable: Func(Vec2i): Bool, diagonal: Bool = False): Path<Vec2i, Double>?
The path across a grid of width by height from start to goal, by A*, through the cells
passable says can be walked, with steps along the axes, or diagonal ones too when diagonal,
and its cost: a step along an axis is 1, and a diagonal one the square root of 2. The start
needn't be a cell passable says can be walked; Null when the goal can't be reached. A
start or goal off the grid panics.
Report an issue with this page or with FutureBlitz on GitHub.