-
Notifications
You must be signed in to change notification settings - Fork 0
/
maze.mli
77 lines (58 loc) · 2.9 KB
/
maze.mli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
(**
Representation of static information of the game.
This module represents the data stored in game files, namely
the location of the walls defining the maze in which the game
is played. It handles loading of that data from a .csv file as
well as querying the data.
*)
(** Raised when attempting to load a file that does not describe
a pacman game, because an invalid character was encountered.
*)
exception InvalidPosition of string
exception InvalidCharacter of string
(** Raised when attempting to load a file that does not describe
a pacman game, because the maze is not rectangular.
*)
exception MalformedFile of string
(** The abstract type of values representing elements of a maze. *)
type element = WALL | EMPTY | VOID | CAGE | DOOR
(** The abstract type of values representing a maze. *)
type t = element array array
(** [rep_ok maze] confirms valid maze csv is entered *)
val rep_ok: t -> t
(** [dimension] returns the dimensions (height, width) of the maze. *)
val dimension : t -> int * int
(** [load file] loads a maze from the .csv file specified by [file]. *)
val load : string -> t
(** [element_at] returns the position of the elements added to the maze *)
val element_at : t -> int * int -> element
(** [to_printer m] is the representation of maze [m] required to redner it to
the terminal. Each element is a tuple of the ANSITerminal styles in which
to render the element at that position, and the string to print. *)
val to_printer : t -> (ANSITerminal.style list * string) array array
(** [valid_dirs ghost maze (x, y)] is the list of directions that pacman
(or ghost if [ghost]) can move in [maze] when at position (x, y). *)
val valid_dirs : ?ghost:bool -> t -> int * int -> Command.direction list
(** [is_intersection ghost maze (x, y)] is whether position (x, y) is an
intersection (i.e. the character can move vertically or horizontally)
in [maze] for pacman (or ghost if [ghost]). *)
val is_intersection : ?ghost:bool -> t -> int * int -> bool
(** [center maze] are the coordinates of the closest element to the center
that is unoccupied *)
val center : t -> int * int
(** [corners maze] are the coordinates representing the 4 corners of the maze.
*)
val corners : t -> (int * int) list
(** [next ghost dir (x, y) maze] is the next position in [maze] starting at
position (x, y) and moving in direction [dir] for pacman (or ghost if
[ghost]). *)
val next : ?ghost:bool -> Command.direction -> int * int -> t -> int * int
(** [find_in elt maze] is the list of positions at which the element at [maze]
is equal to [elt]. *)
val find_in : element -> t -> (int * int) list
(** [init_empty maze] is the coordinates of all positions that are initally
empty. *)
val init_empty : t -> (int * int) list
(** [init_ghosts maze] is the coordinates of all positions that are initially
occupied by a ghost. *)
val init_ghosts : t -> (int * int) list