-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard.mli
50 lines (40 loc) · 2.07 KB
/
board.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
(** Representation of type and functions of board used in the game.
This module includes the initilizing of a new board, adding and
removing of tiles from the board, and board validation and sorting. *)
(** The type [b_row] represents a row on the board with row letter [row]
and [tiles], a list of tiles in that row. *)
type b_row = {
row : string;
tiles : Tile.t list;
}
(** The type [b] represents the board as a list of [b_row]. *)
type b = b_row list
(** [InvalidBoardSets slst] represents the invalid tile runs or groups
on the board. *)
exception InvalidBoardSets of string list
(** [RowAlreadyFull] is raised when a player attempts to add a tile to a
row that is full with 13 tiles. *)
exception RowAlreadyFull of string
(** [init_board] is the initial state of the board with no tiles. *)
val init_board : unit -> b
(** [add_tile tile rl b] is a board [b'] that is board [b] with [tile]
added to row [rl]. Joker tiles on the board are assigned a number
and color that form a valid or run with the rest of the tiles in its
row. If no such values exists, joker tiles are left unaltered.
Raises [RowAlreadyFull] if row [rl] is already full. *)
val add_tile : Tile.t -> string -> b -> b
(** [remove_tile tile rl b] is a board [b'] that is board [b] with
[tile] removed from row [rl]. Joker tiles on the board are assigned
a number and color that form a valid or run with the rest of the
tiles in its row. If no such values exists, joker tiles are left
unaltered. *)
val remove_tile : Tile.t -> string -> b -> b
(** [valid_board board] is [true] if each row in [board] is either empty
or consists of tiles making a valid run or a valid group.
[InvalidBoardRow slst] is raised where [slst] is the list of row
letters that are invalid on the board. *)
val valid_board : b -> bool
(** [sort_board_by_num acc b] is a new board [b'] consisting of the same
rows in [b] but with the tiles sorted in incrementing number order.
Tiles of the same number are also sorted to fit the color hierarchy. *)
val sort_board_by_num : b -> b -> b