BitsChess is a chess library written in Rust. It was mainly written for the chess engine GiffiBot which i'm currently working on, but BitsChess is open for everybody to use under the MIT license.
Behind the scenes BitsChess uses bitboards for board representation. Attack, check, pin -masks and magic bitboards for move generation.
Add BitsChess as a dependency into a Cargo.toml
[dependencies]
bitschess = { git = "https://github.com/miklaskarjalainen/BitsChess.git" }
A simple example of using the BitsChess library
use bitschess::Move;
use bitschess::prelude::*;
fn main() {
// Creating a board
let mut board = ChessBoard::new();
board.parse_fen(STARTPOS_FEN).expect("valid fen");
// Making moves from uci commands
board.make_move_uci("e2e4").unwrap();
board.make_move_uci("a7a5").unwrap();
board.make_move_uci("e4e5").unwrap();
board.make_move_uci("d7d5").unwrap();
board.make_move_uci("e5d6").unwrap(); // en passant
board.make_move_uci("a5a4").unwrap();
board.make_move_uci("d6e7").unwrap();
board.make_move_uci("a4a3").unwrap();
board.make_move_uci("e7f8r").unwrap(); // promote pawn to a rook
let legal_moves_uci: Vec<String> = board.get_legal_moves().into_iter().map(|m: Move| {
m.to_uci()
}).collect();
println!("{}", board);
println!("------------------------");
println!("Legal Moves: {:?}", legal_moves_uci);
}
BitsChess can be compiled as a binary, and it has a very primitive CLI which is mainly there for development purposes.
git clone https://github.com/miklaskarjalainen/BitsChess
cd BitsChess
cargo build --bin bitschess-bin # add '--release' for optimized builds
For the cli commands have look at main.rs they are all in there. They all are subject for change and is the reason they are not listed here (yet).
The repository contains unit tests which can be ran with the command:
cargo test # add '--release' for optimized builds
Sources for the content which helped me to develop this chess library!
https://www.chessprogramming.org/
https://www.youtube.com/watch?v=U4ogK0MIzqk
https://www.youtube.com/@chessprogramming591