Skip to content
FutureBlitz

    Install

    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.

    std/algo/grid.fb, line 106

    • @PanicsAtCaller Public New(width: Int, height: Int, goals: Vec2i[], cost: Func(Vec2i): Double?, diagonal: Bool = False) constructor #

      A flow field over a grid of width by height to the goals, through the cells cost gives a cost for, along the axes, or diagonally too. A goal that cost gives Null for isn't one. A negative size, a goal off the grid, or a cost that's negative or NaN panics.

    • Public Property Width: Int property #

      How many cells wide its grid is.

    • Public Property Height: Int property #

      How many cells high its grid is.

    • @PanicsAtCaller Public Method Reaches(cell: Vec2i): Bool method #

      Whether the cell has a way to a goal, the goals included. A cell off the grid panics.

    • @PanicsAtCaller Public Method Distance(cell: Vec2i): Double? method #

      The cost from the cell to its nearest goal, 0 at a goal, or Null where it has no way to one. A cell off the grid panics.

    • @PanicsAtCaller Public Method Next(cell: Vec2i): Vec2i? method #

      The cell to 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.

    • @PanicsAtCaller Public Method Direction(cell: Vec2i): Vec2 method #

      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.

    std/algo/grid.fb, line 45

    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.

    std/algo/grid.fb, line 79

    Report an issue with this page or with FutureBlitz on GitHub.