chessapi
Safe HaskellNone
LanguageGHC2024

Chess

Description

Bindings for Shiro's chess bot tournament

Synopsis

Documentation

type Bitboard = Word64 Source #

A bitboard - an integer where each of the 64 bits represents a square of the board. The bits usually encode the presence of a particular piece. The least significant bit corresponds to a1, the 8th least significant bit corresponds to a8, the most significant bit corresponds to h8.

data Board Source #

A game of chess in a particular state.

data Dir Source #

Directions, used for bitboard manipulation.

Constructors

N 
NE 
E 
SE 
S 
SW 
W 
NW 

Instances

Instances details
Bounded Dir Source # 
Instance details

Defined in Chess

Methods

minBound :: Dir #

maxBound :: Dir #

Enum Dir Source # 
Instance details

Defined in Chess

Methods

succ :: Dir -> Dir #

pred :: Dir -> Dir #

toEnum :: Int -> Dir #

fromEnum :: Dir -> Int #

enumFrom :: Dir -> [Dir] #

enumFromThen :: Dir -> Dir -> [Dir] #

enumFromTo :: Dir -> Dir -> [Dir] #

enumFromThenTo :: Dir -> Dir -> Dir -> [Dir] #

Show Dir Source # 
Instance details

Defined in Chess

Methods

showsPrec :: Int -> Dir -> ShowS #

show :: Dir -> String #

showList :: [Dir] -> ShowS #

Eq Dir Source # 
Instance details

Defined in Chess

Methods

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

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

data Piece Source #

Chess piece types

Constructors

Pawn 
Bishop 
Knight 
Rook 
Queen 
King 

Instances

Instances details
Bounded Piece Source # 
Instance details

Defined in Chess

Enum Piece Source # 
Instance details

Defined in Chess

Show Piece Source # 
Instance details

Defined in Chess

Methods

showsPrec :: Int -> Piece -> ShowS #

show :: Piece -> String #

showList :: [Piece] -> ShowS #

Eq Piece Source # 
Instance details

Defined in Chess

Methods

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

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

Ord Piece Source # 
Instance details

Defined in Chess

Methods

compare :: Piece -> Piece -> Ordering #

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

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

(>) :: Piece -> Piece -> Bool #

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

max :: Piece -> Piece -> Piece #

min :: Piece -> Piece -> Piece #

data State Source #

Game state.

Constructors

Normal

The game is ongoing.

Stalemate

The game has ended in a stalemate.

Checkmate

The game has ended in a checkmate.

Instances

Instances details
Bounded State Source # 
Instance details

Defined in Chess

Enum State Source # 
Instance details

Defined in Chess

Show State Source # 
Instance details

Defined in Chess

Methods

showsPrec :: Int -> State -> ShowS #

show :: State -> String #

showList :: [State] -> ShowS #

Eq State Source # 
Instance details

Defined in Chess

Methods

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

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

Ord State Source # 
Instance details

Defined in Chess

Methods

compare :: State -> State -> Ordering #

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

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

(>) :: State -> State -> Bool #

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

max :: State -> State -> State #

min :: State -> State -> State #

data Move Source #

A chess move, specifying the positions but not the piece to be moved.

Constructors

Move 

Fields

  • from :: Bitboard

    The move's start position (a bitboard with a single set bit).

  • to :: Bitboard

    The move's end position (a bitboard with a single set bit).

  • promotion :: Maybe Piece

    If this move causes a pawn promotion, specifies the piece to promote it to.

  • capture :: Bool

    Whether this move is a capture.

  • castle :: Bool

    Whether this move is a castle.

Instances

Instances details
Show Move Source # 
Instance details

Defined in Chess

Methods

showsPrec :: Int -> Move -> ShowS #

show :: Move -> String #

showList :: [Move] -> ShowS #

Eq Move Source # 
Instance details

Defined in Chess

Methods

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

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

moveDefault :: Move Source #

A default Move with all of the fields unset.

IO actions

For info on how to use IO actions, see Haskell wiki.

getBoard :: IO Board Source #

Get the game's current board. The current board changes after every move.

submitMove :: Move -> IO () Source #

Submit a move that you are going to play.

getTimeMillis :: IO Int Source #

Get the time that was remaining at the start of the turn in milliseconds.

getOpponentTimeMillis :: IO Int Source #

Get opponent's remaining time in milliseconds.

getElapsedTimeMillis :: IO Int Source #

Get time elapsed since the start of the turn in milliseconds.

Board functions

legalMoves :: Board -> [Move] Source #

List legal moves for a board. Note that it may be either your or your opponent's moves depending on what nextTurnColor returns.

nextTurnColor :: Board -> PlayerColor Source #

Returns the player whose turn it currently is.

isWhiteTurn :: Board -> Bool Source #

Whether it's white's turn.

isBlackTurn :: Board -> Bool Source #

Whether it's black's turn.

skipTurn :: Board -> Board Source #

Skips a player's turn, returning an equivalent board where it's the opposite player's turn.

gameState :: Board -> State Source #

Get a game's current state (whether it's a checkmate, stalemate, or neither).

inCheck :: Board -> Bool Source #

Whether the current player is in check.

inCheckmate :: Board -> Bool Source #

Whether the current player is in checkmate.

inDraw :: Board -> Bool Source #

Whether the current player is in a draw.

canCastleKingside :: PlayerColor -> Board -> Bool Source #

Whether a particular player is allowed to castle kingside at some point in the game.

canCastleQueenside :: PlayerColor -> Board -> Bool Source #

Whether a particular player is allowed to castle queenside at some point in the game.

zobristKey :: Board -> Int Source #

Get a board's Zobrist hash.

pushMove :: Move -> Board -> Board Source #

Make a move on a board, returning a new board with that move made.

popMove :: Board -> Board Source #

Undo a move on a board, returning a board without that move.

fullMoves :: Board -> Int Source #

Read the full move counter (starts at 1, increments each time black moves)

halfMoves :: Board -> Int Source #

Read the half move counter (starts at 0, increments after every move, resets to 0 after pawn moves or captures). Used for the 50-move draw rule.

bitboard :: PlayerColor -> Piece -> Board -> Bitboard Source #

Get a bitboard for a particular player and piece. The bitboard's bits will indicate the presence of that particular piece of that particular color on each square of the board.

pieceFromIndex :: Int -> Board -> Maybe Piece Source #

Get the piece located at a particular index.

pieceFromBitboard :: Bitboard -> Board -> Maybe Piece Source #

Get the piece located at the position set in the bitboard.

colorFromIndex :: Int -> Board -> Maybe PlayerColor Source #

Get the player color for the piece located at a particular index.

colorFromBitboard :: Bitboard -> Board -> Maybe PlayerColor Source #

Get the player color for the piece located at the position set in the bitboard.

Bitboard functions

indexFromBitboard :: Bitboard -> Int Source #

Convert a bitboard with a single set bit to a cell index.

bitboardFromIndex :: Int -> Bitboard Source #

Convert a cell index to a bitboard with a single set bit.

showBitboard :: Bitboard -> String Source #

Get a printable string for a bitboard (a grid with 8 columns and 8 lines)

bbSlide :: Dir -> Bitboard -> Bitboard Source #

Move all elements of the bitboard in a particular direction.

bbFlood Source #

Arguments

:: Bool

Whether to also include the final nonempty space.

-> Dir

Direction to move in.

-> Bitboard

A bitboard representing a set of empty spaces on the board.

-> Bitboard

The bitboard to shift (with a single set bit).

-> Bitboard

The board with movement squares marked. The original square will not be marked.

Travel in a particular direction, setting all bits until encountering a nonempty space, returning all marked spaces.

bbBlocker Source #

Arguments

:: Dir

Direction to move in.

-> Bitboard

A bitboard representing a set of empty spaces on the board.

-> Bitboard

A bitboard to shift (with a single set bit).

-> Bitboard

The board after a shift encountered a nonempty space.

Travel in a particular direction until encountering a nonempty space.

Bitboard function specializations

Specializations for individual directions, matching the C API.