Safe Haskell | None |
---|---|
Language | Haskell2010 |
AUTHOR
- Dr. Alistair Ward
DESCRIPTION
- Defines the data-type which represents any chess-piece.
- type NPieces = Int
- type ByPiece = Array Piece
- type LocatedPiece x y = (Coordinates x y, Piece)
- data Piece
- nPiecesPerSide :: NPieces
- range :: [Piece]
- attackDirectionsByPiece :: Map Piece [Direction]
- findAttackDestinations :: (Enum x, Enum y, Ord x, Ord y) => Coordinates x y -> Piece -> [Coordinates x y]
- promote :: Rank -> Piece -> Piece
- mkBishop :: LogicalColour -> Piece
- mkKing :: LogicalColour -> Piece
- mkKnight :: LogicalColour -> Piece
- mkPawn :: LogicalColour -> Piece
- mkPiece :: LogicalColour -> Rank -> Piece
- mkQueen :: LogicalColour -> Piece
- mkRook :: LogicalColour -> Piece
- listArrayByPiece :: IArray a e => [e] -> a Piece e
- canAttackAlong :: (Enum x, Enum y) => Coordinates x y -> Coordinates x y -> Piece -> Bool
- canMoveBetween :: (Enum x, Enum y, Eq y) => Coordinates x y -> Coordinates x y -> Piece -> Bool
- isBlack :: Piece -> Bool
- isFriend :: Piece -> Piece -> Bool
- isPawn :: Piece -> Bool
- isKnight :: Piece -> Bool
- isKing :: Piece -> Bool
- isPawnPromotion :: (Enum y, Eq y) => Coordinates x y -> Piece -> Bool
Types
Type-synonyms
type LocatedPiece x y = (Coordinates x y, Piece) Source #
Self-documentation.
Data-types
A Chess-piece has a logical colour & a rank.
Constants
nPiecesPerSide :: NPieces Source #
The initial number of pieces per side in a standard opening position; some of which are duplicates.
attackDirectionsByPiece :: Map Piece [Direction] Source #
- Find the constant directions of the straight lines along which each type of piece can attack.
- CAVEAT: not defined for a
Knight
.
Functions
findAttackDestinations Source #
:: (Enum x, Enum y, Ord x, Ord y) | |
=> Coordinates x y | The source from which the attack originates. |
-> Piece | |
-> [Coordinates x y] | The destinations which can be attacked. |
Calls attackVectorsByPiece
to find the destinations which the specified piece can attack from the specified position.
Mutators
promote :: Rank -> Piece -> Piece Source #
- Changes the rank of the specified piece, leaving the logical colour unchanged.
- CAVEAT: only legal if the rank was a
Pawn
, & becomes neither aPawn
nor aKing
.
Constructors
mkBishop :: LogicalColour -> Piece Source #
Constructor.
mkKing :: LogicalColour -> Piece Source #
Constructor.
mkKnight :: LogicalColour -> Piece Source #
Constructor.
mkPawn :: LogicalColour -> Piece Source #
Constructor.
mkQueen :: LogicalColour -> Piece Source #
Constructor.
mkRook :: LogicalColour -> Piece Source #
Constructor.
listArrayByPiece :: IArray a e => [e] -> a Piece e Source #
Array-constructor.
Predicates
:: (Enum x, Enum y) | |
=> Coordinates x y | Source (attacker's location). |
-> Coordinates x y | Destination (victim's location). |
-> Piece | Attacker. |
-> Bool |
- Whether a piece at the specified coordinates could attack the target at the specified coordinates.
- N.B.: doesn't require that the specified piece actually exists at the target-location, nor that the victim's logical colour is opposite from the attacker's.
- N.B.: can't detect any blocking pieces which might invalidate the attack.
- CAVEAT: it won't confirm the ability of a
Pawn
to advance, since that doesn't constitute an attack.
:: (Enum x, Enum y, Eq y) | |
=> Coordinates x y | Source. |
-> Coordinates x y | Destination. |
-> Piece | |
-> Bool |
- Whether the specified piece can move between the specified coordinates.
- N.B.: can't detect any blocking pieces.
isFriend :: Piece -> Piece -> Bool Source #
Whether the specified pieces have the same logical colour.
:: (Enum y, Eq y) | |
=> Coordinates x y | Destination. |
-> Piece | |
-> Bool |
Whether a move qualifies for Pawn
-promotion.