hs2048-0.1.0: A 2048 clone in Haskell.

Safe HaskellSafe-Inferred

Hs2048.Game

Description

Functions for playing the game.

Synopsis

Documentation

addRandomTile :: RandomGen r => Board -> r -> (Board, r)Source

Adds a random tile to the board.

>>> addRandomTile [[Nothing], [Nothing]] (R.mkStdGen 0)
([[Nothing],[Just 2]],1346387765 2103410263)

addRandomTiles :: RandomGen r => Int -> Board -> r -> (Board, r)Source

Adds some random tiles to the board.

>>> addRandomTiles 2 [[Nothing], [Nothing]] (R.mkStdGen 0)
([[Just 2],[Just 2]],2127568003 1780294415)

hasWon :: Board -> BoolSource

Determines if the game has been won. See maxTile.

>>> hasWon [[Just 2048]]
True

isOver :: Board -> BoolSource

Determines if the game is over. The game is over if there are no available moves and no empty points.

>>> isOver [[Just 2]]
True

new :: RandomGen r => r -> (Board, r)Source

Creates a new game by making an empty board and adding some random tiles to it. See width, height, and tiles.

>>> new (R.mkStdGen 0)
([[Just 2,Nothing,Nothing,Nothing],[Nothing,Nothing,Nothing,Nothing],[Nothing,Nothing,Nothing,Nothing],[Nothing,Just 2,Nothing,Nothing]],2127568003 1780294415)

randomEmptyIndex :: RandomGen r => Vector -> r -> (Maybe Int, r)Source

Selects an empty index at random from a vector.

>>> randomEmptyIndex [Nothing, Nothing] (R.mkStdGen 0)
(Just 1,40014 40692)

randomEmptyPoint :: RandomGen r => Board -> r -> (Maybe Point, r)Source

Selects an empty point at random from a board.

>>> randomEmptyPoint [[Nothing],[Nothing]] (R.mkStdGen 0)
(Just (1,0),40014 40692)

randomTile :: RandomGen r => r -> (Tile, r)Source

Creates a random tile.

>>> randomTile (R.mkStdGen 0)
(Just 2,1601120196 1655838864)