bishbosh-0.1.1.0: Plays chess.
Safe HaskellNone
LanguageHaskell2010

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 occurred, 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.
  • Two models of the board are simultaneously maintained; a square-centric model State.MaybePieceByCoordinates & a piece-centric model State.CoordinatesByRankByLogicalColour. Though maintenance of two models is a burden, the duality permits alternative implementations of the required searches, & often one is more efficient than the other.
Synopsis

Types

Type-synonyms

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

Instances details
(Enum x, Enum y, Ord x, Ord y) => Hashable2D Board x y Source # 
Instance details

Defined in BishBosh.State.Board

Methods

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

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

Defined in BishBosh.State.Board

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

Defined in BishBosh.State.Board

Methods

defineCoordinates :: Maybe Piece -> Coordinates x y -> Board x y -> Board x y Source #

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

Defined in BishBosh.State.Board

Methods

(==) :: Board x y -> Board x y -> Bool #

(/=) :: Board x y -> Board x y -> Bool #

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

Defined in BishBosh.State.Board

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

Defined in BishBosh.State.Board

Methods

showsPrec :: Int -> Board x y -> ShowS #

show :: Board x y -> String #

showList :: [Board x y] -> ShowS #

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

Defined in BishBosh.State.Board

Methods

def :: Board x y #

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

Defined in BishBosh.State.Board

Methods

rnf :: Board x y -> () #

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

Defined in BishBosh.State.Board

Methods

empty :: Board x y Source #

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

Defined in BishBosh.State.Board

Methods

showsEPD :: Board x y -> ShowS Source #

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

Defined in BishBosh.State.Board

Methods

readsEPD :: ReadS (Board x y) Source #

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

Defined in BishBosh.State.Board

Methods

showsFEN :: Board x y -> ShowS Source #

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

Defined in BishBosh.State.Board

Methods

readsFEN :: ReadS (Board x y) Source #

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

Defined in BishBosh.State.Board

Methods

reflectOnY :: Board x y -> Board x y Source #

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

Defined in BishBosh.State.Board

Methods

reflectOnX :: Board x y -> Board x y Source #

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.

summariseNDefendersByLogicalColour :: Board x y -> ArrayByLogicalColour NPieces Source #

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

sumPieceSquareValueByLogicalColour :: (Enum x, Enum y, Num pieceSquareValue, Ord x, Ord y) => PieceSquareByCoordinatesByRank x y pieceSquareValue -> Board x y -> ArrayByLogicalColour 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.

findAttackersOf Source #

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.

findAttacksBy Source #

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.

Constructors

Mutators

movePiece Source #

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.

Predicates

isKingChecked Source #

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.

exposesKing Source #

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.