Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module is considered internal. Clients should use Game.H2048.Gameplay instead.
Synopsis
- type Coord = (Int, Int)
- type Coords = [Coord]
- type CoordsGroup = [Coords]
- data Dir
- type CellTier = Int
- newtype Cell = Cell {}
- type Distrib' a = Vector (a, Int)
- type Distrib = Distrib' Int
- data GameRule = GameRule {
- _grDim :: (Int, Int)
- _grMergeAward :: CellTier -> Int
- _grNewCellDistrib :: Distrib
- _grInitSpawn :: Int
- _grHasWon :: Int -> GameBoard -> Bool
- type GameBoard = Map Coord Cell
- randomPick :: Distrib' a -> TFGen -> (a, TFGen)
- allCoords :: GameRule -> Coords
- applyMove :: GameRule -> Dir -> GameBoard -> Maybe (GameBoard, Int)
- possibleMoves :: GameRule -> GameBoard -> [(Dir, (GameBoard, Int))]
- unsafeIntToCell :: Int -> Cell
- intToCell :: Int -> Maybe Cell
- cellToInt :: Cell -> Int
- standardGameRule :: GameRule
- merge :: Cell -> Cell -> Maybe Cell
- mergeWithScore :: GameRule -> Cell -> Cell -> Maybe (Cell, Int)
- mergeLine :: GameRule -> [Cell] -> ([Cell], Int)
- dirToCoordsGroups :: GameRule -> Dir -> CoordsGroup
- computeDistrib :: IntMap Int -> Distrib
- testDistrib :: Int -> [(Int, Int)] -> IO ()
- isAlive :: GameRule -> GameBoard -> Bool
Documentation
type Coords = [Coord] Source #
List of Coord
. This list
is usually a complete row or column in the game board.
type CoordsGroup = [Coords] Source #
List of Coords
, expected to exact-cover the game board.
Moves that a user could do.
An obscure data type that wraps CellTier
.
type Distrib' a = Vector (a, Int) Source #
The same as Distrib
except parameterized on the value type.
type Distrib = Distrib' Int Source #
A Distrib
is a non-empty Vector
whose each element (a,b)
satisfies:
a
, when taken in sequence, is positive and strictly increasing.b
, when taken in sequence, is strictly increasing.
Think this data type as a precomputation result for making weighted random choice.
You can use computeDistrib
to generate a value of this.
A data type for encoding game rules that do not necessarily needs to be hard-coded into core logic.
You can use standardGameRule
for a standard game rule,
or make changes using it as the base.
GameRule | |
|
randomPick :: Distrib' a -> TFGen -> (a, TFGen) Source #
Pick a value randomly following the distribution as specified by the argument.
allCoords :: GameRule -> Coords Source #
Return a unique, sorted list of all coordinations of a board.
applyMove :: GameRule -> Dir -> GameBoard -> Maybe (GameBoard, Int) Source #
Apply a game move on a board. This operation fails if and only if the move results in no change to the game board.
possibleMoves :: GameRule -> GameBoard -> [(Dir, (GameBoard, Int))] Source #
Return possible moves that can be performed on current board.
unsafeIntToCell :: Int -> Cell Source #
Convert an integer to Cell
, the input is expected
to be a power of 2 but no check is enforced.
Given that standard game is based on powers of 2, it makes sense that we implement some direct support for it.
standardGameRule :: GameRule Source #
The standard game rule. This value can be used as a base for customized game rules.
mergeWithScore :: GameRule -> Cell -> Cell -> Maybe (Cell, Int) Source #
Merge two cells with a reward as specified by GameRule
.
mergeLine :: GameRule -> [Cell] -> ([Cell], Int) Source #
Merge a single line of cells, return the resulting line and
scores awarded according to the GameRule
.
dirToCoordsGroups :: GameRule -> Dir -> CoordsGroup Source #
Given a game move,
return rows or columns of Coords
that forms the complete board.
computeDistrib :: IntMap Int -> Distrib Source #
Computes Distrib
for weighted random cell tier spawns.
The input must be a non-empty map from cell tiers to their corresponding weight. All weights must be positive.