stockfish
A wrapper library that makes integrating Stockfish with Rust a breeze.
An installation of the Stockfish engine is needed. (Or any UCI-compatible engine, although this library was mainly written with Stockfish in mind.)
Usage
Add this to your Cargo.toml:
[]
= "0.2.11"
And this to your source code:
use Stockfish;
Example usage
Using the path to the Stockfish executable, construct an instance. (Mind the ?; it's possible that any of these operations may fail, as they involve IO operations.)
let mut stockfish = new?;
Once created, setup the engine:
stockfish.setup_for_new_game?;
Direct the engine to the desired position on the board; this may be done through a sequence of moves from the regular starting position:
stockfish.play_moves?;
Or through setting its position via Forsyth-Edwards notation (FEN):
let fen = "r1bqkb1r/pppp1ppp/2n2n2/4p3/4P3/2N2N2/PPPP1PPP/\
R1BQKB1R w KQkq - 0 1";
stockfish.set_fen_position?;
Then, calculation may be initiated through various methods, the simplest of which
is go, which makes Stockfish calculate until it reaches a certain depth:
stockfish.set_depth; // Optional; default depth is 15
let engine_output = stockfish.go?;
The returned EngineOutput may be worked with like so:
let best_move = engine_output.best_move;
println!;
let eval = engine_output.eval;
match eval.eval_type ;
A longer example
use Stockfish;
Other details
Some different ways of invoking calculation from Stockfish:
// Have stockfish calculate for five seconds, then get its output
let engine_output = stockfish.go_for?;
// Have stockfish calculate for a variable amount of time based on
// the players' move times in the chess game
// (expressed in milliseconds)
let engine_output = stockfish.go_based_on_times;
Some configuration options (of which the most likely to be changed would be hash table size and thread count):
stockfish.set_threads?;
stockfish.set_hash?;
// Set any UCI option for stockfish
stockfish.set_option?;