-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Basic chess library
--
-- A simple and fast library for generating legal chess moves. Also
-- includes a module for communication with external processes that speak
-- the UCI (Universal Chess Interface) protocol, a PGN parser/pretty
-- printer, and Polyglot opening book support. On top of that, provides a
-- console frontend program (cboard) that can be used to interactively
-- play against UCI engines, and a terminal program (cbookview) to
-- explore commonly played chess openings.
@package chessIO
@version 0.7.0.0
-- | 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:
--
--
module Game.Chess
data Color
Black :: Color
White :: Color
opponent :: Color -> Color
data Square
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
pattern Rank1 :: Rank
pattern Rank2 :: Rank
pattern Rank3 :: Rank
pattern Rank4 :: Rank
pattern Rank5 :: Rank
pattern Rank6 :: Rank
pattern Rank7 :: Rank
pattern Rank8 :: Rank
file :: Square -> File
data File
pattern FileA :: File
pattern FileB :: File
pattern FileC :: File
pattern FileD :: File
pattern FileE :: File
pattern FileF :: File
pattern FileG :: File
pattern FileH :: File
rankFile :: Iso' Square (Rank, File)
isLight :: Square -> Bool
isDark :: Square -> Bool
rankChar :: Square -> Char
fileChar :: Square -> Char
toCoord :: IsString s => Square -> s
data PieceType
Pawn :: PieceType
Knight :: PieceType
Bishop :: PieceType
Rook :: PieceType
Queen :: PieceType
King :: PieceType
data Castle
Kingside :: Castle
Queenside :: Castle
data Position
-- | The starting position as given by the FEN string
-- "rnbqkbnrpppppppp8888PPPPPPPP/RNBQKBNR w KQkq - 0
-- 1".
startpos :: Position
-- | active color
color :: Position -> Color
-- | number of the full move
moveNumber :: Position -> Int
halfMoveClock :: Position -> Int
pieceAt :: Position -> Square -> Maybe (Color, PieceType)
-- | Returns True if Color is in check in the given position.
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
-- | Construct a position from Forsyth-Edwards-Notation.
fromFEN :: String -> Maybe Position
-- | Convert a position to Forsyth-Edwards-Notation.
toFEN :: Position -> String
data Ply
plySource :: Ply -> Square
plyTarget :: Ply -> Square
plyPromotion :: Ply -> Maybe PieceType
-- | Parse a move in the format used by the Universal Chess Interface
-- protocol.
fromUCI :: Position -> String -> Maybe Ply
-- | Convert a move to the format used by the Universal Chess Interface
-- protocol.
toUCI :: Ply -> String
fromPolyglot :: Position -> Ply -> Ply
toPolyglot :: Position -> Ply -> Ply
-- | Generate a list of possible moves for the given position.
legalPlies :: Position -> [Ply]
-- | 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.
doPly :: HasCallStack => Position -> Ply -> Position
-- | 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.
unsafeDoPly :: Position -> Ply -> Position
-- | Parsers and printers for Algebraic Notation.
module Game.Chess.SAN
fromSAN :: (VisualStream s, TraversableStream s, SANToken (Token s), IsString (Tokens s)) => Position -> s -> Either String Ply
toSAN :: (HasCallStack, IsString s) => Position -> Ply -> s
unsafeToSAN :: Position -> Ply -> String
class SANToken a
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
varToSAN :: (MonoFoldable variation, Element variation ~ Ply, IsString string) => Position -> variation -> string
instance GHC.Show.Show Game.Chess.SAN.From
instance GHC.Classes.Eq Game.Chess.SAN.From
instance GHC.Show.Show Game.Chess.SAN.SANStatus
instance GHC.Read.Read Game.Chess.SAN.SANStatus
instance GHC.Classes.Eq Game.Chess.SAN.SANStatus
instance Game.Chess.SAN.SANToken GHC.Types.Char
instance Game.Chess.SAN.SANToken GHC.Word.Word8
-- | A PGN file consists of a list of games. Each game consists of a tag
-- list, the outcome, and a forest of rosetrees.
module Game.Chess.PGN
readPGNFile :: MonadIO m => FilePath -> m (Either String PGN)
gameFromForest :: [(ByteString, Text)] -> Forest Ply -> Outcome -> Game
pgnForest :: PGN -> Forest Ply
newtype PGN
PGN :: [Game] -> PGN
type Game = ([(ByteString, Text)], (Outcome, Forest PlyData))
data Outcome
Win :: Color -> Outcome
Draw :: Outcome
Undecided :: Outcome
data PlyData
PlyData :: ![Int] -> !Ply -> ![Int] -> PlyData
[prefixNAG] :: PlyData -> ![Int]
[pgnPly] :: PlyData -> !Ply
[suffixNAG] :: PlyData -> ![Int]
pgn :: Parser PGN
hPutPGN :: Handle -> RAVOrder (Doc ann) -> PGN -> IO ()
pgnDoc :: RAVOrder (Doc ann) -> PGN -> Doc ann
type RAVOrder a = (Forest PlyData -> a) -> Forest PlyData -> [a]
breadthFirst :: RAVOrder a
depthFirst :: RAVOrder a
gameDoc :: RAVOrder (Doc ann) -> Game -> Doc ann
weightedForest :: PGN -> Forest (Rational, Ply)
instance GHC.Show.Show Game.Chess.PGN.Outcome
instance GHC.Classes.Eq Game.Chess.PGN.Outcome
instance GHC.Show.Show Game.Chess.PGN.PlyData
instance GHC.Classes.Eq Game.Chess.PGN.PlyData
instance GHC.Base.Semigroup Game.Chess.PGN.PGN
instance GHC.Base.Monoid Game.Chess.PGN.PGN
instance GHC.Classes.Eq Game.Chess.PGN.PGN
instance GHC.Classes.Ord Game.Chess.PGN.Outcome
instance Prettyprinter.Internal.Pretty Game.Chess.PGN.Outcome
module Game.Chess.Polyglot
-- | A Polyglot opening book.
data PolyglotBook
defaultBook :: PolyglotBook
twic :: PolyglotBook
-- | Create a PolyglotBook from a ByteString.
fromByteString :: ByteString -> PolyglotBook
toByteString :: PolyglotBook -> ByteString
readPolyglotFile :: FilePath -> IO PolyglotBook
writePolyglotFile :: FilePath -> PolyglotBook -> IO ()
makeBook :: PGN -> PolyglotBook
toPGN :: PolyglotBook -> Position -> PGN
-- | Pick a random ply from the book.
bookPly :: RandomGen g => PolyglotBook -> Position -> Maybe (Rand g Ply)
-- | Probe the book for all plies known for the given position.
bookPlies :: PolyglotBook -> Position -> [Ply]
bookForest :: PolyglotBook -> Position -> Forest Ply
-- | Predicted Variations. Return the most popular game.
variations :: PolyglotBook -> Position -> [[Ply]]
findPosition :: PolyglotBook -> Position -> [BookEntry]
instance GHC.Show.Show Game.Chess.Polyglot.BookEntry
instance GHC.Classes.Eq Game.Chess.Polyglot.BookEntry
instance GHC.Classes.Eq Game.Chess.Polyglot.PolyglotBook
instance GHC.Classes.Ord Game.Chess.Polyglot.BookEntry
instance Foreign.Storable.Storable Game.Chess.Polyglot.BookEntry
-- | Types and functions to name chess positions according to the opening
-- used.
--
-- Two commonly used file formats for opening classification are
-- supported.
module Game.Chess.ECO
-- | Encyclopedia of Chess Openings
data ECO
-- | A Chess Opening
data Opening
CO :: !Text -> !Text -> !Maybe Text -> !Vector Ply -> Opening
[coCode] :: Opening -> !Text
[coName] :: Opening -> !Text
[coVariation] :: Opening -> !Maybe Text
[coPlies] :: Opening -> !Vector Ply
defaultECO :: ECO
-- | Retrieve the opening for a particular position
lookup :: Position -> ECO -> Maybe Opening
fromList :: [Opening] -> ECO
toList :: ECO -> [Opening]
-- | Convert a PGN database to ECO assuming the ECO, Opening and Variation
-- tags are being used to identify chess openings.
fromPGN :: PGN -> ECO
readECOPGNFile :: MonadIO m => FilePath -> m (Either String ECO)
readSCIDECOFile :: MonadIO m => FilePath -> m (Either String ECO)
-- | A parser for opening databases in SCID .eco format
scid :: Parser ECO
embedECO :: FileReader -> FilePath -> Q (TExp ECO)
-- | Parse an ECO database in .pgn format
ecoPgn :: FileReader
-- | Parse an ECO database in .eco format
scidEco :: FileReader
module Game.Chess.Tree
positionTree :: Position -> Tree Position
positionForest :: Position -> Forest Position
plyTree :: Position -> Ply -> Tree Ply
plyForest :: Position -> Forest Ply
-- | The Universal Chess Interface (UCI) is a protocol for communicating
-- with external Chess engines.
module Game.Chess.UCI
data UCIException
IllegalMove :: Ply -> UCIException
data Engine
type BestMove = Maybe (Ply, Maybe Ply)
name :: Engine -> Maybe ByteString
author :: Engine -> Maybe ByteString
-- | Start a UCI engine with the given executable name and command line
-- arguments.
start :: String -> [String] -> IO (Maybe Engine)
-- | Start a UCI engine with the given timeout for initialisation.
--
-- If the engine takes more then the given microseconds to answer to the
-- initialisation request, Nothing is returned and the external
-- process will be terminated.
start' :: KnownDivRat unit Microsecond => Time unit -> (String -> IO ()) -> String -> [String] -> IO (Maybe Engine)
data Option
CheckBox :: Bool -> Option
ComboBox :: ByteString -> [ByteString] -> Option
[comboBoxValue] :: Option -> ByteString
[comboBoxValues] :: Option -> [ByteString]
SpinButton :: Int -> Option
[spinButtonValue, spinButtonMinBound, spinButtonMaxBound] :: Option -> Int
OString :: ByteString -> Option
Button :: Option
options :: Engine -> HashMap ByteString Option
getOption :: ByteString -> Engine -> Maybe Option
-- | Set a spin option to a particular value.
--
-- Bounds are validated. Make sure you don't set a value which is out of
-- range.
setOptionSpinButton :: MonadIO m => ByteString -> Int -> Engine -> m Engine
setOptionString :: MonadIO m => ByteString -> ByteString -> Engine -> m Engine
-- | Wait until the engine is ready to take more commands.
isready :: Engine -> IO ()
-- | Return the final position of the currently active game.
currentPosition :: MonadIO m => Engine -> m Position
-- | Set the starting position of the current game, also clearing any
-- pre-existing history.
setPosition :: MonadIO m => Engine -> Position -> m (Position, [Ply])
-- | Add a Move to the game history.
--
-- This function checks if the move is actually legal, and throws a
-- UCIException if it isn't.
addPly :: MonadIO m => Engine -> Ply -> m ()
replacePly :: MonadIO m => Engine -> Ply -> m ()
data Info
PV :: !Vector Ply -> Info
Depth :: !Int -> Info
SelDepth :: !Int -> Info
Elapsed :: !Time Millisecond -> Info
MultiPV :: !Int -> Info
Score :: !Score -> Maybe Bounds -> Info
Nodes :: !Int -> Info
NPS :: !Int -> Info
TBHits :: !Int -> Info
HashFull :: !Int -> Info
CurrMove :: !Ply -> Info
CurrMoveNumber :: !Int -> Info
String :: !ByteString -> Info
data Score
CentiPawns :: Int -> Score
MateIn :: Int -> Score
data Bounds
UpperBound :: Bounds
LowerBound :: Bounds
-- | Instruct the engine to begin searching.
search :: MonadIO m => Engine -> [SearchParam] -> m (TChan BestMove, TChan [Info])
searching :: MonadIO m => Engine -> m Bool
data SearchParam
searchmoves :: [Ply] -> SearchParam
ponder :: SearchParam
timeleft :: KnownDivRat unit Millisecond => Color -> Time unit -> SearchParam
timeincrement :: KnownDivRat unit Millisecond => Color -> Time unit -> SearchParam
movestogo :: Natural -> SearchParam
movetime :: KnownDivRat unit Millisecond => Time unit -> SearchParam
nodes :: Natural -> SearchParam
depth :: Natural -> SearchParam
infinite :: SearchParam
-- | Switch a ponder search to normal search when the pondered move was
-- played.
ponderhit :: MonadIO m => Engine -> m ()
-- | Stop a search in progress.
stop :: MonadIO m => Engine -> m ()
-- | Quit the engine.
quit :: MonadIO m => Engine -> m (Maybe ExitCode)
quit' :: (KnownDivRat unit Microsecond, MonadIO m) => Time unit -> Engine -> m (Maybe ExitCode)
instance GHC.Show.Show Game.Chess.UCI.UCIException
instance GHC.Show.Show Game.Chess.UCI.Score
instance GHC.Classes.Ord Game.Chess.UCI.Score
instance GHC.Classes.Eq Game.Chess.UCI.Score
instance GHC.Show.Show Game.Chess.UCI.Bounds
instance GHC.Classes.Eq Game.Chess.UCI.Bounds
instance GHC.Show.Show Game.Chess.UCI.Info
instance GHC.Classes.Eq Game.Chess.UCI.Info
instance GHC.Show.Show Game.Chess.UCI.Option
instance GHC.Classes.Eq Game.Chess.UCI.Option
instance GHC.Show.Show Game.Chess.UCI.Command
instance GHC.Show.Show Game.Chess.UCI.SearchParam
instance GHC.Classes.Eq Game.Chess.UCI.SearchParam
instance Data.String.IsString Game.Chess.UCI.Option
instance GHC.Exception.Type.Exception Game.Chess.UCI.UCIException