bishbosh-0.0.0.6: Plays chess.

Safe HaskellNone
LanguageHaskell2010

BishBosh.State.MaybePieceByCoordinates

Contents

Description

AUTHOR
Dr. Alistair Ward
DESCRIPTION
  • Models the board as a sparse array, each element of which might contain a piece.
  • N.B.: while this could be represented as Data.Map.Map Coordinates Piece, replacing ! with lookup, it actually required more space (despite having at most half the elements) & runs slower (because of compare).
  • cf. the piece-centric model of the board defined in BishBosh.State.CoordinatesByRankByLogicalColour.
Synopsis

Types

Type-synonyms

Data-types

data MaybePieceByCoordinates x y Source #

  • This structure allows one to determine what piece (if any) is located at specific coordinates.
  • N.B.: this could be implemented using Vector, which being indexed by Int is no longer polymorphic & permits many unsafe operations; but the result is no faster.
Instances
(Enum x, Enum y, Ord x, Ord y) => Hashable2D MaybePieceByCoordinates x y Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

Methods

listRandoms2D :: MaybePieceByCoordinates x y -> Zobrist x y positionHash -> [positionHash] Source #

(Enum x, Enum y, Ord x, Ord y) => Eq (MaybePieceByCoordinates x y) Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

(Enum x, Enum y, Ord x, Ord y) => Ord (MaybePieceByCoordinates x y) Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

(Enum x, Enum y, Ord x, Ord y) => Read (MaybePieceByCoordinates x y) Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

(Enum x, Enum y, Ord x, Ord y) => Show (MaybePieceByCoordinates x y) Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

(NFData x, NFData y) => NFData (MaybePieceByCoordinates x y) Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

Methods

rnf :: MaybePieceByCoordinates x y -> () #

(Enum x, Enum y, Ord x, Ord y) => Default (MaybePieceByCoordinates x y) Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

(Enum x, Enum y, Ord x, Ord y) => Empty (MaybePieceByCoordinates x y) Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

(Enum x, Enum y, Ord x, Ord y) => ShowsFEN (MaybePieceByCoordinates x y) Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

(Enum x, Enum y, Ord x, Ord y) => ReadsFEN (MaybePieceByCoordinates x y) Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

(Enum x, Enum y, Ord x, Ord y) => ReflectableOnY (MaybePieceByCoordinates x y) Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

(Enum x, Enum y, Ord x, Ord y) => ReflectableOnX (MaybePieceByCoordinates x y) Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

(Enum x, Enum y, Ord x, Ord y) => Censor (MaybePieceByCoordinates x y) Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

Constants

Functions

inferMoveType Source #

Arguments

:: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) 
=> Move x y 
-> Maybe Rank

The rank to which a Pawn should be promoted; defaulting to Queen.

-> MaybePieceByCoordinates x y 
-> MoveType 

Infer the type of the specified move.

findPieces :: (Enum x, Enum y, Ord x, Ord y) => MaybePieceByCoordinates x y -> [LocatedPiece x y] Source #

Find all pieces.

findBlockingPiece Source #

Arguments

:: (Enum x, Enum y, Ord x, Ord y) 
=> Direction

The direction in which to search.

-> Coordinates x y

The starting point.

-> MaybePieceByCoordinates x y 
-> Maybe (LocatedPiece x y) 
  • Find the first piece of either logical colour, encountered along a straight line in the specified direction, from just after the specified coordinates.
  • CAVEAT: this is a performance-hotspot.

findProximateKnights Source #

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.

-> MaybePieceByCoordinates x y 
-> [Coordinates x y] 
  • Find any Knights of the specified logical colour, in attack-range around the specified coordinates.
  • CAVEAT: nothing is said about whether any piece at the specified coordinates belongs to the opponent, as one might expect.
  • CAVEAT: less efficient than findProximateKnights.

findAttackerInDirection Source #

Arguments

:: (Enum x, Enum y, Ord x, Ord y) 
=> LogicalColour

The defender's logical colour.

-> Direction

The direction from the coordinates of concern; the opposite direction from which an attacker might strike.

-> Coordinates x y

The defender's square.

-> MaybePieceByCoordinates x y 
-> Maybe (Coordinates x y, Rank)

Any opposing piece which can attack the specified square from the specified direction.

  • Find the coordinates of any attacker who can strike the specified coordinates, in a straight line along the specified direction (as seen by the target).
  • N.B.: there no requirement for there to actually be a piece to attack at the specified target.

sumPieceSquareValueByLogicalColour :: (Enum x, Enum y, Num pieceSquareValue, Ord x, Ord y) => FindPieceSquareValue x y pieceSquareValue -> MaybePieceByCoordinates x y -> [pieceSquareValue] Source #

Calculate the total value of the coordinates occupied by the pieces of either side.

listDestinationsFor Source #

Arguments

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

The source for which destinations are required.

-> Piece

The piece at the specified source.

-> MaybePieceByCoordinates x y 
-> [(Coordinates x y, Maybe Rank)]

The destination & the rank of any piece taken.

  • Lists the destination-coordinates to which the referenced piece can move, & the rank of any piece taken.
  • N.B.: one can reference either player's piece, regardless of whose turn it is to move.
  • CAVEAT: doesn't include either Castling or En-passant, because this function doesn't know the history of the game.
  • CAVEAT: doesn't check whether any proposed move exposes one's King, because this function doesn't assume the existence of a King.
  • CAVEAT: the opponent's King may be one of the destinations returned, but only if it was actually their move next.
  • CAVEAT: doesn't typically check whether anything (let alone the specified piece) exists at the specified source-coordinates.

show2D Source #

Arguments

:: (Enum x, Enum y, Integral column, Ord x, Ord y) 
=> column

The column-magnification.

-> ColourScheme 
-> (Int, Int)

The origin from which axes are labelled.

-> MaybePieceByCoordinates x y 
-> String

The output suitable for display on a terminal.

Show the board using a two-dimensional representation.

Accessors

dereference :: (Enum x, Enum y, Ord x, Ord y) => Coordinates x y -> MaybePieceByCoordinates x y -> Maybe Piece Source #

Dereference the array.

Mutators

defineCoordinates Source #

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.

movePiece Source #

Arguments

:: (Enum x, Enum y, Ord x, Ord y) 
=> Move x y 
-> Piece

The (possibly promoted) piece to place at the destination.

-> Maybe (Coordinates x y)

Destination of any En-passant Pawn.

-> Transformation x y 
  • Adjust the array to reflect a move.
  • CAVEAT: regrettably this allocates an entire array.

Predicates

isVacant :: (Enum x, Enum y, Ord x, Ord y) => Coordinates x y -> MaybePieceByCoordinates x y -> Bool Source #

Whether the specified coordinates are unoccupied.

isOccupied :: (Enum x, Enum y, Ord x, Ord y) => Coordinates x y -> MaybePieceByCoordinates x y -> Bool Source #

Whether the specified coordinates are occupied.

isClear Source #

Arguments

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

Source.

-> Coordinates x y

Destination.

-> MaybePieceByCoordinates x y 
-> Bool 
  • Whether the open interval (source, destination) is unobstructed.
  • N.B.: the specified end-points are uninspected.

isObstructed Source #

Arguments

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

Source.

-> Coordinates x y

Destination.

-> MaybePieceByCoordinates x y 
-> Bool 

Whether there's a blockage between a piece presumed to exist at the specified source, & a piece presumed to exist @ the specified destination.

isEnPassantMove :: (Enum x, Enum y, Ord x, Ord y) => Move x y -> MaybePieceByCoordinates x y -> Bool Source #

  • Whether the specified move matches the rules for en-passant.
  • CAVEAT: assumes that the move is valid; otherwise one would also need to confirm that the opponent's Pawn had just double-advanced into the appropriate position.