hs2048-0.1.0: A 2048 clone in Haskell.

Hs2048.Board

Description

Types and functions for manipulating boards.

Synopsis

# Documentation

type Board = [Vector]Source

Represents the game board. By convention, it is row-major.

Determines if the board can be moved in the given direction. See `move`.

````>>> ````canMove [[Nothing, Just 2]] D.West
```True
```

Determines if the board can be shifted. See `shift`.

````>>> ````canShift [[Nothing, Just 2]]
```True
```

Arguments

 :: Int Width -> Int Height -> Board

Returns an empty board of the given size.

````>>> ````empty 2 1
```[[Nothing,Nothing]]
```

emptyPoints :: Board -> [Point]Source

Returns the points that don't contain tiles.

````>>> ````emptyPoints [[Nothing, Just 2]]
```[(0,0)]
```

Moves the board in the given direction.

````>>> ````move [[Nothing, Just 2]] D.West
```[[Just 2,Nothing]]
```

Parses a string as a board. This is the inverse of `render`.

````>>> ````parse "- 2\n4 -\n"
```[[Nothing,Just 2],[Just 4,Nothing]]
```

Renders a board as a string. This is the inverse of `parse`.

````>>> ````render [[Nothing, Just 2], [Just 4, Nothing]]
```"- 2\n4 -\n"
```

Rotate the board 90 degrees clockwise.

````>>> ````rotate [[Nothing, Just 2], [Just 4, Nothing]]
```[[Just 4,Nothing],[Nothing,Just 2]]
```

Rotates the board so that `West` is at the left, assuming the given direction is currently at the left. This is the inverse of `rotateTo`.

````>>> ````rotateFrom [[Just 4, Nothing], [Nothing, Just 2]] D.South
```[[Nothing,Just 2],[Just 4,Nothing]]
```

Rotates the board so that the given direction is at the left. This is the inverse of `rotateFrom`

````>>> ````rotateTo [[Nothing, Just 2], [Just 4, Nothing]] D.South
```[[Just 4,Nothing],[Nothing,Just 2]]
```

Calculates the score of a board.

````>>> ````score [[Nothing, Just 2], [Just 4, Just 8]]
```20
```

set :: Board -> Tile -> Point -> BoardSource

Sets a tile at the given point in the board.

````>>> ````set [[Nothing, Just 2], [Just 4, Nothing]] (Just 8) (1, 1)
```[[Nothing,Just 2],[Just 4,Just 8]]
```

Shifts a board toward the head. See `shift`.

````>>> ````shift [[Nothing, Just 2], [Just 4, Nothing]]
```[[Just 2,Nothing],[Just 4,Nothing]]
```