Safe Haskell | None |
---|---|
Language | GHC2024 |
Chess
Description
Bindings for Shiro's chess bot tournament
Synopsis
- type Bitboard = Word64
- data Board
- data Dir
- data Piece
- data PlayerColor
- data State
- data Move = Move {}
- moveDefault :: Move
- getBoard :: IO Board
- opponentMove :: IO Move
- submitMove :: Move -> IO ()
- getTimeMillis :: IO Int
- getOpponentTimeMillis :: IO Int
- getElapsedTimeMillis :: IO Int
- legalMoves :: Board -> [Move]
- nextTurnColor :: Board -> PlayerColor
- isWhiteTurn :: Board -> Bool
- isBlackTurn :: Board -> Bool
- skipTurn :: Board -> Board
- gameState :: Board -> State
- inCheck :: Board -> Bool
- inCheckmate :: Board -> Bool
- inDraw :: Board -> Bool
- canCastleKingside :: PlayerColor -> Board -> Bool
- canCastleQueenside :: PlayerColor -> Board -> Bool
- zobristKey :: Board -> Int
- pushMove :: Move -> Board -> Board
- popMove :: Board -> Board
- fullMoves :: Board -> Int
- halfMoves :: Board -> Int
- bitboard :: PlayerColor -> Piece -> Board -> Bitboard
- pieceFromIndex :: Int -> Board -> Maybe Piece
- pieceFromBitboard :: Bitboard -> Board -> Maybe Piece
- colorFromIndex :: Int -> Board -> Maybe PlayerColor
- colorFromBitboard :: Bitboard -> Board -> Maybe PlayerColor
- indexFromBitboard :: Bitboard -> Int
- bitboardFromIndex :: Int -> Bitboard
- showBitboard :: Bitboard -> String
- bbSlide :: Dir -> Bitboard -> Bitboard
- bbFlood :: Bool -> Dir -> Bitboard -> Bitboard -> Bitboard
- bbBlocker :: Dir -> Bitboard -> Bitboard -> Bitboard
- bbSlideN :: Bitboard -> Bitboard
- bbSlideS :: Bitboard -> Bitboard
- bbSlideE :: Bitboard -> Bitboard
- bbSlideW :: Bitboard -> Bitboard
- bbSlideNE :: Bitboard -> Bitboard
- bbSlideNW :: Bitboard -> Bitboard
- bbSlideSE :: Bitboard -> Bitboard
- bbSlideSW :: Bitboard -> Bitboard
- bbFloodN :: Bool -> Bitboard -> Bitboard -> Bitboard
- bbFloodS :: Bool -> Bitboard -> Bitboard -> Bitboard
- bbFloodE :: Bool -> Bitboard -> Bitboard -> Bitboard
- bbFloodW :: Bool -> Bitboard -> Bitboard -> Bitboard
- bbFloodNE :: Bool -> Bitboard -> Bitboard -> Bitboard
- bbFloodNW :: Bool -> Bitboard -> Bitboard -> Bitboard
- bbFloodSE :: Bool -> Bitboard -> Bitboard -> Bitboard
- bbFloodSW :: Bool -> Bitboard -> Bitboard -> Bitboard
- bbBlockerN :: Bitboard -> Bitboard -> Bitboard
- bbBlockerS :: Bitboard -> Bitboard -> Bitboard
- bbBlockerE :: Bitboard -> Bitboard -> Bitboard
- bbBlockerW :: Bitboard -> Bitboard -> Bitboard
- bbBlockerNE :: Bitboard -> Bitboard -> Bitboard
- bbBlockerNW :: Bitboard -> Bitboard -> Bitboard
- bbBlockerSE :: Bitboard -> Bitboard -> Bitboard
- bbBlockerSW :: Bitboard -> Bitboard -> Bitboard
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.
Directions, used for bitboard manipulation.
Chess piece types
data PlayerColor Source #
Player colors
Instances
Game state.
Constructors
Normal | The game is ongoing. |
Stalemate | The game has ended in a stalemate. |
Checkmate | The game has ended in a checkmate. |
A chess move, specifying the positions but not the piece to be moved.
Constructors
Move | |
Fields
|
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.
Get the game's current board. The current board changes after every move.
opponentMove :: IO Move Source #
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).
inCheckmate :: Board -> Bool Source #
Whether the current player is in checkmate.
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.
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.
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.
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.
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.