Cauldron2D.Grid.Path (Cauldron2D v0.1.3)

Copy Markdown View Source

Ways across a tile grid: breadth-first for the fewest steps, A* for the cheapest.

{:ok, path} = Cauldron2D.Grid.Path.find(&open?/1, {0, 0}, {5, 2}, size: {6, 5})
{:ok, path} = Cauldron2D.Grid.Path.astar(&open?/1, {0, 0}, {5, 2}, size: {6, 5}, cost: &terrain/1)

The grid is a function from a cell {x, y} to whether it can be walked. A path is the cells from the first step to the goal, the start left out; the same cell as start and goal is []. :none is no way within the limit.

Options

  • :size{width, height} of the grid in cells. Required
  • :wrap? — whether the edges join. Default false
  • :neighbours:four or :eight. Default :four
  • :limit — how many cells may be expanded before giving up. Default 10_000
  • :costastar/4 only: a function from a cell to the cost of stepping into it, a positive number. Default 1 everywhere

Summary

Functions

The cheapest way, by :cost, guided by the distance still to go.

The way with the fewest steps.

Types

cell()

@type cell() :: {integer(), integer()}

passable()

@type passable() :: (cell() -> boolean())

Functions

astar(passable?, from, to, opts)

@spec astar(passable(), cell(), cell(), keyword()) :: {:ok, [cell()]} | :none

The cheapest way, by :cost, guided by the distance still to go.

find(passable?, from, to, opts)

@spec find(passable(), cell(), cell(), keyword()) :: {:ok, [cell()]} | :none

The way with the fewest steps.