Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Types and functions for manipulating vectors.
Documentation
Represents a row or column on the game board. By convention, a vector has 4 tiles.
canShift :: Vector -> Bool Source
Determines if the vector can be shifted.
>>>
canShift [Nothing, Just 2, Nothing, Nothing]
True
Returns an empty vector of the given size.
>>>
empty 4
[Nothing,Nothing,Nothing,Nothing]
emptyIndexes :: Vector -> [Int] Source
Returns the indexes that don't contain tiles.
>>>
emptyIndexes [Nothing, Just 2, Nothing, Nothing]
[0,2,3]
parse :: String -> Vector Source
Parses a string as a vector. This is the inverse of render
.
>>>
parse "- 2 - -"
[Nothing,Just 2,Nothing,Nothing]
render :: Vector -> String Source
Renders a vector as a string. This is the inverse of parse
.
>>>
render [Nothing, Just 2, Nothing, Nothing]
"- 2 - -"
Calculates the score of a vector.
>>>
score [Nothing, Just 2, Just 4, Just 8]
20
set :: Vector -> Tile -> Int -> Vector Source
Sets a tile at the given index in the vector.
>>>
set [Nothing, Nothing, Nothing, Nothing] (Just 2) 1
[Nothing,Just 2,Nothing,Nothing]
shift :: Vector -> Vector Source
Shifts a vector toward the head. The output vector will be the same size as
the input vector, padded with Nothing
.
>>>
shift [Nothing, Just 2, Nothing, Nothing]
[Just 2,Nothing,Nothing,Nothing]
Like tiles will be combined.
>>>
shift [Just 2, Nothing, Just 2, Just 2]
[Just 4,Just 2,Nothing,Nothing]
Any number of tiles can be combined in one shift.
>>>
shift [Just 2, Just 2, Just 4, Just 4]
[Just 4,Just 8,Nothing,Nothing]