module Hex:sig
..end
Support for hexagonal grids as used in Hey That's My Fish!
A hexagonal grid is represented as a matrix. The details on the mapping from hexagonal to square grids do not matter. Positions in the grid are thus simply pairs of integers.
We make use of char grid
when printing, and bool grid
when
we only need to know which cells are avaiable.
typepos =
int * int
type'a
grid ='a array array
type
dir =
| |
N |
| |
NE |
| |
SE |
| |
S |
| |
SW |
| |
NW |
There are six directions for moving: north, north-east, etc.
val all_directions : dir list
List of all possible directions.
typemove =
dir * int
A movement is a direction and an integer indicating how many steps must be taken in that direction.
val move : pos -> dir -> pos
move p d
indicates the position obtained when moving from p
in direction d
with just one step.
val move_n : pos -> move -> pos
Compute the position resulting from an arbitrary move.
Display grids on formatters.
val pp_char_grid : Stdlib.Format.formatter -> char grid -> unit
val pp_bool_grid : Stdlib.Format.formatter -> bool grid -> unit
val pp_solution : Stdlib.Format.formatter -> bool grid -> pos array -> unit
pp_solution fmt grid path
displays the grid on fmt
,
and shows a path (list of positions) on it. It is meant to
be used to visualize problem solutions.
val from_channel : Stdlib.in_channel -> pos * bool grid
Read a grid and initial position from some input channel.