Tanton

Tanton is a Chess Library, containing the building blocks of the chess engine Stockfish, re-written entirely in Rust.

It is a fork of a now unmaintained project Pleco.

Tanton crate

This project is split into two crates, tanton (the library you are currently in), which contains the library functionality, and tanton_engine, which contains the UCI (Universal Chess Interface) compatible Engine & AI.

The overall goal of tanton is to recreate the Stockfish engine in rust, for comparison and educational purposes. As such, the majority of the algorithms used here are a direct port of Stockfish's, and the credit for the majority of the code go directly to the maintainers and authors of Stockfish.

For the chess engine implemented using this library provided by tanton, see tanton_engine.

Features

Some of the features tanton implements:

Use

To use Tanton inside your own Rust projects, Tanton.rs is available as a library on crates.io. Tanton runs on all three distributions (nightly, beta, stable) of rust.

Basic Usage

Setting up a board position is extremely simple.

```rust use tanton::{Board,Player,PieceType};

let board = Board::startpos(); asserteq!(board.countpiece(Player::White,PieceType::P), 8); asserteq!(&board.fen(),"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"); ```

Creating a board from a Position

A Board can be created with any valid chess position using a valid FEN (Forsyth-Edwards Notation) String. Check out the Wikipedia article for more information on FEN Strings and their format.

rust let board: Board = Board::from_fen("rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 2").unwrap();

Applying and Generating Moves

Moves are represented with a BitMove structure. They must be generated by a Board object directly, to be considered a valid move. Using Board::generate_moves() will generate all legal BitMoves of the current position for the current player.

```rust use tanton::{Board,BitMove};

let mut board = Board::startpos(); // create a board of the starting position let moves = board.generatemoves(); // generate all possible legal moves board.applymove(moves[0]); asserteq!(board.moves_played(), 1); ```

We can ask the Board to apply a move to itself from a string. This string must follow the format of a standard UCI Move, in the format [srcsq][dstsq][promo]. E.g., moving a piece from A1 to B3 would have a uci string of "a1b3", while promoting a pawn would look something like "e7e81". If the board is supplied a UCI move that is either incorrectly formatted or illegal, false shall be returned.

rust let mut board = Board::start_pos(); // create a board of the starting position let success = board.apply_uci_move("e7e8q"); // apply a move where piece on e7 -> eq, promotes to queen assert!(!success); // Wrong, not a valid move for the starting position

Undoing Moves

We can revert to the previous chessboard state with a simple Board::undo_move():

rust let mut board = Board::start_pos(); board.apply_uci_move("e2e4"); // A very good starting move, might I say assert_eq!(board.moves_played(),1); board.undo_move(); assert_eq!(board.moves_played(),0);