-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkers.mli
51 lines (36 loc) · 1.72 KB
/
checkers.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
type player = Red | Black
type square = player option
type position = int * int
type state
exception Invalid_pos
(** [size] is the size of a checkerboard. *)
val size : int
(** [new_game] is the state that represents a new game of checkers. *)
val new_game : state
(** [get_player t] is the player who's turn it is in state [t]. *)
val get_player : state -> player
(** [get_board t] is the list of squares in state [t] where a square in
position [x,y] is found at index [size * x + y] in the list. *)
val get_board : state -> square list
(** [get_square t pos] is the square located at position [pos] in state [t].
Raises Invalid_Pos if [pos] is not a valid position. *)
val get_square : state -> position -> square
(** [set_square t pos sq] is the state [t] with the square located at position
[pos] set to [sq].
Raises Invalid_Pos if [pos] is not a valid position. *)
val set_square : state -> position -> square -> state
(** [winner t] is None if the game is not over. Otherwise, it is an option
containing the player that won. *)
val winner : state -> player option
(** [valid_move t pos1 pos2] is true iff moving the checker piece
located at position [pos1] to position [pos2] is a valid move
according to the rules of checkers. *)
val valid_move : state -> position -> position -> bool
(** [move t pos1 pos2] is the state [t] after moving the checker piece in [pos1]
to [pos2], removing all appropriate checker pieces in the process. *)
val move : state -> position -> position -> state
(** [to_string t] is a string representation of the state [t]. *)
val to_string : state -> string
(** [print_game t] prints a string representation of the state [t] to
the console. *)
val print_game : state -> unit