alcibiades 0.2.5

A framework for writing chess engines in Rust

Crate alcibiades [] [src]

This crate provides a framework for writing chess engines.

Why chess engines?

Simple! Chess is the greatest thing humans have invented. Computers follow closely ;)

Why a framework?

There is lots of knowledge out there about how to write a chess engine, and there is a lot of room for innovation also. Writing a chess engine is fun, but even for the simplest engine there is a lot of complex (and boring) things that have to be implemented first: the UCI protocol communication, the rules, the static exchange evaluator, and many more. Thousands of programmers have been re-implementing those things over and over again.

So, if you want to write your own chess engine, you face an unpleasant choice: You either roll up your sleeves and implement all the hard stuff from scratch, or you take someone else's chess engine and struggle to understand its cryptic, undocumented source code, hoping that it will be general enough to allow modification. This unfortunate situation stifles innovation.

Usage

This crate is on crates.io and can be used by adding alcibiades to your dependencies in your project's Cargo.toml.

[dependencies]
alcibiades = "0.2.5"

and this to your crate root:

extern crate alcibiades;

Here is how simple it is to create a chess engine using this crate:

extern crate alcibiades;
use alcibiades::stock::*;
use alcibiades::engine::run_uci;

fn main() {
    type SearchNode = StdSearchNode<StdQsearch<StdMoveGenerator<SimpleEvaluator>>>;
    type SearchExecutor = Deepening<StdSearchExecutor<StdHashTable, SearchNode>>;
    run_uci::<SearchExecutor, StdTimeManager>("My engine", "John Doe");
}

This engine is assembled from the "in stock" implementations of the different framework traits.

In reality, you will probably want to write your own implementations for some of the framework traits. Thanks to Rust's incredible generic programming capabilities, you are not limited to implementing only the methods required by the traits. For example you may write your own static position evaluator which has a consult_endgame_table method. Then you will be able to write a search algorithm that uses this method.

Speed and safety

This crate tries to be fast and memory-safe.

Modules

bitsets

Defines constants and functions for working with bitboards.

engine

Implements a generic chess engine.

files

Defines a constant for each file on the board.

ranks

Defines a constant for each rank on the board.

squares

Defines a constant for each square on the board.

stock

Implementations of various traits.

utils

Defines generally useful functions and types.

Structs

Board

Holds a chess position.

CastlingRights

Holds information about which player can castle on which side.

IllegalBoard

Represents an illegal position error.

Move

Represents a move on the chessboard.

MoveDigest

Encodes the minimum needed information that unambiguously describes a move.

PiecesPlacement

Describes how the pieces are placed on the board.

QsearchParams

Parameters describing a quiescence search.

RemainingTime

Describes the remaining time on the clocks.

SearchParams

Parameters describing a search.

SearchReport

A progress report from a search.

Variation

A sequence of moves from some starting position, together with the value assigned to the final position.

Enums

OptionDescription

Describes a configuration option.

Constants

BISHOP
BLACK
BOUND_EXACT
BOUND_LOWER
BOUND_NONE
BOUND_UPPER
DEPTH_MAX
DEPTH_MIN
KING
KINGSIDE
KNIGHT
MOVE_CASTLING
MOVE_ENPASSANT
MOVE_NORMAL
MOVE_PROMOTION
PAWN
PIECE_NONE
QUEEN
QUEENSIDE
ROOK
VALUE_EVAL_MAX
VALUE_EVAL_MIN
VALUE_MAX
VALUE_MIN
VALUE_UNKNOWN
WHITE

Traits

AddMove

A trait for adding moves to move containers.

Evaluator

A trait used to statically evaluate positions.

HashTable

A trait for transposition tables.

HashTableEntry

A trait for transposition table entries.

MoveGenerator

A trait for move generators.

Qsearch

A trait for performing quiescence searches.

QsearchResult

A trait for quiescence searches' results.

SearchExecutor

A trait for executing consecutive searches in different starting positions.

SearchNode

A trait for chess positions -- a convenient interface for the tree-searching algorithm.

SetOption

A trait for announcing and changing configuration options.

TimeManager

A trait for deciding when the search must be terminated and the best move played.

Type Definitions

Bitboard

A set of squares on the chessboard.

BoundType

BOUND_EXACT, BOUND_LOWER, BOUND_UPPER, or BOUND_NONE.

CastlingSide

QUEENSIDE or KINGSIDE.

Color

WHITE or BLACK.

Depth

Search depth in half-moves.

MoveType

MOVE_ENPASSANT, MOVE_PROMOTION, MOVE_CASTLING, or MOVE_NORMAL.

PieceType

KING, QUEEN, ROOK, BISHOP, KINGHT, PAWN or PIECE_NONE.

Square

From 0 to 63 (0 is A1, 1 is B1, .. , 62 is G8, 63 is H8).

Value

Evaluation value in centipawns.