Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
Pawn
s 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
- type Transformation = Game -> Game
- data Game
- countPliesAvailableTo :: Game -> LogicalColour -> NPlies
- rollBack :: Game -> [(Game, Turn)]
- sortAvailableQualifiedMoves :: AvailableQualifiedMoves -> AvailableQualifiedMoves
- findQualifiedMovesAvailableTo :: Game -> LogicalColour -> [QualifiedMove]
- findQualifiedMovesAvailableToNextPlayer :: Game -> [QualifiedMove]
- listTurns :: Game -> [Turn]
- listTurnsChronologically :: Game -> [Turn]
- maybeLastTurn :: Game -> Maybe Turn
- validateQualifiedMove :: Game -> QualifiedMove -> Maybe String
- validateEitherQualifiedMove :: Game -> EitherQualifiedMove -> Maybe String
- updateIncrementalPositionHash :: Bits positionHash => Game -> positionHash -> Game -> Zobrist positionHash -> positionHash
- mkPosition :: Game -> Position
- mkGame :: LogicalColour -> CastleableRooksByLogicalColour -> Board -> TurnsByLogicalColour -> Game
- fromBoard :: Board -> Game
- mkAvailableQualifiedMovesFor :: Game -> LogicalColour -> AvailableQualifiedMoves
- takeTurn :: Turn -> Transformation
- applyQualifiedMove :: QualifiedMove -> Transformation
- applyEitherQualifiedMove :: EitherQualifiedMove -> Transformation
- applyEitherQualifiedMoves :: (a -> Either String EitherQualifiedMove) -> Game -> [a] -> Either (a, String) Game
- updateTerminationReasonWith :: Result -> Transformation
- resign :: Transformation
- isValidQualifiedMove :: Game -> QualifiedMove -> Bool
- isValidEitherQualifiedMove :: Game -> EitherQualifiedMove -> Bool
- isTerminated :: Game -> Bool
- cantConverge :: Game -> Game -> Bool
- (=~) :: Game -> Game -> Bool
- (/~) :: Game -> Game -> Bool
Types
Type-synonyms
type Transformation = Game -> Game Source #
The type of a function which transforms a game.
Data-types
- 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
Eq Game Source # | |
Read Game Source # | |
Show Game Source # | |
Default Game Source # | |
Defined in BishBosh.Model.Game | |
NFData Game Source # | |
Defined in BishBosh.Model.Game | |
Empty Game Source # | |
Defined in BishBosh.Model.Game | |
ShowsEPD Game Source # | |
ReadsEPD Game Source # | |
ShowsFEN Game Source # | |
ReadsFEN Game Source # | |
Null Game Source # | |
ReflectableOnX Game Source # |
|
Defined in BishBosh.Model.Game reflectOnX :: Game -> Game Source # | |
Hashable Game Source # | |
Defined in BishBosh.Model.Game 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.
validateQualifiedMove Source #
:: 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 #
:: Game | Prior to playing the move. |
-> EitherQualifiedMove | |
-> Maybe String | Error-message. |
Validates the move-type then forwards the request to validateQualifiedMove
.
updateIncrementalPositionHash Source #
:: 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.
:: 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 allRook
s 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 #
:: (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.
cantConverge :: Game -> Game -> Bool Source #
Forwards request to State.CastleableRooksByLogicalColour.
(=~) :: 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.