Sign in

    moonchess

    Pure-MoonBit chess core: FEN/PGN/SAN/UCI formats, bitboards and perft-verified rules.

    chess
    fen
    pgn
    san
    uci
    bitboard
    Download zip
    Author
    Version
    0.1.1
    License
    Apache-2.0
    Last updated
    13 hours ago
    Downloads
    4

    #L76148/moonchess

    A pure-MoonBit chess core: bitboards, FEN, Zobrist keys and, in the coming increments, legal move generation with PGN, SAN and UCI support.

    The library core has no runtime dependencies. The command line tool uses the standard moonbitlang/core/env package for its arguments.

    #Install

    moon add L76148/moonchess

    #Why MoonChess

    mooncakes.io already ships Chinese chess (xiangqi) packages, but the ecosystem has no international chess library and nothing that reads or writes the standard chess file formats. Anything that wants to replay a PGN game, index a puzzle database, validate a position string or drive an engine over UCI has to start from a board representation. This module supplies that representation.

    #Parse a position

    let position = @moonchess.Position::from_fen( "r3k2r/8/8/3pP3/8/8/8/R3K2R w Kq d6 0 12", )

    Position::from_fen accepts four to six fields. The clock fields default to 0 and 1, and a document that is missing a king, that names an unknown piece or that carries a bad en passant square is rejected:

    match @moonchess.Position::try_from_fen(input) { Ok(position) => println(position.to_fen()) Err(error) => println("error: " + error.message()) }

    Every error is a FenError value, so callers can match on the failing field instead of parsing a message.

    #Inspect a position

    position.turn() // White or Black position.castling().to_fen() // "Kq" position.en_passant() // Square of d6 position.piece_at(@moonchess.Square::parse("d5").unwrap()) // black pawn position.king_square(@moonchess.White) // Square of e1 position.piece_count() // 8

    The board renders as a diagram, with FEN letters or with Unicode symbols:

    println(position.to_ascii()) println(position.to_unicode())

    #Work with bitboards

    let pawns = position.pieces_of(@moonchess.White, @moonchess.Pawn) pawns.count() // number of white pawns pawns.squares() // squares in index order pawns.contains(@moonchess.Square::parse("e5").unwrap()) let rank_one = @moonchess.Bitboard::rank_mask(0) let file_a = @moonchess.Bitboard::file_mask(0) rank_one.intersect(file_a).first() // Square of a1

    Square index 0 is a1 and index 63 is h8, so bit i of a bitboard always refers to Square(i).

    #Generate moves

    let moves = position.pseudo_legal_moves() let legal = position.legal_moves() position.is_legal(moves[0]) position.pseudo_legal_moves_from(square) position.in_check(position.turn()) position.is_attacked(square, @moonchess.White) position.attackers_to(square, @moonchess.White)

    pseudo_legal_moves ignores king safety, as the name says: a pinned piece still reports its moves, and castling only checks the right and the empty path. Legal filtering is layered on top of make_move; perft counters checked against published node counts are the next increment.

    Attack sets are built from step offsets for knights, kings and pawns and from ray walks for rooks, bishops and queens. Each ray stops at the first occupied square and includes it, so the blocking piece is part of the set:

    @moonchess.Bitboard::knight_attacks(square) @moonchess.Bitboard::rook_attacks(square, occupancy)

    #Compute a repetition key

    position.zobrist_hash()

    The keys are derived from fixed seeds, so they are reproducible across runs and backends, and they ignore the halfmove clock and the move number. Two positions that differ only in those two fields share a key.

    #Command line

    moon run cmd/moonchess moon run cmd/moonchess -- board "<FEN>" moon run cmd/moonchess -- unicode "<FEN>" moon run cmd/moonchess -- fen "<FEN>" moon run cmd/moonchess -- moves "<FEN>" moon run cmd/moonchess -- validate "<FEN>"

    #Current increment

    This release covers two milestones: the square, colour, piece and castling-rights types, the 64-bit bitboard, the position with its twelve piece bitboards and FEN state, the strict FEN reader and canonical writer, ASCII and Unicode rendering and deterministic Zobrist keys; then step and slider attack generation, attack maps, check detection and pseudo-legal move generation with castling and en passant; then applying a move and filtering pseudo-legal moves down to legal ones.

    Perft counters, game status and SAN, PGN and EPD, and UCI notation are the next increments. Search and evaluation, opening books, tablebases, GUIs, network play and non-standard variants are out of scope.

    #Quality gates

    moon check --target all --deny-warn moon fmt --check moon test --target wasm --deny-warn moon test --target wasm-gc --deny-warn

    The project is licensed under Apache-2.0.

    FenError

    pub(all) suberror FenError {
    Empty
    FieldCount(Int)
    BoardRankCount(Int)
    BoardRankWidth(Int, Int)
    InvalidPiece(Char)
    InvalidSideToMove(String)
    InvalidCastling(String)
    InvalidEnPassant(String)
    InvalidHalfmoveClock(String)
    InvalidFullmoveNumber(String)
    MissingKing(Color)
    TooManyKings(Color)
    } derive(
    Debug
    )

    Everything that can be reported while reading a FEN document.

    FenError::message

    fn FenError::message(self : FenError) -> String

    A human readable explanation of the error.

    FenError::to_repr

    Bitboard

    pub(all) struct Bitboard(UInt64) derive(Eq,
    Debug
    )

    A set of squares stored in a 64-bit word.

    Bit i corresponds to Square(i), so bit 0 is a1 and bit 63 is h8.
    impl Show for Bitboard

    Bitboard::attacks_of

    fn Bitboard::attacks_of(kind : PieceKind, color : Color, square : Square, occupancy : Bitboard) -> Bitboard

    The squares a piece of one kind and colour attacks from square.

    Pawn attacks ignore the en passant target; use the position level helpers for a complete move list.

    Bitboard::bishop_attacks

    fn Bitboard::bishop_attacks(square : Square, occupancy : Bitboard) -> Bitboard

    The squares a bishop on square attacks.

    As with rooks, each ray includes the square that stops it.

    Bitboard::contains

    fn Bitboard::contains(self : Bitboard, square : Square) -> Bool

    Whether the square is a member of the set.

    Bitboard::count

    fn Bitboard::count(self : Bitboard) -> Int

    The number of squares in the set.

    Bitboard::difference

    fn Bitboard::difference(self : Bitboard, other : Bitboard) -> Bitboard

    The squares of self that are not in other.

    Bitboard::empty

    fn Bitboard::empty() -> Bitboard

    The empty square set.

    Bitboard::equal

    fn Bitboard::equal(Bitboard, Bitboard) -> Bool

    Bitboard::file_mask

    fn Bitboard::file_mask(file : Int) -> Bitboard

    Every square of one file, 0 for a.

    Bitboard::first

    fn Bitboard::first(self : Bitboard) -> Square?

    The lowest square of the set in index order, or None when empty.

    Bitboard::from_u64

    fn Bitboard::from_u64(value : UInt64) -> Bitboard

    Wraps a raw word.

    Bitboard::full

    fn Bitboard::full() -> Bitboard

    The square set containing every square.

    Bitboard::intersect

    fn Bitboard::intersect(self : Bitboard, other : Bitboard) -> Bitboard

    The intersection of two sets.

    Bitboard::is_empty

    fn Bitboard::is_empty(self : Bitboard) -> Bool

    Whether the set holds no square at all.

    Bitboard::king_attacks

    fn Bitboard::king_attacks(square : Square) -> Bitboard

    The squares a king on square attacks.

    Bitboard::knight_attacks

    fn Bitboard::knight_attacks(square : Square) -> Bitboard

    The squares a knight on square attacks.

    Bitboard::not_equal

    fn Bitboard::not_equal(x : Bitboard, y : Bitboard) -> Bool

    Bitboard::output

    fn Bitboard::output(self : Bitboard, logger : &Logger) -> Unit

    Bitboard::pawn_attacks

    fn Bitboard::pawn_attacks(color : Color, square : Square) -> Bitboard

    The squares a pawn of color attacks from square.

    Bitboard::queen_attacks

    fn Bitboard::queen_attacks(square : Square, occupancy : Bitboard) -> Bitboard

    The squares a queen on square attacks.

    As with rooks and bishops, each ray includes the square that stops it.

    Bitboard::rank_mask

    fn Bitboard::rank_mask(rank : Int) -> Bitboard

    Every square of one rank, 0 for rank 1.

    Bitboard::remove

    fn Bitboard::remove(self : Bitboard, square : Square) -> Bitboard

    Returns a set with the square removed.

    Bitboard::rook_attacks

    fn Bitboard::rook_attacks(square : Square, occupancy : Bitboard) -> Bitboard

    The squares a rook on square attacks.

    Each ray stops at the first occupied square and includes it, so a blocking piece is part of the set. Move generation removes own pieces from the result.

    Bitboard::set

    fn Bitboard::set(self : Bitboard, square : Square) -> Bitboard

    Returns a set with the square added.

    Bitboard::single

    fn Bitboard::single(square : Square) -> Bitboard

    A set containing exactly one square.

    Bitboard::squares

    fn Bitboard::squares(self : Bitboard) -> Array[Square]

    The squares of the set in ascending index order.

    Bitboard::to_ascii

    fn Bitboard::to_ascii(self : Bitboard) -> String

    Renders the set as an eight by eight diagram, rank 8 first.

    Bitboard::to_repr

    Bitboard::to_string

    fn Bitboard::to_string(self : Bitboard) -> String

    Bitboard::to_u64

    fn Bitboard::to_u64(self : Bitboard) -> UInt64

    The raw word behind the square set.

    Bitboard::union

    fn Bitboard::union(self : Bitboard, other : Bitboard) -> Bitboard

    The union of two sets.

    CastlingRights

    pub(all) struct CastlingRights {
    white_kingside : Bool
    white_queenside : Bool
    black_kingside : Bool
    black_queenside : Bool
    } derive(Eq,
    Debug
    )

    The castling rights that are still available in a position.

    CastlingRights::all

    Both sides may castle on both wings.

    CastlingRights::equal

    CastlingRights::has_kingside

    fn CastlingRights::has_kingside(self : CastlingRights, color : Color) -> Bool

    Whether the colour may castle on the king's side.

    CastlingRights::has_queenside

    fn CastlingRights::has_queenside(self : CastlingRights, color : Color) -> Bool

    Whether the colour may castle on the queen's side.

    CastlingRights::index

    fn CastlingRights::index(self : CastlingRights) -> Int

    A four-bit index over the four rights, used for Zobrist keys.

    CastlingRights::is_empty

    fn CastlingRights::is_empty(self : CastlingRights) -> Bool

    Whether no colour may castle at all.

    CastlingRights::none

    No side may castle.

    CastlingRights::not_equal

    fn CastlingRights::not_equal(x : CastlingRights, y : CastlingRights) -> Bool

    CastlingRights::output

    fn CastlingRights::output(self : CastlingRights, logger : &Logger) -> Unit

    CastlingRights::to_fen

    fn CastlingRights::to_fen(self : CastlingRights) -> String

    The FEN castling field, either - or a subset of KQkq in that order.

    CastlingRights::to_string

    fn CastlingRights::to_string(self : CastlingRights) -> String

    CastlingRights::with_kingside

    fn CastlingRights::with_kingside(self : CastlingRights, color : Color, value : Bool) -> CastlingRights

    Returns a copy with the king's side right of one colour set.

    CastlingRights::with_queenside

    fn CastlingRights::with_queenside(self : CastlingRights, color : Color, value : Bool) -> CastlingRights

    Returns a copy with the queen's side right of one colour set.

    Color

    pub(all) enum Color {
    White
    Black
    } derive(Eq,
    Debug
    )

    The side a piece belongs to.
    impl Show for Color

    Color::equal

    fn Color::equal(Color, Color) -> Bool

    Color::fen_char

    fn Color::fen_char(self : Color) -> Char

    The w/b character used by FEN and PGN.

    Color::from_fen_char

    fn Color::from_fen_char(c : Char) -> Color?

    Reads the w/b character used by FEN and PGN.

    Color::index

    fn Color::index(self : Color) -> Int

    The storage index of the colour, 0 for white and 1 for black.

    Color::name

    fn Color::name(self : Color) -> String

    The lower-case name of the colour.

    Color::not_equal

    fn Color::not_equal(x : Color, y : Color) -> Bool

    Color::opposite

    fn Color::opposite(self : Color) -> Color

    The opposite colour.

    Color::output

    fn Color::output(self : Color, logger : &Logger) -> Unit

    Color::to_repr

    Color::to_string

    fn Color::to_string(self : Color) -> String

    Move

    pub(all) struct Move {
    from : Square
    to : Square
    kind : MoveKind
    promotion : PieceKind?
    } derive(Eq,
    Debug
    )

    A move between two squares.

    The fields are public because move generation touches them in tight loops. promotion is Some exactly when kind is Promotion.
    impl Show for Move

    Move::castle

    fn Move::castle(color : Color, kingside : Bool) -> Move

    Builds the king move of a castling.

    Move::double_push

    fn Move::double_push(from : Square, to : Square) -> Move

    Builds a two square pawn advance.

    Move::en_passant

    fn Move::en_passant(from : Square, to : Square) -> Move

    Builds an en passant capture into the empty square behind the pawn.

    Move::equal

    fn Move::equal(Move, Move) -> Bool

    Move::is_capture

    fn Move::is_capture(self : Move, position : Position) -> Bool

    Whether the move captures something, directly or in passing.

    Move::is_castling

    fn Move::is_castling(self : Move) -> Bool

    Whether the move castles.

    Move::is_promotion

    fn Move::is_promotion(self : Move) -> Bool

    Whether the move promotes.

    Move::new

    fn Move::new(from : Square, to : Square) -> Move

    Builds a quiet move or an ordinary capture.

    Move::not_equal

    fn Move::not_equal(x : Move, y : Move) -> Bool

    Move::output

    fn Move::output(self : Move, logger : &Logger) -> Unit

    Move::promotion

    fn Move::promotion(from : Square, to : Square, piece : PieceKind) -> Move

    Builds a king, rook, bishop or queen promotion.

    Move::promotion_piece

    fn Move::promotion_piece(self : Move) -> PieceKind?

    The promotion piece, or None for a move that does not promote.

    Move::to_repr

    Move::to_string

    fn Move::to_string(self : Move) -> String

    Move::to_uci

    fn Move::to_uci(self : Move) -> String

    The move in UCI notation, for example e2e4 or e7e8q.

    Castling is written as the king move, which is what UCI sends.

    MoveKind

    pub(all) enum MoveKind {
    Normal
    DoublePawnPush
    EnPassant
    CastleKingside
    CastleQueenside
    Promotion
    } derive(Eq,
    Debug
    )

    The shape of a move, which the board alone cannot infer.
    impl Show for MoveKind

    MoveKind::equal

    fn MoveKind::equal(MoveKind, MoveKind) -> Bool

    MoveKind::name

    fn MoveKind::name(self : MoveKind) -> String

    The lower-case name of the move shape.

    MoveKind::not_equal

    fn MoveKind::not_equal(x : MoveKind, y : MoveKind) -> Bool

    MoveKind::output

    fn MoveKind::output(self : MoveKind, logger : &Logger) -> Unit

    MoveKind::to_repr

    MoveKind::to_string

    fn MoveKind::to_string(self : MoveKind) -> String

    Piece

    pub(all) struct Piece {
    color : Color
    kind : PieceKind
    } derive(Eq,
    Debug
    )

    A coloured piece.
    impl Show for Piece

    Piece::color

    fn Piece::color(self : Piece) -> Color

    Piece::equal

    fn Piece::equal(Piece, Piece) -> Bool

    Piece::fen_char

    fn Piece::fen_char(self : Piece) -> Char

    The FEN letter of the piece, upper-case for white and lower-case for black.

    Piece::from_fen_char

    fn Piece::from_fen_char(c : Char) -> Piece?

    Reads a FEN piece letter, deriving the colour from the letter's case.

    Piece::kind

    fn Piece::kind(self : Piece) -> PieceKind

    Piece::new

    fn Piece::new(color : Color, kind : PieceKind) -> Piece

    Piece::not_equal

    fn Piece::not_equal(x : Piece, y : Piece) -> Bool

    Piece::output

    fn Piece::output(self : Piece, logger : &Logger) -> Unit

    Piece::to_repr

    Piece::to_string

    fn Piece::to_string(self : Piece) -> String

    PieceKind

    pub(all) enum PieceKind {
    Pawn
    Knight
    Bishop
    Rook
    Queen
    King
    } derive(Eq,
    Debug
    )

    The kind of a chess piece, independent of its colour.
    impl Show for PieceKind

    PieceKind::equal

    fn PieceKind::equal(PieceKind, PieceKind) -> Bool

    PieceKind::fen_char

    fn PieceKind::fen_char(self : PieceKind) -> Char

    The lower-case piece letter used by FEN and SAN.

    PieceKind::from_fen_char

    fn PieceKind::from_fen_char(c : Char) -> PieceKind?

    Reads a FEN piece letter, accepting either case.

    PieceKind::from_index

    fn PieceKind::from_index(index : Int) -> PieceKind?

    Maps a storage index in 0..=5 back to a piece kind.

    PieceKind::index

    fn PieceKind::index(self : PieceKind) -> Int

    The storage index of the piece kind, 0 for a pawn and 5 for a king.

    PieceKind::name

    fn PieceKind::name(self : PieceKind) -> String

    The lower-case English name of the piece kind.

    PieceKind::not_equal

    fn PieceKind::not_equal(x : PieceKind, y : PieceKind) -> Bool

    PieceKind::output

    fn PieceKind::output(self : PieceKind, logger : &Logger) -> Unit

    PieceKind::to_string

    fn PieceKind::to_string(self : PieceKind) -> String

    Position

    pub(all) struct Position {
    // private fields
    } derive(Eq,
    Debug
    )

    A complete chess position.

    The board is stored as twelve bitboards, one per colour and piece kind. Inside each bitboard, bit i set means Square(i) holds that piece. The remaining fields carry the state that FEN records: the side to move, the castling rights, the en passant target, the halfmove clock and the move number.

    Position::attackers_to

    fn Position::attackers_to(self : Position, square : Square, color : Color) -> Bitboard

    Every piece of color that attacks square, as a square set.

    Position::attacks_from

    fn Position::attacks_from(self : Position, square : Square) -> Bitboard

    The squares a piece on square attacks in this position.

    Position::castling

    fn Position::castling(self : Position) -> CastlingRights

    The castling rights that are still available.
    fn Position::castling_is_pseudo_legal(self : Position, color : Color, kingside : Bool) -> Bool

    Whether a wing is cleared for castling: the right is held, both pieces stand on their home squares and the squares between them are empty.

    King safety is not considered here, so a position with a king in check or a piece attacking the king's path still answers true.

    Position::color_occupancy

    fn Position::color_occupancy(self : Position, color : Color) -> Bitboard

    The squares occupied by one colour.

    Position::empty

    fn Position::empty() -> Position

    A position with an empty board, white to move and no castling rights.

    Position::en_passant

    fn Position::en_passant(self : Position) -> Square?

    The en passant target square, when the previous move was a double pawn push.

    Position::equal

    fn Position::equal(Position, Position) -> Bool

    Position::from_fen

    fn Position::from_fen(fen : String) -> Position raise FenError

    Parses a FEN document.

    Four to six fields are accepted. When the clock fields are omitted the halfmove clock defaults to 0 and the move number to 1. The board must hold exactly one king per colour.

    Position::fullmove_number

    fn Position::fullmove_number(self : Position) -> Int

    The number of the move that is about to be played, starting at 1.

    Position::halfmove_clock

    fn Position::halfmove_clock(self : Position) -> Int

    The number of halfmoves since the last pawn move or capture.

    Position::in_check

    fn Position::in_check(self : Position, color : Color) -> Bool

    Whether color's king is attacked.

    Position::is_attacked

    fn Position::is_attacked(self : Position, square : Square, color : Color) -> Bool

    Whether color attacks square.

    Position::is_empty_square

    fn Position::is_empty_square(self : Position, square : Square) -> Bool

    Whether the square holds no piece.
    fn Position::is_legal(self : Position, played : Move) -> Bool

    Whether a move is legal.

    The move must be one that pseudo_legal_moves generates, with the same origin, target, kind and promotion piece. A move built by hand with the right origin and target but the wrong kind, such as a castle written as a plain king move, is not recognised. Use legal_moves to obtain moves that satisfy this contract.

    Position::king_square

    fn Position::king_square(self : Position, color : Color) -> Square?

    The square of one colour's king, or None when the king is missing.

    Position::legal_moves

    fn Position::legal_moves(self : Position) -> Array[Move]

    The legal moves of the side to move.

    A move is legal when it is pseudo-legal and, once played, the mover's own king is not attacked. Castling additionally requires that the king is not in check, does not cross an attacked square and does not land on one. An en passant capture is checked after the captured pawn has been removed, so a capture that opens a rank to the king is rejected.

    Position::make_move

    fn Position::make_move(self : Position, played : Move) -> Position

    Applies a move and returns the resulting position.

    The move is applied as written, so this does not check king safety: a move that leaves the mover in check still produces the position it describes. The origin square must hold a piece, which is always true for a move that came out of pseudo_legal_moves.

    The step updates everything FEN records: the piece bitboards, a capture on the target square, the pawn removed by an en passant capture, the promoted piece, the rook of a castling, the castling rights lost by a king or rook move or by the capture of a rook on its home square, the en passant target after a double pawn push, the halfmove clock and the move number.

    Position::new

    fn Position::new(pieces : FixedArray[UInt64], turn : Color, castling : CastlingRights, ep_square : Square?, halfmove_clock : Int, fullmove_number : Int) -> Position

    Builds a position from raw fields.

    pieces must hold twelve bitboards in colour-major order: the six white kinds first, then the six black kinds, each ordered pawn, knight, bishop, rook, queen, king.

    Position::not_equal

    fn Position::not_equal(x : Position, y : Position) -> Bool

    Position::occupancy

    fn Position::occupancy(self : Position) -> Bitboard

    Every occupied square.

    Position::piece_at

    fn Position::piece_at(self : Position, square : Square) -> Piece?

    The piece on a square, or None when the square is empty.

    Position::piece_count

    fn Position::piece_count(self : Position) -> Int

    The number of pieces on the board.

    Position::pieces_of

    fn Position::pieces_of(self : Position, color : Color, kind : PieceKind) -> Bitboard

    The squares occupied by one colour and piece kind.
    fn Position::pseudo_legal_moves(self : Position) -> Array[Move]

    Every move of the side to move that ignores king safety.

    A position with a pinned piece therefore reports moves that would leave its own king in check, and castling is reported whenever the right and the empty path allow it. Filtering through is_legal is the task of the next increment; this list is what perft-style bookkeeping starts from.
    fn Position::pseudo_legal_moves_from(self : Position, square : Square) -> Array[Move]

    The pseudo-legal moves that start on a square.

    Position::startpos

    fn Position::startpos() -> Position

    The standard starting position.

    Position::to_ascii

    fn Position::to_ascii(self : Position) -> String

    Renders the board as an eight by eight diagram using FEN letters, upper-case for white.

    Position::to_fen

    fn Position::to_fen(self : Position) -> String

    Renders the position as a FEN document with all six fields.

    Position::to_repr

    Position::to_unicode

    fn Position::to_unicode(self : Position) -> String

    Renders the board as an eight by eight diagram using the Unicode chess symbols.

    Position::try_from_fen

    fn Position::try_from_fen(fen : String) -> Result[Position, FenError]

    Parses a FEN document and returns the error instead of raising it.

    Position::turn

    fn Position::turn(self : Position) -> Color

    The side that is to move.

    Position::zobrist_hash

    fn Position::zobrist_hash(self : Position) -> UInt64

    Computes the position key with the shared key tables.

    Square

    pub(all) struct Square(Int) derive(Eq,
    Debug
    )

    A board square, encoded as rank * 8 + file.

    Index 0 is a1 and index 63 is h8. The layout matches the little-endian rank-file order used by Bitboard, so bit i always refers to Square(i).
    impl Show for Square

    Square::all

    fn Square::all() -> Array[Square]

    All 64 squares in index order.

    Square::equal

    fn Square::equal(Square, Square) -> Bool

    Square::file

    fn Square::file(self : Square) -> Int

    The file of the square, 0 for a and 7 for h.

    Square::file_char

    fn Square::file_char(file : Int) -> Char

    The file letter for a file index in 0..=7.

    Square::from_file_rank

    fn Square::from_file_rank(file : Char, rank : Char) -> Square?

    Builds a square from algebraic coordinates such as e4.

    Square::from_index

    fn Square::from_index(index : Int) -> Square?

    Wraps an index in 0..=63, or returns None when it is out of range.

    Square::index

    fn Square::index(self : Square) -> Int

    The raw index of the square in 0..=63.

    Square::is_light

    fn Square::is_light(self : Square) -> Bool

    Whether the square belongs to the light squares of the board.

    Square::make

    fn Square::make(file : Int, rank : Int) -> Square

    Builds a square from a file (0 is a) and a rank (0 is rank 1).

    Square::not_equal

    fn Square::not_equal(x : Square, y : Square) -> Bool

    Square::offset

    fn Square::offset(self : Square, file_delta : Int, rank_delta : Int) -> Square?

    Moves the square by a file and rank delta, or returns None when the result would leave the board.

    Square::output

    fn Square::output(self : Square, logger : &Logger) -> Unit

    Square::parse

    fn Square::parse(text : String) -> Square?

    Parses an algebraic square name such as e4 or h8.

    Square::rank

    fn Square::rank(self : Square) -> Int

    The rank of the square, 0 for rank 1 and 7 for rank 8.

    Square::rank_char

    fn Square::rank_char(rank : Int) -> Char

    The rank digit for a rank index in 0..=7.

    Square::to_repr

    Square::to_string

    fn Square::to_string(self : Square) -> String

    Zobrist

    pub(all) struct Zobrist {
    // private fields
    } derive(
    Debug
    )

    Deterministic Zobrist keys for chess positions.

    The tables are derived from fixed seeds with the SplitMix64 finalizer, so the same key is produced on every run and on every backend.

    Zobrist::castling_key

    fn Zobrist::castling_key(self : Zobrist, rights : CastlingRights) -> UInt64

    The key of one castling right combination.

    Zobrist::en_passant_key

    fn Zobrist::en_passant_key(self : Zobrist, file : Int) -> UInt64

    The key of an en passant file.

    Zobrist::hash

    fn Zobrist::hash(self : Zobrist, position : Position) -> UInt64

    Computes the key of a position.

    Two positions that differ only in the move number usually share a key, which is what repetition detection needs.

    Zobrist::new

    fn Zobrist::new() -> Zobrist

    Builds the key tables.

    Zobrist::piece_key

    fn Zobrist::piece_key(self : Zobrist, piece : Piece, square : Square) -> UInt64

    The key of one piece on one square.

    Zobrist::side_key

    fn Zobrist::side_key(self : Zobrist) -> UInt64

    The key that marks black to move.

    Zobrist::to_repr

    start_fen

    fn start_fen() -> String

    The FEN document of the standard starting position.