Copyright | (c) Mario Lang 2021 |
---|---|
License | BSD3 |
Maintainer | mlang@blind.guru |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Types for representing positions and plies and functions for move generation and application. Internally, quad bitboards are employed and plies are stored as 16 bit values. The move generation is fully compliant to the standard rules of Chess.
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.
The following modules implement more specific functionality:
- Game.Chess.ECO: Parse the Encyclopedia of Chess Openings and lookup positions
- Game.Chess.Polyglot: Polyglot opening book format
- Game.Chess.SAN: Parse and print Standard Algebraic Notation.
- Game.Chess.PGN: Parse and format Portable Game Notation files.
- Game.Chess.Tree: Functions for converting a position to a tree.
- Game.Chess.UCI: Control external engines using the Universal Chess Interface.
Synopsis
- data Color
- opponent :: Color -> Color
- data Square where
- pattern A1 :: Square
- pattern A2 :: Square
- pattern A3 :: Square
- pattern A4 :: Square
- pattern A5 :: Square
- pattern A6 :: Square
- pattern A7 :: Square
- pattern A8 :: Square
- pattern B1 :: Square
- pattern B2 :: Square
- pattern B3 :: Square
- pattern B4 :: Square
- pattern B5 :: Square
- pattern B6 :: Square
- pattern B7 :: Square
- pattern B8 :: Square
- pattern C1 :: Square
- pattern C2 :: Square
- pattern C3 :: Square
- pattern C4 :: Square
- pattern C5 :: Square
- pattern C6 :: Square
- pattern C7 :: Square
- pattern C8 :: Square
- pattern D1 :: Square
- pattern D2 :: Square
- pattern D3 :: Square
- pattern D4 :: Square
- pattern D5 :: Square
- pattern D6 :: Square
- pattern D7 :: Square
- pattern D8 :: Square
- pattern E1 :: Square
- pattern E2 :: Square
- pattern E3 :: Square
- pattern E4 :: Square
- pattern E5 :: Square
- pattern E6 :: Square
- pattern E7 :: Square
- pattern E8 :: Square
- pattern F1 :: Square
- pattern F2 :: Square
- pattern F3 :: Square
- pattern F4 :: Square
- pattern F5 :: Square
- pattern F6 :: Square
- pattern F7 :: Square
- pattern F8 :: Square
- pattern G1 :: Square
- pattern G2 :: Square
- pattern G3 :: Square
- pattern G4 :: Square
- pattern G5 :: Square
- pattern G6 :: Square
- pattern G7 :: Square
- pattern G8 :: Square
- pattern H1 :: Square
- pattern H2 :: Square
- pattern H3 :: Square
- pattern H4 :: Square
- pattern H5 :: Square
- pattern H6 :: Square
- pattern H7 :: Square
- pattern H8 :: Square
- rank :: Square -> Rank
- data Rank where
- mkRank :: HasCallStack => Int -> Rank
- unRank :: Rank -> Int
- file :: Square -> File
- data File where
- mkFile :: HasCallStack => Int -> File
- unFile :: File -> Int
- rankFile :: Iso' Square (Rank, File)
- mapRank :: (Rank -> Rank) -> Square -> Square
- mapFile :: (File -> File) -> Square -> Square
- isLight :: Square -> Bool
- isDark :: Square -> Bool
- rankChar :: Square -> Char
- fileChar :: Square -> Char
- toCoord :: IsString s => Square -> s
- data PieceType where
- data Castle
- data Position
- startpos :: Position
- color :: Position -> Color
- moveNumber :: Position -> Int
- halfMoveClock :: Position -> Int
- pieceAt :: Position -> Square -> 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)
- enPassantSquare :: Position -> Maybe Square
- fromFEN :: String -> Maybe Position
- toFEN :: Position -> String
- data Ply
- plySource :: Ply -> Square
- plyTarget :: Ply -> Square
- plyPromotion :: Ply -> Maybe PieceType
- move :: Square -> Square -> Ply
- promoteTo :: Ply -> PieceType -> Ply
- fromUCI :: Position -> String -> Maybe Ply
- toUCI :: Ply -> String
- legalPlies :: Position -> [Ply]
- legalPlies' :: Position -> Vector Ply
- doPly :: HasCallStack => Position -> Ply -> Position
- unsafeDoPly :: Position -> Ply -> Position
Chess positions
pattern A1 :: Square | |
pattern A2 :: Square | |
pattern A3 :: Square | |
pattern A4 :: Square | |
pattern A5 :: Square | |
pattern A6 :: Square | |
pattern A7 :: Square | |
pattern A8 :: Square | |
pattern B1 :: Square | |
pattern B2 :: Square | |
pattern B3 :: Square | |
pattern B4 :: Square | |
pattern B5 :: Square | |
pattern B6 :: Square | |
pattern B7 :: Square | |
pattern B8 :: Square | |
pattern C1 :: Square | |
pattern C2 :: Square | |
pattern C3 :: Square | |
pattern C4 :: Square | |
pattern C5 :: Square | |
pattern C6 :: Square | |
pattern C7 :: Square | |
pattern C8 :: Square | |
pattern D1 :: Square | |
pattern D2 :: Square | |
pattern D3 :: Square | |
pattern D4 :: Square | |
pattern D5 :: Square | |
pattern D6 :: Square | |
pattern D7 :: Square | |
pattern D8 :: Square | |
pattern E1 :: Square | |
pattern E2 :: Square | |
pattern E3 :: Square | |
pattern E4 :: Square | |
pattern E5 :: Square | |
pattern E6 :: Square | |
pattern E7 :: Square | |
pattern E8 :: Square | |
pattern F1 :: Square | |
pattern F2 :: Square | |
pattern F3 :: Square | |
pattern F4 :: Square | |
pattern F5 :: Square | |
pattern F6 :: Square | |
pattern F7 :: Square | |
pattern F8 :: Square | |
pattern G1 :: Square | |
pattern G2 :: Square | |
pattern G3 :: Square | |
pattern G4 :: Square | |
pattern G5 :: Square | |
pattern G6 :: Square | |
pattern G7 :: Square | |
pattern G8 :: Square | |
pattern H1 :: Square | |
pattern H2 :: Square | |
pattern H3 :: Square | |
pattern H4 :: Square | |
pattern H5 :: Square | |
pattern H6 :: Square | |
pattern H7 :: Square | |
pattern H8 :: Square |
pattern Rank1 :: Rank | |
pattern Rank2 :: Rank | |
pattern Rank3 :: Rank | |
pattern Rank4 :: Rank | |
pattern Rank5 :: Rank | |
pattern Rank6 :: Rank | |
pattern Rank7 :: Rank | |
pattern Rank8 :: Rank |
pattern FileA :: File | |
pattern FileB :: File | |
pattern FileC :: File | |
pattern FileD :: File | |
pattern FileE :: File | |
pattern FileF :: File | |
pattern FileG :: File | |
pattern FileH :: File |
pattern Pawn :: PieceType | |
pattern Knight :: PieceType | |
pattern Bishop :: PieceType | |
pattern Rook :: PieceType | |
pattern Queen :: PieceType | |
pattern King :: PieceType |
Instances
Ix PieceType Source # | |
Defined in Game.Chess.Internal 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 # | |
Show PieceType Source # | |
Eq PieceType Source # | |
Ord PieceType Source # | |
Defined in Game.Chess.Internal | |
Lift PieceType Source # | |
Instances
IsString Position Source # | |
Defined in Game.Chess.Internal fromString :: String -> Position # | |
Generic Position Source # | |
Show Position Source # | |
Binary Position Source # | |
NFData Position Source # | |
Defined in Game.Chess.Internal | |
Eq Position Source # | |
Ord Position Source # | |
Defined in Game.Chess.Internal | |
Hashable Position Source # | |
Defined in Game.Chess.Internal | |
Lift Position Source # | |
type Rep Position Source # | |
Defined in Game.Chess.Internal |
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
Chess moves
Instances
Convertion
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 :: HasCallStack => 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 legalPlies
function.