Crate owlchess

source ·
Expand description

Yet another Rust chess library

🦉🦉🦉

Owlchess is a chess library written in Rust, with emphasis on both speed and safety. Primarily designed for various chess GUIs and tools, it’s also possible to use Owlchess to build a fast chess engine.

The code is mostly derived from my chess engine SoFCheck, but rewritten in Rust with regard to safety.

This crate supports core chess functionality:

  • generate moves
  • make moves
  • calculate game outcome
  • parse and format boards in FEN
  • parse and format moves in UCI and SAN

Example

use owlchess::{Board, movegen::legal, Move};
use owlchess::{Coord, File, Rank};

// Create a board with initial position
let b = Board::initial();

// Generate all the legal moves
let moves = legal::gen_all(&b);
assert_eq!(moves.len(), 20);

// Parse move "e2e4" from UCI string
let mv = Move::from_uci("e2e4", &b).unwrap();
let e2 = Coord::from_parts(File::E, Rank::R2);
let e4 = Coord::from_parts(File::E, Rank::R4);
assert_eq!(mv.src(), e2);
assert_eq!(mv.dst(), e4);

// Create a new board with made move `mv`
let b = b.make_move(mv).unwrap();
assert_eq!(b.as_fen(), "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1");

Re-exports

Modules

  • Bitboard-related stuff
  • Board and related things
  • Board that remembers previous moves
  • Move generation and related things
  • Moves and related stuff
  • Core chess types

Structs

  • Bitmask on chess board
  • Flags specifying allowed castling sides for both white and black
  • Contents of square on a chess board
  • Coordinate of a square

Enums

  • Castling side (either queenside or kingside)
  • Color of chess pieces (either white or black)
  • Reason for game finish with draw
  • File (i. e. a vertical line) on a chess board
  • Short status of the game (either running of finished)
  • Outcome of the finished game
  • Kind of chess pieces (without regard to piece color)
  • Rank (i. e. a horizontal line) on a chess board
  • Reason for game finish with win