chessIO-0.3.1.0: Basic chess library

Copyright(c) Mario Lang 2019
LicenseBSD3
Maintainermlang@blind.guru
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Game.Chess

Contents

Description

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.

Synopsis

Chess positions

data Color Source #

Constructors

Black 
White 
Instances
Eq Color Source # 
Instance details

Defined in Game.Chess

Methods

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

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

Ord Color Source # 
Instance details

Defined in Game.Chess

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

Methods

showsPrec :: Int -> Color -> ShowS #

show :: Color -> String #

showList :: [Color] -> ShowS #

Ix Color Source # 
Instance details

Defined in Game.Chess

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
Bounded Sq Source # 
Instance details

Defined in Game.Chess

Methods

minBound :: Sq #

maxBound :: Sq #

Enum Sq Source # 
Instance details

Defined in Game.Chess

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

Methods

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

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

Ord Sq Source # 
Instance details

Defined in Game.Chess

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 #

Show Sq Source # 
Instance details

Defined in Game.Chess

Methods

showsPrec :: Int -> Sq -> ShowS #

show :: Sq -> String #

showList :: [Sq] -> ShowS #

Ix Sq Source # 
Instance details

Defined in Game.Chess

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

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

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

data Castle Source #

Constructors

Kingside 
Queenside 
Instances
Eq Castle Source # 
Instance details

Defined in Game.Chess

Methods

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

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

Ord Castle Source # 
Instance details

Defined in Game.Chess

Show Castle Source # 
Instance details

Defined in Game.Chess

Ix Castle Source # 
Instance details

Defined in Game.Chess

data Position Source #

Instances
Eq Position Source # 
Instance details

Defined in Game.Chess

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

pieceAt :: IsSquare sq => Position -> sq -> Maybe (Color, PieceType) Source #

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
Eq Ply Source # 
Instance details

Defined in Game.Chess

Methods

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

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

Show Ply Source # 
Instance details

Defined in Game.Chess

Methods

showsPrec :: Int -> Ply -> ShowS #

show :: Ply -> String #

showList :: [Ply] -> ShowS #

Converting from/to algebraic notation

strictSAN :: forall s. (Stream s, SANToken (Token s), IsString (Tokens s)) => Position -> Parser s Ply Source #

relaxedSAN :: (Stream s, SANToken (Token s), IsString (Tokens s)) => Position -> Parser s Ply Source #

fromSAN :: (Stream s, SANToken (Token s), IsString (Tokens s)) => Position -> s -> Either String Ply Source #

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.