Safe Haskell | None |
---|---|

Language | Haskell2010 |

`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

- data MaybePieceByCoordinates x y
- inferMoveType :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => Move x y -> Maybe Rank -> MaybePieceByCoordinates x y -> MoveType
- findPieces :: (Enum x, Enum y, Ord x, Ord y) => MaybePieceByCoordinates x y -> [LocatedPiece x y]
- findBlockingPiece :: (Enum x, Enum y, Ord x, Ord y) => Direction -> Coordinates x y -> MaybePieceByCoordinates x y -> Maybe (LocatedPiece x y)
- findProximateKnights :: (Enum x, Enum y, Ord x, Ord y) => LogicalColour -> Coordinates x y -> MaybePieceByCoordinates x y -> [Coordinates x y]
- findAttackerInDirection :: (Enum x, Enum y, Ord x, Ord y) => LogicalColour -> Direction -> Coordinates x y -> MaybePieceByCoordinates x y -> Maybe (Coordinates x y, Rank)
- sumPieceSquareValueByLogicalColour :: (Enum x, Enum y, Num pieceSquareValue, Ord x, Ord y) => FindPieceSquareValue x y pieceSquareValue -> MaybePieceByCoordinates x y -> [pieceSquareValue]
- listDestinationsFor :: (Enum x, Enum y, Ord x, Ord y) => Coordinates x y -> Piece -> MaybePieceByCoordinates x y -> [(Coordinates x y, Maybe Rank)]
- show2D :: (Enum x, Enum y, Integral column, Ord x, Ord y) => column -> ColourScheme -> (Int, Int) -> MaybePieceByCoordinates x y -> String
- dereference :: (Enum x, Enum y, Ord x, Ord y) => Coordinates x y -> MaybePieceByCoordinates x y -> Maybe Piece
- defineCoordinates :: (Enum x, Enum y, Ord x, Ord y) => Maybe Piece -> Coordinates x y -> Transformation x y
- movePiece :: (Enum x, Enum y, Ord x, Ord y) => Move x y -> Piece -> Maybe (Coordinates x y) -> Transformation x y
- isVacant :: (Enum x, Enum y, Ord x, Ord y) => Coordinates x y -> MaybePieceByCoordinates x y -> Bool
- isOccupied :: (Enum x, Enum y, Ord x, Ord y) => Coordinates x y -> MaybePieceByCoordinates x y -> Bool
- isClear :: (Enum x, Enum y, Ord x, Ord y) => Coordinates x y -> Coordinates x y -> MaybePieceByCoordinates x y -> Bool
- isObstructed :: (Enum x, Enum y, Ord x, Ord y) => Coordinates x y -> Coordinates x y -> MaybePieceByCoordinates x y -> Bool
- isEnPassantMove :: (Enum x, Enum y, Ord x, Ord y) => Move x y -> MaybePieceByCoordinates x y -> Bool

# Types

## Type-synonyms

## Data-types

data MaybePieceByCoordinates x y Source #

## Instances

# Constants

# Functions

:: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) | |

=> Move x y | |

-> Maybe Rank | The |

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

:: (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.

:: (Enum x, Enum y, Ord x, Ord y) | |

=> LogicalColour | The |

-> Coordinates x y | The destination to which the |

-> MaybePieceByCoordinates x y | |

-> [Coordinates x y] |

- Find any
`Knight`

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

:: (Enum x, Enum y, Ord x, Ord y) | |

=> LogicalColour | The defender's |

-> Direction | The |

-> Coordinates x y | The defender's square. |

-> MaybePieceByCoordinates x y | |

-> Maybe (Coordinates x y, Rank) | Any opposing |

- 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 *piece*s of either side.

:: (Enum x, Enum y, Ord x, Ord y) | |

=> Coordinates x y | The source for which destinations are required. |

-> Piece | The |

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

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

:: (Enum x, Enum y, Ord x, Ord y) | |

=> Maybe Piece | The optional |

-> Coordinates x y | The |

-> Transformation x y |

Define the specified *coordinates*, by either placing or removing a *piece*.

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

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

:: (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.

:: (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.