| Copyright | (c) Mario Lang 2020 |
|---|---|
| License | BSD3 |
| Maintainer | mlang@blind.guru |
| Stability | experimental |
| Safe Haskell | None |
| Language | Haskell2010 |
Game.Chess
Description
A small collection of data types and functions to represent Chess positions and moves including move generation and parsing from external sources.
This module does deliberately not implement any search or evaluation functionality. It is intended to be used to lay the ground for communicating with other programs or players, hence the package name chessIO.
Synopsis
- data Color
- opponent :: Color -> Color
- data Sq
- isLight :: IsSquare sq => sq -> Bool
- isDark :: IsSquare sq => sq -> Bool
- data PieceType
- data Castle
- data Position
- startpos :: Position
- color :: Position -> Color
- moveNumber :: Position -> Int
- halfMoveClock :: Position -> Int
- pieceAt :: IsSquare sq => Position -> sq -> Maybe (Color, PieceType)
- inCheck :: Color -> Position -> Bool
- castlingRights :: Position -> [(Color, Castle)]
- canCastleKingside :: Position -> Bool
- canCastleQueenside :: Position -> Bool
- insufficientMaterial :: Position -> Bool
- repetitions :: [Position] -> Maybe (Int, Position)
- fromFEN :: String -> Maybe Position
- toFEN :: Position -> String
- positionTree :: Position -> Tree Position
- positionForest :: Position -> Forest Position
- newtype Ply = Ply Word16
- strictSAN :: forall s. (Stream s, SANToken (Token s), IsString (Tokens s)) => Position -> Parser s Ply
- relaxedSAN :: (Stream s, SANToken (Token s), IsString (Tokens s)) => Position -> Parser s Ply
- fromSAN :: (VisualStream s, TraversableStream s, SANToken (Token s), IsString (Tokens s)) => Position -> s -> Either String Ply
- toSAN :: IsString s => Position -> Ply -> s
- unsafeToSAN :: Position -> Ply -> String
- varToSAN :: IsString s => Position -> [Ply] -> s
- fromUCI :: Position -> String -> Maybe Ply
- toUCI :: Ply -> String
- fromPolyglot :: Position -> Ply -> Ply
- toPolyglot :: Position -> Ply -> Ply
- legalPlies :: Position -> [Ply]
- doPly :: Position -> Ply -> Position
- unsafeDoPly :: Position -> Ply -> Position
- plyTree :: Position -> Ply -> Tree Ply
- plyForest :: Position -> Forest Ply
Chess positions
Constructors
| A1 | |
| B1 | |
| C1 | |
| D1 | |
| E1 | |
| F1 | |
| G1 | |
| H1 | |
| A2 | |
| B2 | |
| C2 | |
| D2 | |
| E2 | |
| F2 | |
| G2 | |
| H2 | |
| A3 | |
| B3 | |
| C3 | |
| D3 | |
| E3 | |
| F3 | |
| G3 | |
| H3 | |
| A4 | |
| B4 | |
| C4 | |
| D4 | |
| E4 | |
| F4 | |
| G4 | |
| H4 | |
| A5 | |
| B5 | |
| C5 | |
| D5 | |
| E5 | |
| F5 | |
| G5 | |
| H5 | |
| A6 | |
| B6 | |
| C6 | |
| D6 | |
| E6 | |
| F6 | |
| G6 | |
| H6 | |
| A7 | |
| B7 | |
| C7 | |
| D7 | |
| E7 | |
| F7 | |
| G7 | |
| H7 | |
| A8 | |
| B8 | |
| C8 | |
| D8 | |
| E8 | |
| F8 | |
| G8 | |
| H8 |
Instances
| Eq PieceType Source # | |
| Ord PieceType Source # | |
| Show PieceType Source # | |
| Ix PieceType Source # | |
Defined in Game.Chess.Internal Methods range :: (PieceType, PieceType) -> [PieceType] # index :: (PieceType, PieceType) -> PieceType -> Int # unsafeIndex :: (PieceType, PieceType) -> PieceType -> Int # inRange :: (PieceType, PieceType) -> PieceType -> Bool # rangeSize :: (PieceType, PieceType) -> Int # unsafeRangeSize :: (PieceType, PieceType) -> Int # | |
Instances
The starting position as given by the FEN string "rnbqkbnrpppppppp8888PPPPPPPP/RNBQKBNR w KQkq - 0 1".
moveNumber :: Position -> Int Source #
number of the full move
halfMoveClock :: Position -> Int Source #
canCastleKingside :: Position -> Bool Source #
canCastleQueenside :: Position -> Bool Source #
insufficientMaterial :: Position -> Bool Source #
Converting from/to Forsyth-Edwards-Notation
Position tree
Chess moves
Converting from/to algebraic notation
strictSAN :: forall s. (Stream s, SANToken (Token s), IsString (Tokens s)) => Position -> Parser s Ply Source #
relaxedSAN :: (Stream s, SANToken (Token s), IsString (Tokens s)) => Position -> Parser s Ply Source #
fromSAN :: (VisualStream s, TraversableStream s, SANToken (Token s), IsString (Tokens s)) => Position -> s -> Either String Ply Source #
fromUCI :: Position -> String -> Maybe Ply Source #
Parse a move in the format used by the Universal Chess Interface protocol.
toUCI :: Ply -> String Source #
Convert a move to the format used by the Universal Chess Interface protocol.
Move generation
legalPlies :: Position -> [Ply] Source #
Generate a list of possible moves for the given position.
Executing moves
doPly :: Position -> Ply -> Position Source #
Apply a move to the given position.
This function checks if the move is actually legal and throws and error
if it isn't. See unsafeDoPly for a version that omits the legality check.
unsafeDoPly :: Position -> Ply -> Position Source #
An unsafe version of doPly. Only use this if you are sure the given move
can be applied to the position. This is useful if the move has been generated
by the moves function.