grid.jamo (built in)

grid: a 2D board of any type, for tile maps, mazes, puzzles and board games. use "grid.jamo"

Grid<T> holds width * height cells, each a T. Places count from 0, with x going right and y going down, and the cells are kept row by row in one array. Going outside the grid stops with an error that says its size, so use inside() or get_or() when a place might be off the edge.

structGrid

struct Grid<T>
    width: int
    height: int
    cells: [T]
end

structCell

struct Cell
    x: int
    y: int
end

A place on a grid

funcnew_grid

func new_grid<T>(width: int, height: int, fill: T): Grid<T>

funcGrid.inside

func Grid<T>.inside(x: int, y: int): bool

funcGrid.place

func Grid<T>.place(x: int, y: int): int

funcGrid.get

func Grid<T>.get(x: int, y: int): T

funcGrid.set

func Grid<T>.set(x: int, y: int, value: T)

funcGrid.get_or

func Grid<T>.get_or(x: int, y: int, fallback: T): T

The cell's value, or fallback when the place is off the grid

funcGrid.fill

func Grid<T>.fill(value: T)

funcGrid.count

func Grid<T>.count(value: T): int

How many cells hold this value. T must work with ==, like ints, strings, bools and enums

funcGrid.copy

func Grid<T>.copy(): Grid<T>

A new grid with the same cells. Structs and arrays in it are shared, like any assignment

funcGrid.neighbours

func Grid<T>.neighbours(x: int, y: int, diagonals: bool): [Cell]

The places next to (x, y) that are on the grid: up, right, down and left, and with diagonals the four corners after them