Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Functions for playing the game.
- addRandomTile :: RandomGen r => Board -> r -> (Board, r)
- addRandomTiles :: RandomGen r => Int -> Board -> r -> (Board, r)
- hasWon :: Board -> Bool
- isOver :: Board -> Bool
- new :: RandomGen r => r -> (Board, r)
- randomEmptyIndex :: RandomGen r => Vector -> r -> (Maybe Int, r)
- randomEmptyPoint :: RandomGen r => Board -> r -> (Maybe Point, r)
- randomTile :: RandomGen r => r -> (Tile, r)
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 -> Bool Source
Determines if the game has been won. See maxTile
.
>>>
hasWon [[Just 2048]]
True
isOver :: Board -> Bool Source
Determines if the game is over. The game is over if there are no available moves and no empty points.
>>>
isOver [[Just 2]]
True
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)