Portability | portable |
---|---|
Stability | experimental |
Maintainer | amy@nualeargais.ie |
Safe Haskell | Safe-Infered |
A regular arrangement of tiles. Grids have a variety of uses, including games and self-organising maps.
- class Eq x => Grid g s x | g -> s, g -> x where
- data TriTriGrid
- triTriGrid :: Int -> TriTriGrid
- data ParaTriGrid
- paraTriGrid :: Int -> Int -> ParaTriGrid
- data RectSquareGrid
- rectSquareGrid :: Int -> Int -> RectSquareGrid
- data TorSquareGrid
- torSquareGrid :: Int -> Int -> TorSquareGrid
- data HexHexGrid
- hexHexGrid :: Int -> HexHexGrid
- data ParaHexGrid
- paraHexGrid :: Int -> Int -> ParaHexGrid
The Grid class
class Eq x => Grid g s x | g -> s, g -> x whereSource
A regular arrangement of tiles.
Minimal complete definition: indices
, distance
, and size
.
Returns the indices of all tiles in a grid.
distance :: x -> x -> g -> IntSource
returns the minimum number of moves required to get from
distance
a ba
to b
, 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.
Returns the dimensions of the grid.
For example, if g
is a 4x3 rectangular grid,
would return
size
g(4, 3)
, while
would return tileCount
g12
.
neighbours :: x -> g -> [x]Source
returns the indices of the tiles in the grid neighbours
x gg
which are adjacent to the tile at x
.
inGrid :: x -> g -> BoolSource
x `'inGrid'` g
returns true if the index x
is contained within g
,
otherwise it returns false.
viewpoint :: x -> g -> [(x, Int)]Source
returns a list of pairs associating the index of each
tile in viewpoint
x gg
with its distance to the tile with index x
. If x
is not
contained within g
, the result is undefined.
tileCount :: Grid g s x => g -> IntSource
Returns the number of tiles in a grid. Compare with
.
size
empty :: Grid g s x => g -> BoolSource
Returns True
if the number of tiles in a grid is zero, False
otherwise.
nonEmpty :: Grid g s x => g -> BoolSource
Returns False
if the number of tiles in a grid is zero, True
otherwise.
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.commhwombatgrid/wiki.
triTriGrid :: Int -> TriTriGridSource
returns a triangular grid with sides of
length triTriGrid
ss
, using triangular tiles. If s
is nonnegative, the resulting
grid will have s^2
tiles. Otherwise, the resulting grid will be empty
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.commhwombatgrid/wiki.
Show ParaTriGrid | |
Grid ParaTriGrid (Int, Int) (Int, Int) |
paraTriGrid :: Int -> Int -> ParaTriGridSource
returns a grid in the shape of a
parallelogram with paraTriGrid
r cr
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 empty 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.commhwombatgrid/wiki.
Show RectSquareGrid | |
Grid RectSquareGrid (Int, Int) (Int, Int) |
rectSquareGrid :: Int -> Int -> RectSquareGridSource
produces a rectangular grid with rectSquareGrid
r cr
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 empty 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.commhwombatgrid/wiki.
Show TorSquareGrid | |
Grid TorSquareGrid (Int, Int) (Int, Int) |
torSquareGrid :: Int -> Int -> TorSquareGridSource
returns a toroidal grid with torSquareGrid
r cr
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 empty 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.commhwombatgrid/wiki.
hexHexGrid :: Int -> HexHexGridSource
returns a grid of hexagonal shape, with
-- sides of length hexHexGrid
ss
, using hexagonal tiles. If s
is nonnegative, the
resulting grid will have 3*s*(s-1) + 1
tiles. Otherwise, the resulting
grid will be empty 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.commhwombatgrid/wiki.
Show ParaHexGrid | |
Grid ParaHexGrid (Int, Int) (Int, Int) |
paraHexGrid :: Int -> Int -> ParaHexGridSource
returns a grid in the shape of a
parallelogram with paraHexGrid
r cr
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 empty and the list of indices will
be null.
Example
Create a grid.
ghci> let g = hexHexGrid 3 ghci> indices g [(-2,0),(-2,1),(-2,2),(-1,-1),(-1,0),(-1,1),(-1,2),(0,-2),(0,-1),(0,0),(0,1),(0,2),(1,-2),(1,-1),(1,0),(1,1),(2,-2),(2,-1),(2,0)]
Find out the minimum number of moves to go from one tile in a grid to another tile, moving between adjacent tiles at each step.
ghci> distance (0,-2) (0,2) g 4
Find out the minimum number of moves to go from one tile in a grid to any other tile, moving between adjacent tiles at each step.
ghci> viewpoint (1,-2) g [((-2,0),3),((-2,1),3),((-2,2),4),((-1,-1),2),((-1,0),2),((-1,1),3),((-1,2),4),((0,-2),1),((0,-1),1),((0,0),2),((0,1),3),((0,2),4),((1,-2),0),((1,-1),1),((1,0),2),((1,1),3),((2,-2),1),((2,-1),2),((2,0),3)]
Find out which tiles are adjacent to a particular tile.
ghci> neighbours (-1,1) g [(-2,1),(-2,2),(-1,2),(0,1),(0,0),(-1,0)]
Find out if a tile is within the grid boundary.
ghci> inGrid (0,0) g True ghci> inGrid (0,12) g False
Find out the physical dimensions of the grid.
ghci> size g 3
Find out the number of tiles in the grid.
ghci> tileCount g 19
Check if a grid is empty (contains no tiles).
ghci> empty g False ghci> nonEmpty g True