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.
- type NGames = Int
- type Transformation x y = Game x y -> Game x y
- data Game x y
- countMovesAvailableTo :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => LogicalColour -> Game x y -> NMoves
- rollBack :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => Game x y -> [(Game x y, Turn x y)]
- sortAvailableQualifiedMoves :: (Ord x, Ord y) => AvailableQualifiedMoves x y -> AvailableQualifiedMoves x y
- findQualifiedMovesAvailableTo :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => LogicalColour -> Game x y -> [QualifiedMove x y]
- findQualifiedMovesAvailableToNextPlayer :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => Game x y -> [QualifiedMove x y]
- listTurns :: Game x y -> [Turn x y]
- listTurnsChronologically :: Game x y -> [Turn x y]
- maybeLastTurn :: Game x y -> Maybe (Turn x y)
- validateQualifiedMove :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => QualifiedMove x y -> Game x y -> Maybe String
- validateEitherQualifiedMove :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => EitherQualifiedMove x y -> Game x y -> Maybe String
- incrementalHash :: (Ix x, Bits positionHash, Enum x, Enum y, Ord y) => Game x y -> positionHash -> Game x y -> Zobrist x y positionHash -> positionHash
- mkPosition :: (Enum x, Enum y, Ord x, Ord y) => Game x y -> Position x y
- mkGame :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => LogicalColour -> CastleableRooksByLogicalColour x -> Board x y -> TurnsByLogicalColour x y -> Game x y
- fromBoard :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => Board x y -> Game x y
- mkAvailableQualifiedMovesFor :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => LogicalColour -> Game x y -> AvailableQualifiedMoves x y
- takeTurn :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => Turn x y -> Transformation x y
- applyQualifiedMove :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => QualifiedMove x y -> Transformation x y
- applyEitherQualifiedMove :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => EitherQualifiedMove x y -> Transformation x y
- applyEitherQualifiedMoves :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => (a -> Either String (EitherQualifiedMove x y)) -> Game x y -> [a] -> Either (a, String) (Game x y)
- updateTerminationReasonWith :: Result -> Transformation x y
- resign :: Transformation x y
- isValidQualifiedMove :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => QualifiedMove x y -> Game x y -> Bool
- isValidEitherQualifiedMove :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => EitherQualifiedMove x y -> Game x y -> Bool
- isTerminated :: Game x y -> Bool
- cantConverge :: Game x y -> Game x y -> Bool
- (=~) :: (Enum x, Enum y, Ord x, Ord y) => Game x y -> Game x y -> Bool
- (/~) :: (Enum x, Enum y, Ord x, Ord y) => Game x y -> Game x y -> Bool
Types
Type-synonyms
type Transformation x y = Game x y -> Game x y 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.
(Ix x, Enum x, Enum y, Ord y) => Hashable2D Game x y Source # | |
(Enum x, Enum y, Ord x, Ord y) => Eq (Game x y) Source # | |
(Enum x, Enum y, Ord x, Ord y, Read x, Read y, Show x, Show y) => Read (Game x y) Source # | |
(Enum x, Enum y, Ord x, Ord y, Show x, Show y) => Show (Game x y) Source # | |
(NFData x, NFData y) => NFData (Game x y) Source # | |
(Enum x, Enum y, Ord x, Ord y, Show x, Show y) => Default (Game x y) Source # | |
(Enum x, Enum y, Ord x, Ord y, Show x, Show y) => Empty (Game x y) Source # | |
(Enum x, Enum y, Ord x, Ord y) => ShowsFEN (Game x y) Source # | |
(Enum x, Enum y, Ord x, Ord y, Read x, Read y, Show x, Show y) => ReadsFEN (Game x y) Source # | |
Null (Game x y) Source # | |
(Enum x, Enum y, Ord x, Ord y, Show x, Show y) => ReflectableOnX (Game x y) Source # |
|
Functions
countMovesAvailableTo :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => LogicalColour -> Game x y -> NMoves Source #
Count the number of moves available to the specified player.
rollBack :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => Game x y -> [(Game x y, Turn x y)] 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 :: (Ord x, Ord y) => AvailableQualifiedMoves x y -> AvailableQualifiedMoves x y Source #
Sort the lists of destinations to faciliate testing for equality.
findQualifiedMovesAvailableTo :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => LogicalColour -> Game x y -> [QualifiedMove x y] 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 :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => Game x y -> [QualifiedMove x y] Source #
Retrieve the recorded value, or generate the list of moves available to the next player.
listTurns :: Game x y -> [Turn x y] Source #
Gets the sequence of turns, with the latest at the head & the opening one last.
listTurnsChronologically :: Game x y -> [Turn x y] Source #
Gets the sequence of turns in the order they occured.
validateQualifiedMove Source #
:: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) | |
=> QualifiedMove x y | |
-> Game x y | Prior to playing the qualified move. |
-> 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 #
:: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) | |
=> EitherQualifiedMove x y | |
-> Game x y | Prior to playing the move. |
-> Maybe String | Error-message. |
Validates the move-type than forwards the request to validateQualifiedMove
.
:: (Ix x, Bits positionHash, Enum x, Enum y, Ord y) | |
=> Game x y | The game before application of the last move. |
-> positionHash | The value before application of the last move. |
-> Game x y | The current game. |
-> Zobrist x y positionHash | |
-> positionHash |
Amend the position-hash of the game prior to application of the last move.
Constructors
:: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) | |
=> LogicalColour | The player who is required to move next. |
-> CastleableRooksByLogicalColour x | |
-> Board x y | |
-> TurnsByLogicalColour x y | |
-> Game x y |
Smart constructor.
fromBoard :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => Board x y -> Game x y 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 :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => LogicalColour -> Game x y -> AvailableQualifiedMoves x y Source #
Construct AvailableQualifiedMoves
for the player of the specified logical colour.
Mutators
takeTurn :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => Turn x y -> Transformation x y 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 :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => QualifiedMove x y -> Transformation x y Source #
Construct a turn & relay the request to takeTurn
.
applyEitherQualifiedMove :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => EitherQualifiedMove x y -> Transformation x y Source #
Construct a qualifiedMove & relay the request to "applyQualifiedMove".
applyEitherQualifiedMoves Source #
:: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) | |
=> (a -> Either String (EitherQualifiedMove x y)) | A constructor which can return an error-message. |
-> Game x y | 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 x y) | 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 x y 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 x y Source #
Resignation by the player who currently holds the choice of move.
Predicates
isValidQualifiedMove :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => QualifiedMove x y -> Game x y -> Bool Source #
Whether the specified qualifiedMove is valid.
isValidEitherQualifiedMove :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => EitherQualifiedMove x y -> Game x y -> Bool Source #
Whether the specified eitherQualifiedMove is valid.
isTerminated :: Game x y -> Bool Source #
Whether the game has been terminated.
cantConverge :: Game x y -> Game x y -> Bool Source #
Forwards request to State.CastleableRooksByLogicalColour.
(=~) :: (Enum x, Enum y, Ord x, Ord y) => Game x y -> Game x y -> 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.