Skip to content
FutureBlitz

    Install

    Import std.algo.grid

    GridPath

    std.algo.grid

    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.

    Examples

    // A wall down the middle column, but for its bottom cell, which the path goes around by.
    Local open = Function(cell: Vec2i): Bool => cell.x != 1 || cell.y == 2
    Local path = GridPath(3, 3, Vec2i(0, 0), Vec2i(2, 0), open)
    Expect(path?.Cost == 6.0)
    Expect(path?.Nodes == [Vec2i(0, 0), Vec2i(0, 1), Vec2i(0, 2), Vec2i(1, 2), Vec2i(2, 2),
                           Vec2i(2, 1), Vec2i(2, 0)])

    std/algo/grid.fb, line 101

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