bishbosh-0.0.0.2: Plays chess.

Safe HaskellNone
LanguageHaskell2010

BishBosh.Component.Piece

Contents

Description

AUTHOR
Dr. Alistair Ward
DESCRIPTION
Defines the data-type which represents any chess-piece.

Synopsis

Types

Type-synonyms

type NPieces = Int Source #

A number of pieces.

type ByPiece = Array Piece Source #

A boxed array indexed by piece, of unspecified elements.

type LocatedPiece x y = (Coordinates x y, Piece) Source #

Self-documentation.

Data-types

Constants

nPiecesPerSide :: NPieces Source #

The initial number of pieces per side in a standard opening position; some of which are duplicates.

range :: [Piece] Source #

The constant ascending range of pieces.

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 #

Arguments

:: (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 a Pawn nor a King.

Constructors

mkBishop :: LogicalColour -> Piece Source #

Constructor.

mkKing :: LogicalColour -> Piece Source #

Constructor.

mkKnight :: LogicalColour -> Piece Source #

Constructor.

mkPawn :: LogicalColour -> Piece Source #

Constructor.

mkPiece :: LogicalColour -> Rank -> 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

canAttackAlong Source #

Arguments

:: (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.

canMoveBetween Source #

Arguments

:: (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.

isBlack :: Piece -> Bool Source #

Whether the specified piece is Black.

isFriend :: Piece -> Piece -> Bool Source #

Whether the specified pieces have the same logical colour.

isPawn :: Piece -> Bool Source #

Whether the specified piece is a Pawn.

isKnight :: Piece -> Bool Source #

Whether the specified piece is a Knight.

isKing :: Piece -> Bool Source #

Whether the specified piece is a King.

isPawnPromotion Source #

Arguments

:: (Enum y, Eq y) 
=> Coordinates x y

Destination.

-> Piece 
-> Bool 

Whether a move qualifies for Pawn-promotion.