Safe Haskell | None |
---|---|

Language | Haskell2010 |

`AUTHOR`

- Dr. Alistair Ward
`DESCRIPTION`

- Describes a line's magnitude & direction, irrespective of its position.

- type VectorInt = Vector Distance
- data Vector distance
- attackVectorsForKnight :: Num distance => [Vector distance]
- attackVectorsForKing :: (Eq distance, Num distance) => [Vector distance]
- attackVectorsForPawn :: Num distance => LogicalColour -> [Vector distance]
- translate :: (Enum x, Enum y, Integral distance, Ord x, Ord y) => Coordinates x y -> Vector distance -> Coordinates x y
- maybeTranslate :: (Enum x, Enum y, Integral distance, Ord x, Ord y) => Coordinates x y -> Vector distance -> Maybe (Coordinates x y)
- toMaybeDirection :: (Num distance, Ord distance) => Vector distance -> Maybe Direction
- mkVector :: (Num distance, Ord distance) => distance -> distance -> Vector distance
- measureDistance :: (Enum x, Enum y, Num distance, Ord distance) => Coordinates x y -> Coordinates x y -> Vector distance
- isDiagonal :: (Eq distance, Num distance) => Vector distance -> Bool
- isParallel :: (Eq distance, Num distance) => Vector distance -> Bool
- isStraight :: (Eq distance, Num distance) => Vector distance -> Bool
- isPawnAttack :: (Eq distance, Num distance) => LogicalColour -> Vector distance -> Bool
- isKnightsMove :: (Eq distance, Num distance) => Vector distance -> Bool
- isKingsMove :: (Num distance, Ord distance) => Vector distance -> Bool
- matchesPawnDoubleAdvance :: (Eq distance, Num distance) => LogicalColour -> Vector distance -> Bool

# Types

## Type-synonyms

## Data-types

The distance between two *coordinates*.

# Constants

attackVectorsForKnight :: Num distance => [Vector distance] Source #

The constant list of attack-vectors for a `Knight`

.

attackVectorsForKing :: (Eq distance, Num distance) => [Vector distance] Source #

The constant list of attack-vectors for a `King`

.

# Functions

attackVectorsForPawn :: Num distance => LogicalColour -> [Vector distance] Source #

- The list of attack-vectors for a
`Pawn`

. - N.B.: the
`Pawn`

's ability to advance without taking, isn't dealt with here.

translate :: (Enum x, Enum y, Integral distance, Ord x, Ord y) => Coordinates x y -> Vector distance -> Coordinates x y Source #

Translate the specified *coordinates* by the specified *vector*.

maybeTranslate :: (Enum x, Enum y, Integral distance, Ord x, Ord y) => Coordinates x y -> Vector distance -> Maybe (Coordinates x y) Source #

Where legal, translate the specified *coordinates* by the specified *vector*.

toMaybeDirection :: (Num distance, Ord distance) => Vector distance -> Maybe Direction Source #

- Where possible, converts the specified
*vector*into a*direction*. `Nothing`

is returned for those*vector*s which don't translate into a legal*direction*(e.g. a`Knight`

's move).

## Constructor

mkVector :: (Num distance, Ord distance) => distance -> distance -> Vector distance Source #

Smart constructor.

:: (Enum x, Enum y, Num distance, Ord distance) | |

=> Coordinates x y | Source. |

-> Coordinates x y | Destination. |

-> Vector distance |

Construct a *vector* by measuring the signed distance between source-*coordinates* & destination.

## Predicates

isDiagonal :: (Eq distance, Num distance) => Vector distance -> Bool Source #

Whether the specified *vector* is at 45 degrees to an edge of the board, i.e. any move a `Bishop`

could make.

isParallel :: (Eq distance, Num distance) => Vector distance -> Bool Source #

Whether the specified *vector* is parallel to an edge of the board, i.e. any move a `Rook`

could make.

isStraight :: (Eq distance, Num distance) => Vector distance -> Bool Source #

Whether the specified *vector* is either parallel or at 45 degrees to an edge of the board, i.e. any move a `Queen`

could make.

isPawnAttack :: (Eq distance, Num distance) => LogicalColour -> Vector distance -> Bool Source #

- Whether the specified
*vector*might represent an attack (rather than an advance) by a`Pawn`

. - CAVEAT: if the move started at the first rank, then it can't be a
`Pawn`

, but that's unknown.

isKnightsMove :: (Eq distance, Num distance) => Vector distance -> Bool Source #

Whether the specified *vector* represents a move a `Knight`

could make.

isKingsMove :: (Num distance, Ord distance) => Vector distance -> Bool Source #

Whether the specified *vector* represents a move a `King`

could make.

matchesPawnDoubleAdvance :: (Eq distance, Num distance) => LogicalColour -> Vector distance -> Bool Source #

- Whether the specified
*vector*matches a`Pawn`

's initial double-advance move. - CAVEAT: passing this test doesn't guarantee that it is a
`Pawn`

's double-advance move, since the move may not relate to a`Pawn`

, or could be invalid.