Safe Haskell | None |
---|---|
Language | Haskell2010 |
AUTHOR
- Dr. Alistair Ward
DESCRIPTION
- The location of a square on the board.
Synopsis
- data Coordinates
- type ArrayByCoordinates = Array Coordinates
- tag :: String
- topLeft :: Coordinates
- bottomRight :: Coordinates
- nSquares :: NCoordinates
- extrapolate :: Direction -> Coordinates -> [Coordinates]
- interpolate :: Coordinates -> Coordinates -> [Coordinates]
- getLogicalColourOfSquare :: Coordinates -> LogicalColourOfSquare
- kingsStartingCoordinates :: LogicalColour -> Coordinates
- rooksStartingCoordinates :: LogicalColour -> [Coordinates]
- measureDistance :: Coordinates -> Coordinates -> (X, Y)
- translate :: ((X, Y) -> (X, Y)) -> Coordinates -> Coordinates
- maybeTranslate :: ((X, Y) -> (X, Y)) -> Coordinates -> Maybe Coordinates
- translateX :: (X -> X) -> Transformation
- maybeTranslateX :: (X -> X) -> Coordinates -> Maybe Coordinates
- translateY :: (Y -> Y) -> Transformation
- maybeTranslateY :: (Y -> Y) -> Coordinates -> Maybe Coordinates
- getAdjacents :: Coordinates -> [Coordinates]
- advance :: LogicalColour -> Transformation
- retreat :: LogicalColour -> Transformation
- maybeRetreat :: LogicalColour -> Coordinates -> Maybe Coordinates
- mkCoordinates :: X -> Y -> Coordinates
- mkMaybeCoordinates :: X -> Y -> Maybe Coordinates
- fromIx :: Int -> Coordinates
- mkRelativeCoordinates :: ((X, Y) -> (X, Y)) -> Coordinates
- listArrayByCoordinates :: IArray a e => [e] -> a Coordinates e
- arrayByCoordinates :: IArray a e => [(Coordinates, e)] -> a Coordinates e
- isPawnsFirstRank :: LogicalColour -> Coordinates -> Bool
- isEnPassantRank :: LogicalColour -> Coordinates -> Bool
- areSquaresIsochromatic :: [Coordinates] -> Bool
Types
Data-types
data Coordinates Source #
The coordinates of a square on the board.
Instances
Type-synonyms
type ArrayByCoordinates = Array Coordinates Source #
A boxed array indexed by coordinates, of arbitrary elements.
Constants
topLeft :: Coordinates Source #
Constant.
bottomRight :: Coordinates Source #
Constant.
nSquares :: NCoordinates Source #
The constant number of squares on the board.
Functions
:: Direction | The direction in which to proceed. |
-> Coordinates | The point from which to start. |
-> [Coordinates] |
- Generates a line of coordinates, starting just after the specified source & proceeding in the specified direction to the edge of the board.
- CAVEAT: this is a performance-hotspot (it's also responsible for the allocation of a third of the application's memory); refactor => re-profile. In consequence, it is typically automatically avoided using a rewrite-rule to lookup an array of the results from all possible calls.
interpolate :: Coordinates -> Coordinates -> [Coordinates] Source #
- Generates a line of coordinates covering the half open interval
(source, destination]
. - CAVEAT: the destination-coordinates must be a valid
Queen
's move from the source; so that all intermediate points lie on a square of the board.
getLogicalColourOfSquare :: Coordinates -> LogicalColourOfSquare Source #
The logical colour of the specified square.
kingsStartingCoordinates :: LogicalColour -> Coordinates Source #
The conventional starting coordinates for the King
of the specified logical colour.
rooksStartingCoordinates :: LogicalColour -> [Coordinates] Source #
The conventional starting coordinates for each Rook
.
:: Coordinates | Source. |
-> Coordinates | Destination. |
-> (X, Y) |
- Measures the signed distance between source & destination coordinates.
- N.B.: this isn't the irrational distance a rational crow would fly, but rather the integral x & y components of that path.
- CAVEAT: beware the potential fence-post error.
translate :: ((X, Y) -> (X, Y)) -> Coordinates -> Coordinates Source #
- Translate the specified coordinates using the specified mapping.
- CAVEAT: the caller must ensure that the results are legal.
maybeTranslate :: ((X, Y) -> (X, Y)) -> Coordinates -> Maybe Coordinates Source #
Where legal, translate the specified coordinates.
translateX :: (X -> X) -> Transformation Source #
- Translate the specified abscissa.
- CAVEAT: the caller must ensure that the results are legal.
:: (X -> X) | Translation. |
-> Coordinates | |
-> Maybe Coordinates |
Where legal, translate the x-component of the specified coordinates.
translateY :: (Y -> Y) -> Transformation Source #
- Translate the specified ordinate.
- CAVEAT: the caller must ensure that the results are legal.
:: (Y -> Y) | Translation. |
-> Coordinates | |
-> Maybe Coordinates |
Where legal, translate the y-component of the specified coordinates.
getAdjacents :: Coordinates -> [Coordinates] Source #
Get the coordinates immediately left & right.
:: LogicalColour | The logical colour of the piece which is to advance. |
-> Transformation |
- Move one step towards the opponent.
- CAVEAT: the caller must ensure that the results are legal.
:: LogicalColour | The logical colour of the piece which is to retreat. |
-> Transformation |
- Move one step away from the opponent.
- CAVEAT: the caller must ensure that the results are legal.
:: LogicalColour | The logical colour of the piece which is to retreat. |
-> Coordinates | The location from which to retreat. |
-> Maybe Coordinates |
Where legal, move one step away from the opponent.
Constructors
fromIx :: Int -> Coordinates Source #
- Construct from the specified array-index.
- CAVEAT: assumes that the array is indexed by the whole range of coordinates.
mkRelativeCoordinates :: ((X, Y) -> (X, Y)) -> Coordinates Source #
- Construct coordinates relative to
minBound
. - CAVEAT: the caller must ensure that the results are legal.
listArrayByCoordinates :: IArray a e => [e] -> a Coordinates e Source #
Array-constructor from an ordered list of elements.
arrayByCoordinates :: IArray a e => [(Coordinates, e)] -> a Coordinates e Source #
Array-constructor from an association-list.
Predicates
isPawnsFirstRank :: LogicalColour -> Coordinates -> Bool Source #
Whether the specified coordinates are where a Pawn
of the specified logical colour starts.
isEnPassantRank :: LogicalColour -> Coordinates -> Bool Source #
Whether a Pawn
is currently on the appropriate rank to take an opponent's Pawn
en-passant.
areSquaresIsochromatic :: [Coordinates] -> Bool Source #
Whether the specified squares have the same logical colour.