Module Twenty_fourty_eight.Game

Parameters

module _ : GameParams

Signature

type direction =
  1. | Up
  2. | Down
  3. | Left
  4. | Right

Defines all possible movement directions.

type state =
  1. | Won
  2. | Over
  3. | Playing

Defines all possible game states. The player can keep playing after winning, and the state will be kept as `Won`.

type cell = {
  1. value : int;
  2. position : int;
}

Represents a game cell with a value and an index position.

type t = cell list

Represents the actual game state, which is a list of all cells.

val new_game : unit -> t

Creates a new game with a single random cell.

val move : direction -> t -> t * state * int

Moves all cells into the given direction,generates a new cell, and returns a tuple of the new cells and the game state.