bishbosh-0.1.4.0: Plays chess.
Safe HaskellNone
LanguageHaskell2010

BishBosh.State.MaybePieceByCoordinates

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

Data-types

data MaybePieceByCoordinates 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

Instances details
Eq MaybePieceByCoordinates Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

Ord MaybePieceByCoordinates Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

Read MaybePieceByCoordinates Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

Show MaybePieceByCoordinates Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

Default MaybePieceByCoordinates Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

NFData MaybePieceByCoordinates Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

Methods

rnf :: MaybePieceByCoordinates -> () #

Empty MaybePieceByCoordinates Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

ShowsEPD MaybePieceByCoordinates Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

ReadsEPD MaybePieceByCoordinates Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

ShowsFEN MaybePieceByCoordinates Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

ReadsFEN MaybePieceByCoordinates Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

ReflectableOnY MaybePieceByCoordinates Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

ReflectableOnX MaybePieceByCoordinates Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

SelfValidating MaybePieceByCoordinates Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

Hashable MaybePieceByCoordinates Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

Methods

listRandoms :: Zobrist positionHash -> MaybePieceByCoordinates -> [positionHash] Source #

Seeker MaybePieceByCoordinates Source #
  • 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.
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

View MaybePieceByCoordinates Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

Censor MaybePieceByCoordinates Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

Mutator MaybePieceByCoordinates Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

Accountant MaybePieceByCoordinates Source # 
Instance details

Defined in BishBosh.State.MaybePieceByCoordinates

Functions

inferMoveType Source #

Arguments

:: MaybePieceByCoordinates 
-> Move 
-> Maybe Rank

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

-> MoveType 

Infer the type of the specified move.

findBlockingPiece Source #

Arguments

:: MaybePieceByCoordinates 
-> Coordinates

The starting point.

-> Direction

The direction in which to search.

-> Maybe LocatedPiece

Any blocking piece.

  • Find the first piece of either logical colour, encountered in the specified direction, from just after the specified coordinates.
  • CAVEAT: this is a performance-hotspot.

findBlockingPieces Source #

Arguments

:: MaybePieceByCoordinates 
-> Coordinates

The starting point.

-> Maybe [Direction]

The directions in which to search; Nothing implies omni-directional.

-> [LocatedPiece]

Blocking pieces in non-specific directions.

  • Find the first piece of either logical colour, encountered in each of the specified directions, from just after the specified coordinates.
  • N.B.: one could call findBlockingPiece for each direction, but this function exploits optimisations available when all directions are required.

findAttackerInDirection Source #

Arguments

:: MaybePieceByCoordinates 
-> LogicalColour

The defender's logical colour.

-> Coordinates

The defender's square.

-> Direction

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

-> Maybe (Coordinates, 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, from the specified direction (as seen by the target).
  • N.B.: there's no requirement for there to actually be a piece to attack at the specified target.

findAttackerInDirections Source #

Arguments

:: MaybePieceByCoordinates 
-> LogicalColour

The defender's logical colour.

-> Coordinates

The defender's square.

-> Maybe [Direction]

The directions from the coordinates of concern; the opposite direction from which an attacker might strike; Nothing implies omni-directional.

-> [(Coordinates, Rank)]

Any opposing pieces which can attack the specified square from the specified directions.

  • Find the coordinates of any attacker who can strike the specified coordinates, from the specified directions (as seen by the target).
  • N.B.: one could call findAttackerInDirection for each direction, but this function exploits optimisations available when all directions are required.

listDestinationsFor Source #

Arguments

:: MaybePieceByCoordinates 
-> Coordinates

The source for which destinations are required.

-> Piece

The piece at the specified source.

-> [(Coordinates, 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

:: MaybePieceByCoordinates 
-> Column

The column-magnification.

-> ColourScheme 
-> Bool

Whether to depict figurines.

-> (X, Y)

The origin from which axes are labelled.

-> String

The output suitable for display on a terminal.

Show the board using a two-dimensional representation.

Accessors

Predicates

isVacant :: MaybePieceByCoordinates -> Coordinates -> Bool Source #

Whether the specified coordinates are unoccupied.

isOccupied :: MaybePieceByCoordinates -> Coordinates -> Bool Source #

Whether the specified coordinates are occupied.

isClear Source #

Arguments

:: MaybePieceByCoordinates 
-> Coordinates

Source.

-> Coordinates

Destination.

-> Bool 
  • Whether the open interval (source, destination) is unobstructed.
  • CAVEAT: the move must be straight, so that all intermediate points lie on squares of the board.
  • N.B.: the specified end-points are uninspected.

isObstructed Source #

Arguments

:: MaybePieceByCoordinates 
-> Coordinates

Source.

-> Coordinates

Destination.

-> 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 :: MaybePieceByCoordinates -> Move -> 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.