package knights_tour

  1. Overview
  2. Docs
type t

represents the 'chessboard' of n x n squares. The Board.t data type is two-dimenional array. Each cell in the array keeps track of whether and when a knight has visited the square. If a knight has visited it, the cell contains a number indicating when (i.e. the number indicates which turn of the game the knight visited that square.

val size : t -> int

The size of the board. If Board.size b is n, then the boards is a n x n square.

val make : int -> t

Board.make n creates a board of size n x n

val to_string : t -> string

Produces a string representation of the board that is suitable for printing on the console.

val get : t -> Point.t -> int option

Board.get b {x;y} reads the current contents of a square of the board at a given {x;y} coordinate.

val set : t -> Point.t -> int option -> unit

Board.set b {x;y} newContents sets the contents of the board at a given coordinate.

val draw : t -> unit

Drays the board using the graphics library.

val isValid : t -> bool

Validates where a given board representation corresponds to a valid sequence of moves. (I.e. if go through the squares on the board in the order indicated by the numbers recorded in them, then each transition represents a valid move.

val isValidTarget : t -> Point.t -> bool

Checks that given coordinate is a valid place for a knight to move to. This means that the coordinate is within the board; and has not yet been visited by a knight before.

val count_targets : t -> Point.t -> int

Counts the number of already visited squares in the board.

OCaml

Innovation. Community. Security.