hs2048-0.1.0: A 2048 clone in Haskell.

Safe HaskellSafe-Inferred
LanguageHaskell2010

Hs2048.Tile

Description

Types and functions for manipulating tiles.

Synopsis

Documentation

type Tile = Maybe Int Source

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 :: Tile Source

Returns the empty tile.

>>> empty
Nothing

parse :: String -> Tile Source

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

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

rank :: Tile -> Int Source

Calculates the rank of a tile.

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

render :: Tile -> String Source

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

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

score :: Tile -> Int Source

Calculates the score of a tile.

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