Portability | portable |
---|---|

Stability | experimental |

Maintainer | amy@nualeargais.ie |

Safe Haskell | Safe-Inferred |

A module containing private `Grid`

internals. Most developers should
use `Grid`

instead. This module is subject to change without notice.

- class Grid g where
- type Index g
- indices :: g -> [Index g]
- distance :: g -> Index g -> Index g -> Int
- minDistance :: g -> [Index g] -> Index g -> Int
- neighbours :: g -> Index g -> [Index g]
- numNeighbours :: g -> Index g -> Int
- contains :: Eq (Index g) => g -> Index g -> Bool
- viewpoint :: g -> Index g -> [(Index g, Int)]
- tileCount :: g -> Int
- null :: g -> Bool
- nonNull :: g -> Bool
- edges :: Eq (Index g) => g -> [(Index g, Index g)]
- isAdjacent :: Eq (Index g) => g -> Index g -> Index g -> Bool
- adjacentTilesToward :: g -> Index g -> Index g -> [Index g]
- minimalPaths :: Eq (Index g) => g -> Index g -> Index g -> [[Index g]]

- class Grid g => FiniteGrid g where
- class Grid g => BoundedGrid g where
- class Grid g => WrappedGrid g where
- data UnboundedTriGrid
- data TriTriGrid
- triTriGrid :: Int -> TriTriGrid
- data ParaTriGrid
- paraTriGrid :: Int -> Int -> ParaTriGrid
- data RectTriGrid
- rectTriGrid :: Int -> Int -> RectTriGrid
- data TorTriGrid
- torTriGrid :: Int -> Int -> TorTriGrid
- data UnboundedSquareGrid
- data RectSquareGrid
- rectSquareGrid :: Int -> Int -> RectSquareGrid
- data TorSquareGrid
- torSquareGrid :: Int -> Int -> TorSquareGrid
- data UnboundedHexGrid
- data HexHexGrid
- hexHexGrid :: Int -> HexHexGrid
- data ParaHexGrid
- paraHexGrid :: Int -> Int -> ParaHexGrid

# Generic

A regular arrangement of tiles.
Minimal complete definition: `indices`

and `distance`

.

indices :: g -> [Index g]Source

Returns the indices of all tiles in a grid.

distance :: g -> Index g -> Index g -> IntSource

returns the minimum number of moves required
to get from the tile at index `distance`

g a b`a`

to the tile at index `b`

in
grid `g`

, moving between adjacent tiles at each step. (Two tiles
are adjacent if they share an edge.) If `a`

or `b`

are not
contained within `g`

, the result is undefined.

minDistance :: g -> [Index g] -> Index g -> IntSource

returns the minimum number of moves
required to get from any of the tiles at indices `minDistance`

g bs a`bs`

to the tile
at index `a`

in grid `g`

, moving between adjacent tiles at each
step. (Two tiles are adjacent if they share an edge.) If `a`

or
any of `bs`

are not contained within `g`

, the result is
undefined.

neighbours :: g -> Index g -> [Index g]Source

returns the indices of the tiles in the grid
`neighbours`

g x`g`

which are adjacent to the tile with index `x`

.

numNeighbours :: g -> Index g -> IntSource

returns the number of tiles in the grid
`numNeighbours`

g x`g`

which are adjacent to the tile with index `x`

.

contains :: Eq (Index g) => g -> Index g -> BoolSource

`g `'contains'` x`

returns `True`

if the index `x`

is contained
within the grid `g`

, otherwise it returns false.

viewpoint :: g -> Index g -> [(Index g, Int)]Source

returns a list of pairs associating the index
of each tile in `viewpoint`

g x`g`

with its distance to the tile with index `x`

.
If `x`

is not contained within `g`

, the result is undefined.

Returns the number of tiles in a grid. Compare with

.
`size`

Returns `True`

if the number of tiles in a grid is zero, `False`

otherwise.

Returns `False`

if the number of tiles in a grid is zero, `True`

otherwise.

edges :: Eq (Index g) => g -> [(Index g, Index g)]Source

A list of all edges in a grid, where the edges are represented by a pair of indices of adjacent tiles.

isAdjacent :: Eq (Index g) => g -> Index g -> Index g -> BoolSource

returns `isAdjacent`

g a b`True`

if the tile at index `a`

is
adjacent to the tile at index `b`

in `g`

. (Two tiles are adjacent
if they share an edge.) If `a`

or `b`

are not contained within
`g`

, the result is undefined.

adjacentTilesToward :: g -> Index g -> Index g -> [Index g]Source

returns the indices of all tiles
which are neighbours of the tile at index `adjacentTilesToward`

g a b`a`

, and which are
closer to the tile at `b`

than `a`

is. In other words, it returns
the possible next steps on a minimal path from `a`

to `b`

. If `a`

or `b`

are not contained within `g`

, or if there is no path from
`a`

to `b`

(e.g., a disconnected grid), the result is undefined.

minimalPaths :: Eq (Index g) => g -> Index g -> Index g -> [[Index g]]Source

returns a list of all minimal paths from
the tile at index `minimalPaths`

g a b`a`

to the tile at index `b`

in grid `g`

. A
path is a sequence of tiles where each tile in the sequence is
adjacent to the previous one. (Two tiles are adjacent if they
share an edge.) If `a`

or `b`

are not contained within `g`

, the
result is undefined.

Tip: The default implementation of this function calls

. If you want to use a custom algorithm,
consider modifying `adjacentTilesToward`

instead of
`adjacentTilesToward`

.
`minimalPaths`

class Grid g => FiniteGrid g whereSource

A regular arrangement of tiles where the number of tiles is finite.
Minimal complete definition: `size`

.

class Grid g => BoundedGrid g whereSource

A regular arrangement of tiles with an edge.
Minimal complete definition: `tileSideCount`

.

tileSideCount :: g -> IntSource

Returns the number of sides a tile has

boundary :: g -> [Index g]Source

Returns a the indices of all the tiles at the boundary of a grid.

isBoundary :: Eq (Index g) => g -> Index g -> BoolSource

' returns `isBoundary`

g x`True`

if the tile with index `x`

is
on a boundary of `g`

, `False`

otherwise. (Corner tiles are also
boundary tiles.)

centre :: g -> [Index g]Source

Returns the index of the tile(s) that require the maximum number of moves to reach the nearest boundary tile. A grid may have more than one central tile (e.g., a rectangular grid with an even number of rows and columns will have four central tiles).

isCentre :: Eq (Index g) => g -> Index g -> BoolSource

' returns `isCentre`

g x`True`

if the tile with index `x`

is
a centre tile of `g`

, `False`

otherwise.

class Grid g => WrappedGrid g whereSource

# Grids with triangular tiles

data TriTriGrid Source

A triangular grid with triangular tiles. The grid and its indexing scheme are illustrated in the user guide, available at https://github.com/mhwombat/grid/wiki.

triTriGrid :: Int -> TriTriGridSource

returns a triangular grid with sides of
length `triTriGrid`

s`s`

, using triangular tiles. If `s`

is nonnegative, the
resulting grid will have `s^2`

tiles. Otherwise, the resulting grid
will be null and the list of indices will be null.

data ParaTriGrid Source

A Parallelogrammatical grid with triangular tiles. The grid and its indexing scheme are illustrated in the user guide, available at https://github.com/mhwombat/grid/wiki.

paraTriGrid :: Int -> Int -> ParaTriGridSource

returns a grid in the shape of a
parallelogram with `paraTriGrid`

r c`r`

rows and `c`

columns, using triangular
tiles. If `r`

and `c`

are both nonnegative, the resulting grid will
have `2*r*c`

tiles. Otherwise, the resulting grid will be null and
the list of indices will be null.

data RectTriGrid Source

A rectangular grid with triangular tiles. The grid and its indexing scheme are illustrated in the user guide, available at https://github.com/mhwombat/grid/wiki.

rectTriGrid :: Int -> Int -> RectTriGridSource

returns a grid in the shape of a
rectangle (with jagged edges) that has `rectTriGrid`

r c`r`

rows and `c`

columns,
using triangular tiles. If `r`

and `c`

are both nonnegative, the
resulting grid will have `2*r*c`

tiles. Otherwise, the resulting grid will be null and
the list of indices will be null.

data TorTriGrid Source

A toroidal grid with triangular tiles. The grid and its indexing scheme are illustrated in the user guide, available at https://github.com/mhwombat/grid/wiki.

torTriGrid :: Int -> Int -> TorTriGridSource

returns a toroidal grid with `torTriGrid`

r c`r`

rows and `c`

columns, using triangular tiles. If `r`

is odd, the result is
undefined because the grid edges would overlap. If `r`

and `c`

are both nonnegative, the resulting grid will have `2*r*c`

tiles.
Otherwise, the resulting grid will be null and the list of indices
will be null.

# Grids with square tiles

data RectSquareGrid Source

A rectangular grid with square tiles. The grid and its indexing scheme are illustrated in the user guide, available at https://github.com/mhwombat/grid/wiki.

rectSquareGrid :: Int -> Int -> RectSquareGridSource

produces a rectangular grid with `rectSquareGrid`

r c`r`

rows
and `c`

columns, using square tiles. If `r`

and `c`

are both
nonnegative, the resulting grid will have `r*c`

tiles. Otherwise,
the resulting grid will be null and the list of indices will be
null.

data TorSquareGrid Source

A toroidal grid with square tiles. The grid and its indexing scheme are illustrated in the user guide, available at https://github.com/mhwombat/grid/wiki.

torSquareGrid :: Int -> Int -> TorSquareGridSource

returns a toroidal grid with `torSquareGrid`

r c`r`

rows and `c`

columns, using square tiles. If `r`

and `c`

are
both nonnegative, the resulting grid will have `r*c`

tiles. Otherwise,
the resulting grid will be null and the list of indices will be null.

# Grids with hexagonal tiles

data HexHexGrid Source

A hexagonal grid with hexagonal tiles The grid and its indexing scheme are illustrated in the user guide, available at https://github.com/mhwombat/grid/wiki.

hexHexGrid :: Int -> HexHexGridSource

returns a grid of hexagonal shape, with
sides of length `hexHexGrid`

s`s`

, using hexagonal tiles. If `s`

is nonnegative, the
resulting grid will have `3*s*(s-1) + 1`

tiles. Otherwise, the resulting
grid will be null and the list of indices will be null.

data ParaHexGrid Source

A parallelogramatical grid with hexagonal tiles The grid and its indexing scheme are illustrated in the user guide, available at https://github.com/mhwombat/grid/wiki.

paraHexGrid :: Int -> Int -> ParaHexGridSource

returns a grid in the shape of a
parallelogram with `paraHexGrid`

r c`r`

rows and `c`

columns, using hexagonal tiles. If
`r`

and `c`

are both nonnegative, the resulting grid will have `r*c`

tiles.
Otherwise, the resulting grid will be null and the list of indices will
be null.