bishbosh-0.1.4.0: Plays chess.
Safe HaskellNone
LanguageHaskell2010

BishBosh.Model.Game

Description

AUTHOR
Dr. Alistair Ward
DESCRIPTION
  • This module augments State.Board with the history of the game.
  • It therefore understands not only the current state of the board, but also; whose turn it is, whether Castling has occured, which Pawns have been promoted, when pieces were taken.
  • Moves made in this domain conform to the rules of chess, c.f. those made in State.Board.
Synopsis

Types

Type-synonyms

type Transformation = Game -> Game Source #

The type of a function which transforms a game.

Data-types

data Game Source #

  • The first three fields represent the state of the game.
  • These are augmented by the game's history, i.e. the sequence of moves.
  • For efficiency the list of available moves is stored.

Instances

Instances details
Eq Game Source # 
Instance details

Defined in BishBosh.Model.Game

Methods

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

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

Read Game Source # 
Instance details

Defined in BishBosh.Model.Game

Show Game Source # 
Instance details

Defined in BishBosh.Model.Game

Methods

showsPrec :: Int -> Game -> ShowS #

show :: Game -> String #

showList :: [Game] -> ShowS #

Default Game Source # 
Instance details

Defined in BishBosh.Model.Game

Methods

def :: Game #

NFData Game Source # 
Instance details

Defined in BishBosh.Model.Game

Methods

rnf :: Game -> () #

Empty Game Source # 
Instance details

Defined in BishBosh.Model.Game

Methods

empty :: Game Source #

ShowsEPD Game Source # 
Instance details

Defined in BishBosh.Model.Game

Methods

showsEPD :: Game -> ShowS Source #

ReadsEPD Game Source # 
Instance details

Defined in BishBosh.Model.Game

ShowsFEN Game Source # 
Instance details

Defined in BishBosh.Model.Game

Methods

showsFEN :: Game -> ShowS Source #

ReadsFEN Game Source # 
Instance details

Defined in BishBosh.Model.Game

Null Game Source # 
Instance details

Defined in BishBosh.Model.Game

Methods

isNull :: Game -> Bool Source #

ReflectableOnX Game Source #
Instance details

Defined in BishBosh.Model.Game

Methods

reflectOnX :: Game -> Game Source #

Hashable Game Source # 
Instance details

Defined in BishBosh.Model.Game

Methods

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

Functions

countPliesAvailableTo :: Game -> LogicalColour -> NPlies Source #

Count the number of plies available to the specified player.

rollBack :: Game -> [(Game, Turn)] Source #

  • Roll-back the specified game until the start, returning each previous game paired with the ply which was then made.
  • The list-head contains the most recent ply, while the tail contains the first.

sortAvailableQualifiedMoves :: AvailableQualifiedMoves -> AvailableQualifiedMoves Source #

Sort the lists of destinations to faciliate testing for equality.

findQualifiedMovesAvailableTo :: Game -> LogicalColour -> [QualifiedMove] Source #

  • Retrieve the recorded value, or generate the list of moves available to the player of the specified logical colour.
  • CAVEAT: doesn't account for game-termination.

findQualifiedMovesAvailableToNextPlayer :: Game -> [QualifiedMove] Source #

Retrieve the recorded value, or generate the list of moves available to the next player.

listTurns :: Game -> [Turn] Source #

Gets the sequence of turns, with the latest at the head & the opening one last.

listTurnsChronologically :: Game -> [Turn] Source #

Gets the sequence of turns in the order they occured.

maybeLastTurn :: Game -> Maybe Turn Source #

The last turn, if there was one.

validateQualifiedMove Source #

Arguments

:: Game

Prior to playing the qualified move.

-> QualifiedMove 
-> Maybe String

Error-message.

  • True if the specified move is valid, given the implied piece & the current state of the game.
  • N.B.: it is considered valid to take a King, one just never has the opportunity, since the game terminates the move before.

validateEitherQualifiedMove Source #

Arguments

:: Game

Prior to playing the move.

-> EitherQualifiedMove 
-> Maybe String

Error-message.

Validates the move-type then forwards the request to validateQualifiedMove.

updateIncrementalPositionHash Source #

Arguments

:: Bits positionHash 
=> Game

The game before application of the last move.

-> positionHash

The value before application of the last move.

-> Game

The current game.

-> Zobrist positionHash 
-> positionHash 

Update the position-hash of the game prior to application of the last move.

Constructors

mkPosition :: Game -> Position Source #

Constructor.

mkGame Source #

Arguments

:: LogicalColour

The player who is required to move next.

-> CastleableRooksByLogicalColour 
-> Board 
-> TurnsByLogicalColour 
-> Game 

Smart constructor.

fromBoard :: Board -> Game Source #

Constructor. For convenience, the following assumptions are made in the absence of any move-history:

  • The next player's logical colour is assumed to be White;
  • Provided that the King is at its starting coordinates, then all Rooks which exist at their starting coordinates are considered to be castleable;
  • There're zero previous turns.

mkAvailableQualifiedMovesFor :: Game -> LogicalColour -> AvailableQualifiedMoves Source #

Construct AvailableQualifiedMoves for the player of the specified logical colour.

Mutators

takeTurn :: Turn -> Transformation Source #

  • Moves the referenced piece between the specified coordinates.
  • As a result of the turn, the next logical colour is changed, the moves available to each player are updated, & any reason for game-termination recorded.
  • CAVEAT: no validation of the turn is performed since the move may have been automatically selected & therefore known to be valid.
  • CAVEAT: doesn't account for any previous game-termination when updating getAvailableQualifiedMovesByLogicalColour.

applyQualifiedMove :: QualifiedMove -> Transformation Source #

Construct a turn & relay the request to takeTurn.

applyEitherQualifiedMove :: EitherQualifiedMove -> Transformation Source #

Construct a qualifiedMove & relay the request to "applyQualifiedMove".

applyEitherQualifiedMoves Source #

Arguments

:: (a -> Either String EitherQualifiedMove)

A constructor which can return an error-message.

-> Game

The game to which the moves should be sequentially applied.

-> [a]

An ordered sequence of data from which moves are constructed.

-> Either (a, String) Game

Either a rogue datum & the corresponding error-message, or the resulting game.

Constructs eitherQualifiedMoves from the data provided, validating & applying each in the specified order.

updateTerminationReasonWith :: Result -> Transformation Source #

Provided that the game hasn't already terminated, update the termination-reason according to whether the specified result implies either a draw by agreement or a resignation.

resign :: Transformation Source #

Resignation by the player who currently holds the choice of move.

Predicates

isValidQualifiedMove :: Game -> QualifiedMove -> Bool Source #

Whether the specified QualifiedMove is valid.

isValidEitherQualifiedMove :: Game -> EitherQualifiedMove -> Bool Source #

Whether the specified EitherQualifiedMove is valid.

isTerminated :: Game -> Bool Source #

Whether the game has been terminated.

(=~) :: Game -> Game -> Bool infix 4 Source #

  • Whether the specified game's positions have converged, & despite perhaps having reached this position from different move-sequences, now have equal opportunities.
  • CAVEAT: this is different from equality.
  • CAVEAT: this test doesn't account for the possibility that one game may more quickly be drawn according to either the "Seventy-five-move Rule" or "Five-fold Repetition".
  • CAVEAT: though convenient, this function shouldn't be called for repeated tests against a constant position, resulting in unnecessary repeated construction of that position.

(/~) :: Game -> Game -> Bool infix 4 Source #

Whether the state of the specified games is different.