hs2048-0.1.0: A 2048 clone in Haskell.

Safe HaskellSafe-Inferred

Hs2048.Tile

Description

Types and functions for manipulating tiles.

Synopsis

Documentation

type Tile = Maybe IntSource

Represents a tile on the game board. Can be empty (Nothing) or can have a value (Just n). By convention, a tile's value is always a power of 2.

empty :: TileSource

Returns the empty tile.

>>> empty
Nothing

parse :: String -> TileSource

Parses a string as a tile. This is the inverse of render.

>>> parse "-"
Nothing
>>> parse "2"
Just 2

rank :: Tile -> IntSource

Calculates the rank of a tile.

>>> rank Nothing
0
>>> rank (Just 2)
1
>>> rank (Just 2048)
11

render :: Tile -> StringSource

Renders a tile as a string. This is the inverse of parse.

>>> render Nothing
"-"
>>> render (Just 2)
"2"

score :: Tile -> IntSource

Calculates the score of a tile.

>>> score Nothing
0
>>> score (Just 2)
0
>>> score (Just 2048)
20480