bishbosh-0.0.0.5: Plays chess.

BishBosh.State.Board

Description

AUTHOR
Dr. Alistair Ward
DESCRIPTION
• This data-type maintains the state of the board, but it doesn't know its history. In consequence it knows neither whether Castling has already been performed nor which Pawns have been promoted, nor whose turn it is.
• It allows unvalidated access to the board, to place, move, or remove pieces. In consequence; it enforces neither a conventional layout for the pieces nor even that there is exactly one King per side; it permits one to move into check or to take a King.
• For efficiency, two models of the board are maintained; square-centric (State.MaybePieceByCoordinates) & piece-centric (State.CoordinatesByRankByLogicalColour).
Synopsis

# Types

## Type-synonyms

type NBoards = Int Source #

A number of boards.

## Data-types

data Board x y Source #

• The board is modelled as two alternative structures representing the same data, but indexed by either coordinates or piece.
• For efficiency some ancillary structures are also maintained.
Instances

# Functions

countDefendersByCoordinatesByLogicalColour :: (Enum x, Enum y, Ord x, Ord y) => Board x y -> NDefendersByCoordinatesByLogicalColour x y Source #

Count the number of defenders of each piece on the board.

Collapses NDefendersByCoordinatesByLogicalColour into the total number of defenders on either side.

Arguments

 :: (Enum x, Enum y, Ord x, Ord y) => LogicalColour The logical colour of the Knight for which to search. -> Coordinates x y The destination to which the Knight is required to be capable of jumping. -> Board x y -> [Coordinates x y]

Forward request.

sumPieceSquareValueByLogicalColour :: (Enum x, Enum y, Num pieceSquareValue, Ord x, Ord y) => PieceSquareArray x y pieceSquareValue -> Board x y -> ByLogicalColour pieceSquareValue Source #

Calculate the total value of the coordinates occupied by the pieces of either side, at a stage in the game's life-span defined by the total number of pieces remaining.

Arguments

 :: (Enum x, Enum y, Ord x, Ord y) => LogicalColour The defender's logical colour. -> Coordinates x y The defender's location. -> Board x y -> [(Coordinates x y, Rank)] The locations from which the specified square can be attacked by the opposite logical colour.
• Lists the source-coordinates from which the referenced destination can be attacked.
• N.B.: the algorithm is independent of whose turn it actually is.
• CAVEAT: checks neither the logical colour of the defender, nor that their piece even exists.
• CAVEAT: may return the coordinates of a diagonally adjacent Pawn; which would be an illegal move if there's not actually any piece at the referenced destination.
• CAVEAT: can't detect an en-passant attack, since this depends both on whether the previous move was a double advance & that the defender is a Pawn.

Arguments

 :: (Enum x, Enum y, Ord x, Ord y) => Piece The type of attacker. -> Coordinates x y The defender's location. -> Board x y -> [Coordinates x y] The sources from which the specified attacker could strike.
• Lists the source-coordinates from which the referenced destination can be attacked by the specified type of piece.
• N.B.: similar to findAttackersOf, but can be more efficient since the attacking piece is known.
• CAVEAT: can't detect an en-passant attack, since this depends both on whether the previous move was a double advance & that the defender is a Pawn.

## Mutators

Arguments

 :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => Move x y N.B.: illegal moves are acceptable. -> Maybe MoveType N.B.: this may not be available to the caller, for example during the illegal moves required for rollback. -> Transformation x y
• Moves the referenced piece.
• CAVEAT: no validation is performed.
• CAVEAT: castling must be implemented by making two calls.

Arguments

 :: (Enum x, Enum y, Ord x, Ord y) => Maybe Piece The optional piece to place (or remove if Nothing is specified). -> Coordinates x y The coordinates to define. -> Transformation x y
• Define the specified coordinates, by either placing or removing a piece.
• CAVEAT: this function should only be used to construct custom scenarios, since pieces don't normally spring into existence.
• CAVEAT: doesn't validate the request, so Kings can be placed in check & Pawns can be placed behind their starting rank or unpromoted on their last rank.
• CAVEAT: simple but inefficient implementation, since this function isn't called during normal play.

placePiece :: (Enum x, Enum y, Ord x, Ord y) => Piece -> Coordinates x y -> Transformation x y Source #

Place a piece at the specified unoccupied coordinates.

removePiece :: (Enum x, Enum y, Ord x, Ord y) => Coordinates x y -> Transformation x y Source #

Remove a piece from the board.

## Predicates

Arguments

 :: (Enum x, Enum y, Ord x, Ord y) => LogicalColour The logical colour of the King in question. -> Board x y -> Bool
• Whether the King of the specified logical colour is currently checked.
• N.B.: independent of whose turn it actually is.
• CAVEAT: assumes there's exactly one King of the specified logical colour.

Arguments

 :: (Enum x, Enum y, Ord x, Ord y) => LogicalColour The logical colour of the player proposing to move. -> Move x y The move. -> Board x y The original board, i.e. prior to the move. -> Bool
• Whether one's own King has become exposed in the proposed board.
• CAVEAT: assumes that one's King wasn't already checked.
• CAVEAT: this function is a performance-hotspot.