-- 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. @package chessIO @version 0.9.4.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 mkRank :: HasCallStack => Int -> Rank unRank :: Rank -> Int 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 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 pattern Pawn :: PieceType pattern Knight :: PieceType pattern Bishop :: PieceType pattern Rook :: PieceType pattern Queen :: PieceType pattern 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 move :: Square -> Square -> Ply promoteTo :: Ply -> PieceType -> Ply -- | 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 -- | Generate a list of possible moves for the given position. legalPlies :: Position -> [Ply] legalPlies' :: Position -> Vector 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 newtype PGN PGN :: [Game] -> PGN data Game CG :: ![(Text, Text)] -> ![Tree (Annotated Ply)] -> !Outcome -> Game [_cgTags] :: Game -> ![(Text, Text)] [_cgForest] :: Game -> ![Tree (Annotated Ply)] [_cgOutcome] :: Game -> !Outcome cgTags :: Lens' Game [(Text, Text)] cgOutcome :: Lens' Game Outcome cgForest :: Lens' Game [Tree (Annotated Ply)] data Outcome Win :: Color -> Outcome Draw :: Outcome Undecided :: Outcome _Win :: Prism' Outcome Color _Draw :: Prism' Outcome () _Undecided :: Prism' Outcome () data Annotated a Ann :: ![Int] -> !a -> ![Int] -> Annotated a [_annPrefixNAG] :: Annotated a -> ![Int] [_annPly] :: Annotated a -> !a [_annSuffixNAG] :: Annotated a -> ![Int] annPrefixNAG :: forall a_a17WQ. Lens' (Annotated a_a17WQ) [Int] annPly :: forall a_a17WQ a_a188c. Lens (Annotated a_a17WQ) (Annotated a_a188c) a_a17WQ a_a188c annSuffixNAG :: forall a_a17WQ. Lens' (Annotated a_a17WQ) [Int] readPGNFile :: MonadIO m => FilePath -> m (Either String PGN) gameFromForest :: [(Text, Text)] -> [Tree Ply] -> Outcome -> Game pgnForest :: PGN -> [Tree Ply] pgn :: Parser PGN hPutPGN :: Handle -> RAVOrder (Doc ann) -> PGN -> IO () pgnDoc :: RAVOrder (Doc ann) -> PGN -> Doc ann type RAVOrder a = ([Tree (Annotated Ply)] -> a) -> [Tree (Annotated Ply)] -> [a] breadthFirst :: RAVOrder a depthFirst :: RAVOrder a gameDoc :: RAVOrder (Doc ann) -> Game -> Doc ann weightedForest :: PGN -> [Tree (Rational, Ply)] instance (Game.Chess.PGN.PGN GHC.Types.~ t) => Control.Lens.Wrapped.Rewrapped Game.Chess.PGN.PGN t instance Control.Lens.Wrapped.Wrapped Game.Chess.PGN.PGN instance GHC.Classes.Ord Game.Chess.PGN.Outcome instance Prettyprinter.Internal.Pretty Game.Chess.PGN.Outcome 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.Show.Show Game.Chess.PGN.Game instance GHC.Generics.Generic Game.Chess.PGN.Game instance GHC.Classes.Eq Game.Chess.PGN.Game instance Data.Hashable.Class.Hashable Game.Chess.PGN.Game instance GHC.Show.Show Game.Chess.PGN.Outcome instance Language.Haskell.TH.Syntax.Lift Game.Chess.PGN.Outcome instance GHC.Generics.Generic Game.Chess.PGN.Outcome instance GHC.Classes.Eq Game.Chess.PGN.Outcome instance Data.Hashable.Class.Hashable Game.Chess.PGN.Outcome instance Data.Hashable.Class.Hashable a => Data.Hashable.Class.Hashable (Game.Chess.PGN.Annotated a) instance GHC.Show.Show a => GHC.Show.Show (Game.Chess.PGN.Annotated a) instance Language.Haskell.TH.Syntax.Lift a => Language.Haskell.TH.Syntax.Lift (Game.Chess.PGN.Annotated a) instance GHC.Generics.Generic (Game.Chess.PGN.Annotated a) instance GHC.Base.Functor Game.Chess.PGN.Annotated instance GHC.Classes.Eq a => GHC.Classes.Eq (Game.Chess.PGN.Annotated a) instance GHC.Base.Applicative Game.Chess.PGN.Annotated module Game.Chess.Polyglot -- | A Polyglot opening book. data PolyglotBook data BookEntry a BE :: {-# UNPACK #-} !Word64 -> !a -> {-# UNPACK #-} !Word16 -> {-# UNPACK #-} !Word32 -> BookEntry a [_beKey] :: BookEntry a -> {-# UNPACK #-} !Word64 [_bePly] :: BookEntry a -> !a [_beWeight] :: BookEntry a -> {-# UNPACK #-} !Word16 [_beLearn] :: BookEntry a -> {-# UNPACK #-} !Word32 beKey :: forall a_a1gzn. Lens' (BookEntry a_a1gzn) Word64 bePly :: forall a_a1gzn a_a1gIM. Lens (BookEntry a_a1gzn) (BookEntry a_a1gIM) a_a1gzn a_a1gIM beWeight :: forall a_a1gzn. Lens' (BookEntry a_a1gzn) Word16 beLearn :: forall a_a1gzn. Lens' (BookEntry a_a1gzn) Word32 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 -> [BookEntry Ply] bookForest :: PolyglotBook -> Position -> [Tree Ply] -- | Predicted Variations. Return the most popular game. variations :: PolyglotBook -> Position -> [[Ply]] findPosition :: PolyglotBook -> Position -> [BookEntry Ply] hashPosition :: Position -> Word64 instance Data.Hashable.Class.Hashable Game.Chess.Polyglot.PolyglotBook instance GHC.Classes.Eq Game.Chess.Polyglot.PolyglotBook instance GHC.Base.Semigroup Game.Chess.Polyglot.PolyglotBook instance GHC.Base.Monoid Game.Chess.Polyglot.PolyglotBook instance GHC.Classes.Ord a => GHC.Classes.Ord (Game.Chess.Polyglot.BookEntry a) instance Foreign.Storable.Storable (Game.Chess.Polyglot.BookEntry GHC.Word.Word16) instance GHC.Show.Show a => GHC.Show.Show (Game.Chess.Polyglot.BookEntry a) instance GHC.Generics.Generic (Game.Chess.Polyglot.BookEntry a) instance GHC.Base.Functor Game.Chess.Polyglot.BookEntry instance GHC.Classes.Eq a => GHC.Classes.Eq (Game.Chess.Polyglot.BookEntry a) instance Data.Hashable.Class.Hashable a => Data.Hashable.Class.Hashable (Game.Chess.Polyglot.BookEntry a) -- | 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 -> SpliceQ 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 and plies of the current game. setPosition :: (Foldable f, MonadIO m) => Engine -> Position -> f Ply -> m () -- | 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