Expand description
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.
§Features
-
Modular design. Users can write their own implementations for every part of the chess engine.
-
Very good default implementations — move generation, quiescence search, static exchange evaluation, time management, iterative deepening, multi-PV, aspiration windows, generic transposition table.
-
Very complete UCI support (including “searchmoves”).
§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.3.0"
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 Ttable = StdTtable<StdTtableEntry>;
type SearchNode = StdSearchNode<StdQsearch<StdMoveGenerator<SimpleEvaluator>>>;
type SearchExecutor = Deepening<SimpleSearch<Ttable, SearchNode>>;
run_uci::<SearchExecutor, StdTimeManager>("My engine", "John Doe", vec![]);
}
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.
- Castling
Rights - Holds information about which player can castle on which side.
- Illegal
Board - Represents an illegal position error.
- Move
- Represents a move on the chessboard.
- Move
Digest - Encodes the minimum needed information that unambiguously describes a move.
- Pieces
Placement - Describes how the pieces are placed on the board.
- Qsearch
Params - Parameters describing a quiescence search.
- Remaining
Time - Describes the remaining time on the clocks.
- Search
Params - Parameters describing a search.
- Search
Report - 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§
- Option
Description - 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.
- Deepening
Search - A trait for executing iterative deepening searches.
- Evaluator
- A trait used to statically evaluate positions.
- Move
Generator - A trait for move generators.
- Qsearch
- A trait for performing quiescence searches.
- Qsearch
Result - A trait for quiescence searches’ results.
- Search
- A trait used to execute depth-first searches.
- Search
Node - A trait for chess positions – a convenient interface for the tree-searching algorithm.
- SetOption
- A trait for announcing and changing configuration options.
- Time
Manager - A trait for deciding when the search must be terminated and the best move played.
- Ttable
- A trait for transposition tables.
- Ttable
Entry - A trait for transposition table entries.
Functions§
- get_
option - Returns the current value for a given configuration option.
Type Aliases§
- Bitboard
- A set of squares on the chessboard.
- Bound
Type BOUND_EXACT
,BOUND_LOWER
,BOUND_UPPER
, orBOUND_NONE
.- Castling
Side QUEENSIDE
orKINGSIDE
.- Color
WHITE
orBLACK
.- Depth
- Search depth in half-moves.
- Move
Type MOVE_ENPASSANT
,MOVE_PROMOTION
,MOVE_CASTLING
, orMOVE_NORMAL
.- Piece
Type KING
,QUEEN
,ROOK
,BISHOP
,KINGHT
,PAWN
orPIECE_NONE
.- Square
- From 0 to 63 (0 is A1, 1 is B1, .. , 62 is G8, 63 is H8).
- Value
- Evaluation value in centipawns.