chessIO-0.6.0.0: Basic chess library
Copyright(c) Mario Lang 2020
LicenseBSD3
Maintainermlang@blind.guru
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Game.Chess

Description

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:

Synopsis

Chess positions

data Color Source #

Constructors

Black 
White 

Instances

Instances details
Eq Color Source # 
Instance details

Defined in Game.Chess.Internal

Methods

(==) :: Color -> Color -> Bool #

(/=) :: Color -> Color -> Bool #

Ord Color Source # 
Instance details

Defined in Game.Chess.Internal

Methods

compare :: Color -> Color -> Ordering #

(<) :: Color -> Color -> Bool #

(<=) :: Color -> Color -> Bool #

(>) :: Color -> Color -> Bool #

(>=) :: Color -> Color -> Bool #

max :: Color -> Color -> Color #

min :: Color -> Color -> Color #

Show Color Source # 
Instance details

Defined in Game.Chess.Internal

Methods

showsPrec :: Int -> Color -> ShowS #

show :: Color -> String #

showList :: [Color] -> ShowS #

Ix Color Source # 
Instance details

Defined in Game.Chess.Internal

class IsSquare sq where Source #

Minimal complete definition

toIndex

Methods

toIndex :: sq -> Int Source #

toRF :: sq -> (Int, Int) Source #

Instances

Instances details
IsSquare Int Source # 
Instance details

Defined in Game.Chess.Internal.Square

Methods

toIndex :: Int -> Int Source #

toRF :: Int -> (Int, Int) Source #

IsSquare Sq Source # 
Instance details

Defined in Game.Chess.Internal.Square

Methods

toIndex :: Sq -> Int Source #

toRF :: Sq -> (Int, Int) Source #

IsSquare (Int, Int) Source # 
Instance details

Defined in Game.Chess.Internal.Square

Methods

toIndex :: (Int, Int) -> Int Source #

toRF :: (Int, Int) -> (Int, Int) Source #

data Sq Source #

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

Instances details
Bounded Sq Source # 
Instance details

Defined in Game.Chess.Internal.Square

Methods

minBound :: Sq #

maxBound :: Sq #

Enum Sq Source # 
Instance details

Defined in Game.Chess.Internal.Square

Methods

succ :: Sq -> Sq #

pred :: Sq -> Sq #

toEnum :: Int -> Sq #

fromEnum :: Sq -> Int #

enumFrom :: Sq -> [Sq] #

enumFromThen :: Sq -> Sq -> [Sq] #

enumFromTo :: Sq -> Sq -> [Sq] #

enumFromThenTo :: Sq -> Sq -> Sq -> [Sq] #

Eq Sq Source # 
Instance details

Defined in Game.Chess.Internal.Square

Methods

(==) :: Sq -> Sq -> Bool #

(/=) :: Sq -> Sq -> Bool #

Ord Sq Source # 
Instance details

Defined in Game.Chess.Internal.Square

Methods

compare :: Sq -> Sq -> Ordering #

(<) :: Sq -> Sq -> Bool #

(<=) :: Sq -> Sq -> Bool #

(>) :: Sq -> Sq -> Bool #

(>=) :: Sq -> Sq -> Bool #

max :: Sq -> Sq -> Sq #

min :: Sq -> Sq -> Sq #

Read Sq Source # 
Instance details

Defined in Game.Chess.Internal.Square

Show Sq Source # 
Instance details

Defined in Game.Chess.Internal.Square

Methods

showsPrec :: Int -> Sq -> ShowS #

show :: Sq -> String #

showList :: [Sq] -> ShowS #

Ix Sq Source # 
Instance details

Defined in Game.Chess.Internal.Square

Methods

range :: (Sq, Sq) -> [Sq] #

index :: (Sq, Sq) -> Sq -> Int #

unsafeIndex :: (Sq, Sq) -> Sq -> Int #

inRange :: (Sq, Sq) -> Sq -> Bool #

rangeSize :: (Sq, Sq) -> Int #

unsafeRangeSize :: (Sq, Sq) -> Int #

IsSquare Sq Source # 
Instance details

Defined in Game.Chess.Internal.Square

Methods

toIndex :: Sq -> Int Source #

toRF :: Sq -> (Int, Int) Source #

isLight :: IsSquare sq => sq -> Bool Source #

isDark :: IsSquare sq => sq -> Bool Source #

data Castle Source #

Constructors

Kingside 
Queenside 

Instances

Instances details
Eq Castle Source # 
Instance details

Defined in Game.Chess.Internal

Methods

(==) :: Castle -> Castle -> Bool #

(/=) :: Castle -> Castle -> Bool #

Ord Castle Source # 
Instance details

Defined in Game.Chess.Internal

Show Castle Source # 
Instance details

Defined in Game.Chess.Internal

Ix Castle Source # 
Instance details

Defined in Game.Chess.Internal

data Position Source #

Instances

Instances details
Eq Position Source # 
Instance details

Defined in Game.Chess.Internal

Show Position Source # 
Instance details

Defined in Game.Chess.Internal

startpos :: Position Source #

The starting position as given by the FEN string "rnbqkbnrpppppppp8888PPPPPPPP/RNBQKBNR w KQkq - 0 1".

color :: Position -> Color Source #

active color

moveNumber :: Position -> Int Source #

number of the full move

inCheck :: Color -> Position -> Bool Source #

Returns True if Color is in check in the given position.

Converting from/to Forsyth-Edwards-Notation

fromFEN :: String -> Maybe Position Source #

Construct a position from Forsyth-Edwards-Notation.

toFEN :: Position -> String Source #

Convert a position to Forsyth-Edwards-Notation.

Chess moves

newtype Ply Source #

Constructors

Ply Word16 

Instances

Instances details
Eq Ply Source # 
Instance details

Defined in Game.Chess.Internal

Methods

(==) :: Ply -> Ply -> Bool #

(/=) :: Ply -> Ply -> Bool #

Show Ply Source # 
Instance details

Defined in Game.Chess.Internal

Methods

showsPrec :: Int -> Ply -> ShowS #

show :: Ply -> String #

showList :: [Ply] -> ShowS #

Storable Ply Source # 
Instance details

Defined in Game.Chess.Internal

Methods

sizeOf :: Ply -> Int #

alignment :: Ply -> Int #

peekElemOff :: Ptr Ply -> Int -> IO Ply #

pokeElemOff :: Ptr Ply -> Int -> Ply -> IO () #

peekByteOff :: Ptr b -> Int -> IO Ply #

pokeByteOff :: Ptr b -> Int -> Ply -> IO () #

peek :: Ptr Ply -> IO Ply #

poke :: Ptr Ply -> Ply -> IO () #

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 :: 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.