bishbosh-0.1.3.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 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
Eq Board Source # 
Instance details

Defined in BishBosh.State.Board

Methods

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

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

Read Board Source # 
Instance details

Defined in BishBosh.State.Board

Show Board Source # 
Instance details

Defined in BishBosh.State.Board

Methods

showsPrec :: Int -> Board -> ShowS #

show :: Board -> String #

showList :: [Board] -> ShowS #

Default Board Source # 
Instance details

Defined in BishBosh.State.Board

Methods

def :: Board #

NFData Board Source # 
Instance details

Defined in BishBosh.State.Board

Methods

rnf :: Board -> () #

Empty Board Source # 
Instance details

Defined in BishBosh.State.Board

Methods

empty :: Board Source #

ShowsEPD Board Source # 
Instance details

Defined in BishBosh.State.Board

Methods

showsEPD :: Board -> ShowS Source #

ReadsEPD Board Source # 
Instance details

Defined in BishBosh.State.Board

ShowsFEN Board Source # 
Instance details

Defined in BishBosh.State.Board

Methods

showsFEN :: Board -> ShowS Source #

ReadsFEN Board Source # 
Instance details

Defined in BishBosh.State.Board

ReflectableOnY Board Source # 
Instance details

Defined in BishBosh.State.Board

ReflectableOnX Board Source # 
Instance details

Defined in BishBosh.State.Board

SelfValidating Board Source # 
Instance details

Defined in BishBosh.State.Board

Hashable Board Source # 
Instance details

Defined in BishBosh.State.Board

Methods

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

Seeker Board Source # 
Instance details

Defined in BishBosh.State.Board

Mutator Board Source # 
Instance details

Defined in BishBosh.State.Board

Functions

countDefendersByCoordinatesByLogicalColour :: Board -> NDefendersByCoordinatesByLogicalColour Source #

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

summariseNDefendersByLogicalColour :: Board -> ArrayByLogicalColour NPieces Source #

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

sumPieceSquareValueByLogicalColour Source #

Arguments

:: PieceSquareByCoordinatesByRank 
-> Board 
-> ArrayByLogicalColour Base

Sum of PieceSquareValues.

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

:: Board 
-> LogicalColour

The defender's logical colour.

-> Coordinates

The defender's location.

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

:: Board 
-> Piece

The type of attacker.

-> Coordinates

The defender's location.

-> [Coordinates]

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

:: Move

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 
  • Moves the referenced piece.
  • CAVEAT: no validation is performed.
  • CAVEAT: castling must be implemented by making two calls.

Predicates

isKingChecked Source #

Arguments

:: Board 
-> LogicalColour

The logical colour of the King in question.

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

:: Board

The original board, i.e. prior to the move.

-> LogicalColour

The logical colour of the player proposing to move.

-> Move

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.