-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Basic chess library
--
-- A simple 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.3.1.2
module Game.Chess.QuadBitboard
data QuadBitboard
QBB :: {-# UNPACK #-} !Word64 -> {-# UNPACK #-} !Word64 -> {-# UNPACK #-} !Word64 -> {-# UNPACK #-} !Word64 -> QuadBitboard
[black] :: QuadBitboard -> {-# UNPACK #-} !Word64
[pbq] :: QuadBitboard -> {-# UNPACK #-} !Word64
[nbk] :: QuadBitboard -> {-# UNPACK #-} !Word64
[rqk] :: QuadBitboard -> {-# UNPACK #-} !Word64
white :: QuadBitboard -> Word64
occupied :: QuadBitboard -> Word64
pnr :: QuadBitboard -> Word64
pawns :: QuadBitboard -> Word64
knights :: QuadBitboard -> Word64
bishops :: QuadBitboard -> Word64
rooks :: QuadBitboard -> Word64
queens :: QuadBitboard -> Word64
kings :: QuadBitboard -> Word64
wPawns :: QuadBitboard -> Word64
wKnights :: QuadBitboard -> Word64
wBishops :: QuadBitboard -> Word64
wRooks :: QuadBitboard -> Word64
wQueens :: QuadBitboard -> Word64
wKings :: QuadBitboard -> Word64
bPawns :: QuadBitboard -> Word64
bKnights :: QuadBitboard -> Word64
bBishops :: QuadBitboard -> Word64
bRooks :: QuadBitboard -> Word64
bQueens :: QuadBitboard -> Word64
bKings :: QuadBitboard -> Word64
toString :: QuadBitboard -> String
newtype Word4
W4 :: Word8 -> Word4
pattern NoPiece :: Word4
pattern WhitePawn :: Word4
pattern WhiteKnight :: Word4
pattern WhiteBishop :: Word4
pattern WhiteRook :: Word4
pattern WhiteQueen :: Word4
pattern WhiteKing :: Word4
pattern BlackPawn :: Word4
pattern BlackKnight :: Word4
pattern BlackBishop :: Word4
pattern BlackRook :: Word4
pattern BlackQueen :: Word4
pattern BlackKing :: Word4
empty :: QuadBitboard
standard :: QuadBitboard
-- | law: square i x ! i = x where inRange (0,63) i && inRange
-- (0,15) x
square :: Bits nibble => Int -> nibble -> QuadBitboard
(!) :: QuadBitboard -> Int -> Word4
setNibble :: Bits nibble => QuadBitboard -> Int -> nibble -> QuadBitboard
-- | Move a nibble. Note that this function, while convenient, isn't very
-- fast as it needs to lookup the source nibble value.
move :: QuadBitboard -> Int -> Int -> QuadBitboard
move' :: Int -> Word4 -> Int -> Word4 -> QuadBitboard
whiteKingsideCastle :: QuadBitboard
whiteQueensideCastle :: QuadBitboard
blackKingsideCastle :: QuadBitboard
blackQueensideCastle :: QuadBitboard
enPassant :: Int -> Int -> QuadBitboard
whitePromotion :: QuadBitboard -> Int -> Int -> Word4 -> QuadBitboard
blackPromotion :: QuadBitboard -> Int -> Int -> Word4 -> QuadBitboard
whitePromotion' :: Int -> Int -> Word4 -> Word4 -> QuadBitboard
blackPromotion' :: Int -> Int -> Word4 -> Word4 -> QuadBitboard
instance GHC.Show.Show Game.Chess.QuadBitboard.Word4
instance GHC.Real.Real Game.Chess.QuadBitboard.Word4
instance GHC.Read.Read Game.Chess.QuadBitboard.Word4
instance GHC.Classes.Ord Game.Chess.QuadBitboard.Word4
instance GHC.Num.Num Game.Chess.QuadBitboard.Word4
instance GHC.Arr.Ix Game.Chess.QuadBitboard.Word4
instance GHC.Real.Integral Game.Chess.QuadBitboard.Word4
instance GHC.Classes.Eq Game.Chess.QuadBitboard.Word4
instance Data.Bits.Bits Game.Chess.QuadBitboard.Word4
instance GHC.Classes.Eq Game.Chess.QuadBitboard.QuadBitboard
instance GHC.Enum.Bounded Game.Chess.QuadBitboard.Word4
instance GHC.Enum.Enum Game.Chess.QuadBitboard.Word4
instance Data.Bits.FiniteBits Game.Chess.QuadBitboard.Word4
instance Data.Binary.Class.Binary Game.Chess.QuadBitboard.QuadBitboard
instance Data.String.IsString Game.Chess.QuadBitboard.QuadBitboard
instance GHC.Base.Monoid Game.Chess.QuadBitboard.QuadBitboard
instance GHC.Base.Semigroup Game.Chess.QuadBitboard.QuadBitboard
instance GHC.Show.Show Game.Chess.QuadBitboard.QuadBitboard
-- | 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.
module Game.Chess
data Color
Black :: Color
White :: Color
opponent :: Color -> Color
data Sq
A1 :: Sq
B1 :: Sq
C1 :: Sq
D1 :: Sq
E1 :: Sq
F1 :: Sq
G1 :: Sq
H1 :: Sq
A2 :: Sq
B2 :: Sq
C2 :: Sq
D2 :: Sq
E2 :: Sq
F2 :: Sq
G2 :: Sq
H2 :: Sq
A3 :: Sq
B3 :: Sq
C3 :: Sq
D3 :: Sq
E3 :: Sq
F3 :: Sq
G3 :: Sq
H3 :: Sq
A4 :: Sq
B4 :: Sq
C4 :: Sq
D4 :: Sq
E4 :: Sq
F4 :: Sq
G4 :: Sq
H4 :: Sq
A5 :: Sq
B5 :: Sq
C5 :: Sq
D5 :: Sq
E5 :: Sq
F5 :: Sq
G5 :: Sq
H5 :: Sq
A6 :: Sq
B6 :: Sq
C6 :: Sq
D6 :: Sq
E6 :: Sq
F6 :: Sq
G6 :: Sq
H6 :: Sq
A7 :: Sq
B7 :: Sq
C7 :: Sq
D7 :: Sq
E7 :: Sq
F7 :: Sq
G7 :: Sq
H7 :: Sq
A8 :: Sq
B8 :: Sq
C8 :: Sq
D8 :: Sq
E8 :: Sq
F8 :: Sq
G8 :: Sq
H8 :: Sq
isLight :: IsSquare sq => sq -> Bool
isDark :: IsSquare sq => sq -> Bool
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 :: IsSquare sq => Position -> sq -> 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
-- | Construct a position from Forsyth-Edwards-Notation.
fromFEN :: String -> Maybe Position
-- | Convert a position to Forsyth-Edwards-Notation.
toFEN :: Position -> String
positionTree :: Position -> Tree Position
positionForest :: Position -> Forest Position
newtype Ply
Ply :: Word16 -> Ply
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 :: (Stream s, SANToken (Token s), IsString (Tokens s)) => Position -> s -> Either String Ply
toSAN :: Position -> Ply -> String
unsafeToSAN :: Position -> Ply -> String
-- | 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 :: 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 moves function.
unsafeDoPly :: Position -> Ply -> Position
plyTree :: Position -> Ply -> Tree Ply
plyForest :: Position -> Forest Ply
instance GHC.Show.Show Game.Chess.Direction
instance GHC.Classes.Eq Game.Chess.Direction
instance GHC.Show.Show Game.Chess.Castle
instance GHC.Classes.Ord Game.Chess.Castle
instance GHC.Arr.Ix Game.Chess.Castle
instance GHC.Classes.Eq Game.Chess.Castle
instance GHC.Classes.Eq Game.Chess.Ply
instance GHC.Show.Show Game.Chess.Sq
instance GHC.Classes.Ord Game.Chess.Sq
instance GHC.Arr.Ix Game.Chess.Sq
instance GHC.Classes.Eq Game.Chess.Sq
instance GHC.Enum.Enum Game.Chess.Sq
instance GHC.Enum.Bounded Game.Chess.Sq
instance GHC.Show.Show Game.Chess.Piece
instance GHC.Classes.Eq Game.Chess.Piece
instance GHC.Show.Show Game.Chess.Color
instance GHC.Classes.Ord Game.Chess.Color
instance GHC.Arr.Ix Game.Chess.Color
instance GHC.Classes.Eq Game.Chess.Color
instance GHC.Show.Show Game.Chess.PieceType
instance GHC.Classes.Ord Game.Chess.PieceType
instance GHC.Arr.Ix Game.Chess.PieceType
instance GHC.Classes.Eq Game.Chess.PieceType
instance GHC.Show.Show Game.Chess.SANStatus
instance GHC.Read.Read Game.Chess.SANStatus
instance GHC.Classes.Eq Game.Chess.SANStatus
instance GHC.Show.Show Game.Chess.From
instance GHC.Show.Show Game.Chess.Ply
instance GHC.Classes.Eq Game.Chess.Position
instance Game.Chess.IsSquare Game.Chess.Sq
instance Game.Chess.IsSquare GHC.Types.Int
instance Game.Chess.SANToken GHC.Types.Char
instance Game.Chess.SANToken GHC.Word.Word8
module Game.Chess.Polyglot.Hash
hashPosition :: Position -> Word64
pieceKey :: (PieceType, Color, Sq) -> Word64
castleKey :: (Color, Castle) -> Word64
epKeys :: Vector Word64
turnKey :: Word64
module Game.Chess.PGN
readPGNFile :: FilePath -> IO (Either String PGN)
gameFromForest :: [(ByteString, Text)] -> Forest Ply -> Outcome -> Game
newtype PGN
PGN :: [Game] -> PGN
type Game = ([(ByteString, Text)], (Outcome, Forest PlyData))
data Outcome
Win :: Color -> Outcome
Draw :: Outcome
Undecided :: Outcome
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.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.PlyData
instance GHC.Classes.Eq Game.Chess.PGN.PlyData
instance GHC.Show.Show Game.Chess.PGN.Outcome
instance GHC.Classes.Eq Game.Chess.PGN.Outcome
instance Data.Text.Prettyprint.Doc.Internal.Pretty Game.Chess.PGN.Outcome
module Game.Chess.Polyglot.Book
-- | 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 ()
-- | 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
findPosition :: PolyglotBook -> Position -> [BookEntry]
instance GHC.Classes.Eq Game.Chess.Polyglot.Book.PolyglotBook
instance GHC.Show.Show Game.Chess.Polyglot.Book.BookEntry
instance GHC.Classes.Eq Game.Chess.Polyglot.Book.BookEntry
instance GHC.Classes.Ord Game.Chess.Polyglot.Book.BookEntry
instance Foreign.Storable.Storable Game.Chess.Polyglot.Book.BookEntry
module Game.Chess.UCI
data UCIException
IllegalMove :: Ply -> UCIException
data Engine
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 ()
data Info
PV :: [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 (Ply, Maybe Ply), TChan [Info])
searching :: MonadIO m => Engine -> m Bool
data SearchParam
searchmoves :: [Ply] -> 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
-- | 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.SearchParam
instance GHC.Classes.Eq Game.Chess.UCI.SearchParam
instance GHC.Show.Show Game.Chess.UCI.Command
instance GHC.Show.Show Game.Chess.UCI.Option
instance GHC.Classes.Eq Game.Chess.UCI.Option
instance GHC.Show.Show Game.Chess.UCI.Info
instance GHC.Classes.Eq Game.Chess.UCI.Info
instance GHC.Show.Show Game.Chess.UCI.Bounds
instance GHC.Classes.Eq Game.Chess.UCI.Bounds
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.UCIException
instance Data.String.IsString Game.Chess.UCI.Option
instance GHC.Exception.Type.Exception Game.Chess.UCI.UCIException