pub struct Stockfish { /* private fields */ }Expand description
The interface for interacting with a Stockfish process.
Implementations§
Source§impl Stockfish
impl Stockfish
Sourcepub fn new(path: &str) -> Result<Stockfish>
pub fn new(path: &str) -> Result<Stockfish>
Given the path to the Stockfish binary executable, this function
initiates an InteractiveProcess for the executable, and returns an instance
of the Stockfish wrapper class.
§Example
use stockfish::Stockfish;
let stockfish = Stockfish::new("stockfish.exe").unwrap();§Error
Returns an io::Error if an error occurred while trying to
create/communicate with the engine.
Examples found in repository?
4fn main() -> Result<(), std::io::Error> {
5 let path = if cfg!(target_os = "windows") {
6 "./stockfish.exe"
7 } else {
8 "stockfish"
9 };
10
11 let mut stockfish = Stockfish::new(&path)?;
12 stockfish.setup_for_new_game()?;
13 stockfish.print_board()?;
14
15 let engine_output = stockfish.go_for(Duration::from_millis(5000))?;
16 println!("engine_output: {engine_output:?}");
17
18 Ok(())
19}More examples
3fn main() -> Result<(), std::io::Error> {
4 let path = if cfg!(target_os = "windows") {
5 "./stockfish.exe"
6 } else {
7 "stockfish"
8 };
9
10 let mut stockfish = Stockfish::new(&path)?;
11 stockfish.setup_for_new_game()?;
12 stockfish.print_board()?;
13
14 let engine_output = stockfish.go_based_on_times(Some(50000), Some(10))?;
15 println!("engine_output: {engine_output:?}");
16
17 let fen = "r1bqkb1r/pppp1ppp/2n2n2/4p3/4P3/2N2N2/PPPP1PPP/R1BQKB1R w KQkq - 0 1";
18
19 stockfish.set_fen_position(fen)?;
20
21 assert_eq!(fen, stockfish.get_fen()?);
22
23 // Testing
24 let moves = ["e2e4", "e7e5", "f1c4"];
25 stockfish.play_moves(&moves)?;
26 //
27
28 Ok(())
29}3fn main() -> Result<(), std::io::Error> {
4 let path = if cfg!(target_os = "windows") {
5 "./stockfish.exe"
6 } else {
7 "stockfish"
8 };
9
10 let mut stockfish = Stockfish::new(&path)?;
11 stockfish.setup_for_new_game()?;
12 stockfish.print_board()?;
13
14 println!("Stockfish version: {:?}", stockfish.get_version());
15
16 stockfish.set_depth(20); // Optional; default depth is 15
17
18 let engine_output = stockfish.go()?;
19 println!("engine_output: {engine_output:?}");
20
21 // Play some moves!
22 let moves = ["e2e4", "e7e5", "g1f3"];
23 for move_str in moves {
24 stockfish.play_move(move_str)?;
25 stockfish.print_board()?;
26
27 let engine_output = stockfish.go()?;
28 println!("engine_output: {engine_output:?}");
29 }
30
31 stockfish.quit()?;
32
33 Ok(())
34}Sourcepub fn setup_for_new_game(&mut self) -> Result<()>
pub fn setup_for_new_game(&mut self) -> Result<()>
Prepares the Stockfish process for a new game. Should be called to indicate to the engine that the next position it will be evaluating will be from a different game.
§Example
let mut stockfish = Stockfish::new("stockfish.exe")?;
stockfish.setup_for_new_game()?;§Error
Returns an io::Error if an error occurred while trying to
communicate with the engine.
Examples found in repository?
4fn main() -> Result<(), std::io::Error> {
5 let path = if cfg!(target_os = "windows") {
6 "./stockfish.exe"
7 } else {
8 "stockfish"
9 };
10
11 let mut stockfish = Stockfish::new(&path)?;
12 stockfish.setup_for_new_game()?;
13 stockfish.print_board()?;
14
15 let engine_output = stockfish.go_for(Duration::from_millis(5000))?;
16 println!("engine_output: {engine_output:?}");
17
18 Ok(())
19}More examples
3fn main() -> Result<(), std::io::Error> {
4 let path = if cfg!(target_os = "windows") {
5 "./stockfish.exe"
6 } else {
7 "stockfish"
8 };
9
10 let mut stockfish = Stockfish::new(&path)?;
11 stockfish.setup_for_new_game()?;
12 stockfish.print_board()?;
13
14 let engine_output = stockfish.go_based_on_times(Some(50000), Some(10))?;
15 println!("engine_output: {engine_output:?}");
16
17 let fen = "r1bqkb1r/pppp1ppp/2n2n2/4p3/4P3/2N2N2/PPPP1PPP/R1BQKB1R w KQkq - 0 1";
18
19 stockfish.set_fen_position(fen)?;
20
21 assert_eq!(fen, stockfish.get_fen()?);
22
23 // Testing
24 let moves = ["e2e4", "e7e5", "f1c4"];
25 stockfish.play_moves(&moves)?;
26 //
27
28 Ok(())
29}3fn main() -> Result<(), std::io::Error> {
4 let path = if cfg!(target_os = "windows") {
5 "./stockfish.exe"
6 } else {
7 "stockfish"
8 };
9
10 let mut stockfish = Stockfish::new(&path)?;
11 stockfish.setup_for_new_game()?;
12 stockfish.print_board()?;
13
14 println!("Stockfish version: {:?}", stockfish.get_version());
15
16 stockfish.set_depth(20); // Optional; default depth is 15
17
18 let engine_output = stockfish.go()?;
19 println!("engine_output: {engine_output:?}");
20
21 // Play some moves!
22 let moves = ["e2e4", "e7e5", "g1f3"];
23 for move_str in moves {
24 stockfish.play_move(move_str)?;
25 stockfish.print_board()?;
26
27 let engine_output = stockfish.go()?;
28 println!("engine_output: {engine_output:?}");
29 }
30
31 stockfish.quit()?;
32
33 Ok(())
34}Sourcepub fn set_fen_position(&mut self, fen: &str) -> Result<()>
pub fn set_fen_position(&mut self, fen: &str) -> Result<()>
Changes the current chess position in which Stockfish is currently playing. The argument to be passed is a string in FEN (Forsyth-Edwards Notation).
§Example
let mut stockfish = Stockfish::new("stockfish.exe")?;
stockfish.set_fen_position("r1bqk2r/ppppppbp/2n2np1/8/8/2N2NP1/PPPPPPBP/R1BQK2R w KQkq - 0 1")?;
stockfish.print_board()?;§Error
Returns an io::Error if an error occurred while trying to
communicate with the engine.
Examples found in repository?
3fn main() -> Result<(), std::io::Error> {
4 let path = if cfg!(target_os = "windows") {
5 "./stockfish.exe"
6 } else {
7 "stockfish"
8 };
9
10 let mut stockfish = Stockfish::new(&path)?;
11 stockfish.setup_for_new_game()?;
12 stockfish.print_board()?;
13
14 let engine_output = stockfish.go_based_on_times(Some(50000), Some(10))?;
15 println!("engine_output: {engine_output:?}");
16
17 let fen = "r1bqkb1r/pppp1ppp/2n2n2/4p3/4P3/2N2N2/PPPP1PPP/R1BQKB1R w KQkq - 0 1";
18
19 stockfish.set_fen_position(fen)?;
20
21 assert_eq!(fen, stockfish.get_fen()?);
22
23 // Testing
24 let moves = ["e2e4", "e7e5", "f1c4"];
25 stockfish.play_moves(&moves)?;
26 //
27
28 Ok(())
29}Sourcepub fn reset_position(&mut self) -> Result<()>
pub fn reset_position(&mut self) -> Result<()>
Reverts the current chess position to the default starting position.
This is the same as calling set_fen_position with the default
fen. (rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1)
§Example
let mut stockfish = Stockfish::new("stockfish.exe")?;
stockfish.set_fen_position("r1bqk2r/ppppppbp/2n2np1/8/8/2N2NP1/PPPPPPBP/R1BQK2R w KQkq - 0 1")?;
stockfish.reset_position()?;
// See that the board has been reverted to the default position
stockfish.print_board()?;§Error
Returns an io::Error if an error occurred while trying to
communicate with the engine.
Sourcepub fn ensure_ready(&mut self) -> Result<()>
pub fn ensure_ready(&mut self) -> Result<()>
This should be called to ensure that the Stockfish process is ready
to receive its inputs. Sends the UCI command "isready" to Stockfish
and blocks until it sends back "readyok".
§Example
let mut stockfish = Stockfish::new("stockfish.exe")?;
stockfish.ensure_ready()?;
stockfish.setup_for_new_game()?;§Error
Returns an io::Error if an error occurred while trying to
communicate with the engine.
Sourcepub fn get_fen(&mut self) -> Result<String>
pub fn get_fen(&mut self) -> Result<String>
Returns a string Forsyth-Edwards notation (FEN) describing the current chess position in which Stockfish is playing.
§Example
let mut stockfish = Stockfish::new("stockfish.exe")?;
stockfish.play_move("e2e4")?;
let fen = stockfish.get_fen()?;
println!("fen after move was played: {fen}");§Error
Returns an io::Error if an error occurred while trying to
communicate with the engine.
Examples found in repository?
3fn main() -> Result<(), std::io::Error> {
4 let path = if cfg!(target_os = "windows") {
5 "./stockfish.exe"
6 } else {
7 "stockfish"
8 };
9
10 let mut stockfish = Stockfish::new(&path)?;
11 stockfish.setup_for_new_game()?;
12 stockfish.print_board()?;
13
14 let engine_output = stockfish.go_based_on_times(Some(50000), Some(10))?;
15 println!("engine_output: {engine_output:?}");
16
17 let fen = "r1bqkb1r/pppp1ppp/2n2n2/4p3/4P3/2N2N2/PPPP1PPP/R1BQKB1R w KQkq - 0 1";
18
19 stockfish.set_fen_position(fen)?;
20
21 assert_eq!(fen, stockfish.get_fen()?);
22
23 // Testing
24 let moves = ["e2e4", "e7e5", "f1c4"];
25 stockfish.play_moves(&moves)?;
26 //
27
28 Ok(())
29}Sourcepub fn play_move(&mut self, move_str: &str) -> Result<()>
pub fn play_move(&mut self, move_str: &str) -> Result<()>
Plays a move on the current chess position in which Stockfish is playing. This function only updates the board; it does not prompt Stockfish to begin calculating.
§Example
let mut stockfish = Stockfish::new("stockfish.exe")?;
stockfish.print_board()?;
stockfish.play_move("e2e4")?;
// See that the move has been played on the board
stockfish.print_board()?;§Error
Returns an io::Error if an error occurred while trying to
communicate with the engine.
Examples found in repository?
3fn main() -> Result<(), std::io::Error> {
4 let path = if cfg!(target_os = "windows") {
5 "./stockfish.exe"
6 } else {
7 "stockfish"
8 };
9
10 let mut stockfish = Stockfish::new(&path)?;
11 stockfish.setup_for_new_game()?;
12 stockfish.print_board()?;
13
14 println!("Stockfish version: {:?}", stockfish.get_version());
15
16 stockfish.set_depth(20); // Optional; default depth is 15
17
18 let engine_output = stockfish.go()?;
19 println!("engine_output: {engine_output:?}");
20
21 // Play some moves!
22 let moves = ["e2e4", "e7e5", "g1f3"];
23 for move_str in moves {
24 stockfish.play_move(move_str)?;
25 stockfish.print_board()?;
26
27 let engine_output = stockfish.go()?;
28 println!("engine_output: {engine_output:?}");
29 }
30
31 stockfish.quit()?;
32
33 Ok(())
34}Sourcepub fn play_moves(&mut self, moves: &[&str]) -> Result<()>
pub fn play_moves(&mut self, moves: &[&str]) -> Result<()>
Plays a sequence of moves on the current chess position in which Stockfish is playing. This function only updates the board; it does not prompt Stockfish to begin calculating.
§Example
let mut stockfish = Stockfish::new("stockfish.exe")?;
stockfish.print_board()?;
let moves = ["e2e4", "e7e5", "f1c4"];
stockfish.play_moves(&moves)?;
// See that the moves have been played on the board
stockfish.print_board()?;§Error
Returns an io::Error if an error occurred while trying to
communicate with the engine.
Examples found in repository?
3fn main() -> Result<(), std::io::Error> {
4 let path = if cfg!(target_os = "windows") {
5 "./stockfish.exe"
6 } else {
7 "stockfish"
8 };
9
10 let mut stockfish = Stockfish::new(&path)?;
11 stockfish.setup_for_new_game()?;
12 stockfish.print_board()?;
13
14 let engine_output = stockfish.go_based_on_times(Some(50000), Some(10))?;
15 println!("engine_output: {engine_output:?}");
16
17 let fen = "r1bqkb1r/pppp1ppp/2n2n2/4p3/4P3/2N2N2/PPPP1PPP/R1BQKB1R w KQkq - 0 1";
18
19 stockfish.set_fen_position(fen)?;
20
21 assert_eq!(fen, stockfish.get_fen()?);
22
23 // Testing
24 let moves = ["e2e4", "e7e5", "f1c4"];
25 stockfish.play_moves(&moves)?;
26 //
27
28 Ok(())
29}Sourcepub fn go(&mut self) -> Result<EngineOutput>
pub fn go(&mut self) -> Result<EngineOutput>
Makes Stockfish calculate to the depth that has been set. (The default depth is 15.)
Once Stockfish has finished its calculations, this function should return
an EngineOutput describing the result of its calculations.
§Example
let mut stockfish = Stockfish::new("stockfish.exe")?;
let engine_output = stockfish.go()?;
println!("output from stockfish: {engine_output:?}");§Error
Returns an io::Error if an error occurred while trying to
communicate with the engine.
Examples found in repository?
3fn main() -> Result<(), std::io::Error> {
4 let path = if cfg!(target_os = "windows") {
5 "./stockfish.exe"
6 } else {
7 "stockfish"
8 };
9
10 let mut stockfish = Stockfish::new(&path)?;
11 stockfish.setup_for_new_game()?;
12 stockfish.print_board()?;
13
14 println!("Stockfish version: {:?}", stockfish.get_version());
15
16 stockfish.set_depth(20); // Optional; default depth is 15
17
18 let engine_output = stockfish.go()?;
19 println!("engine_output: {engine_output:?}");
20
21 // Play some moves!
22 let moves = ["e2e4", "e7e5", "g1f3"];
23 for move_str in moves {
24 stockfish.play_move(move_str)?;
25 stockfish.print_board()?;
26
27 let engine_output = stockfish.go()?;
28 println!("engine_output: {engine_output:?}");
29 }
30
31 stockfish.quit()?;
32
33 Ok(())
34}Sourcepub fn go_for(&mut self, calculation_time: Duration) -> Result<EngineOutput>
pub fn go_for(&mut self, calculation_time: Duration) -> Result<EngineOutput>
Makes Stockfish calculate for a specified amount of time. Blocks the calling thread for the duration of the specified calculation time.
Once Stockfish has finished its calculations, this function should return
an EngineOutput describing the result of its calculations.
§Example
use std::time::Duration;
let mut stockfish = Stockfish::new("stockfish.exe")?;
let engine_output = stockfish.go_for(Duration::from_millis(500))?;
println!("output from stockfish: {engine_output:?}");§Error
Returns an io::Error if an error occurred while trying to
communicate with the engine.
Examples found in repository?
4fn main() -> Result<(), std::io::Error> {
5 let path = if cfg!(target_os = "windows") {
6 "./stockfish.exe"
7 } else {
8 "stockfish"
9 };
10
11 let mut stockfish = Stockfish::new(&path)?;
12 stockfish.setup_for_new_game()?;
13 stockfish.print_board()?;
14
15 let engine_output = stockfish.go_for(Duration::from_millis(5000))?;
16 println!("engine_output: {engine_output:?}");
17
18 Ok(())
19}Sourcepub fn go_based_on_times(
&mut self,
white_time: Option<u32>,
black_time: Option<u32>,
) -> Result<EngineOutput>
pub fn go_based_on_times( &mut self, white_time: Option<u32>, black_time: Option<u32>, ) -> Result<EngineOutput>
Makes Stockfish calculate for a variable time based on the times given as parameters.
If for example Stockfish were analyzing from the white side and white_time is low
(say, only 10 seconds), then Stockfish will use less time for its calculation.
The parameters are to be given in milliseconds.
Once Stockfish has finished its calculations, this function should return
an EngineOutput describing the result of its calculations.
§Example
let mut stockfish = Stockfish::new("stockfish.exe")?;
let engine_output = stockfish.go_based_on_times(
Some(50_000), // White has 50 seconds
Some(55_000), // Black has 55 seconds
)?;
println!("output from stockfish: {engine_output:?}");§Error
Returns an io::Error if an error occurred while trying to
communicate with the engine.
Examples found in repository?
3fn main() -> Result<(), std::io::Error> {
4 let path = if cfg!(target_os = "windows") {
5 "./stockfish.exe"
6 } else {
7 "stockfish"
8 };
9
10 let mut stockfish = Stockfish::new(&path)?;
11 stockfish.setup_for_new_game()?;
12 stockfish.print_board()?;
13
14 let engine_output = stockfish.go_based_on_times(Some(50000), Some(10))?;
15 println!("engine_output: {engine_output:?}");
16
17 let fen = "r1bqkb1r/pppp1ppp/2n2n2/4p3/4P3/2N2N2/PPPP1PPP/R1BQKB1R w KQkq - 0 1";
18
19 stockfish.set_fen_position(fen)?;
20
21 assert_eq!(fen, stockfish.get_fen()?);
22
23 // Testing
24 let moves = ["e2e4", "e7e5", "f1c4"];
25 stockfish.play_moves(&moves)?;
26 //
27
28 Ok(())
29}Sourcepub fn set_depth(&mut self, depth: u32)
pub fn set_depth(&mut self, depth: u32)
Configures the depth to which Stockfish will calculate. When methods like go
and go_for are called, this field is used to determine how deeply Stockfish will
calculate.
§Example
let mut stockfish = Stockfish::new("stockfish.exe")?;
stockfish.set_depth(20)?;
let engine_output = stockfish.go()?; // Stockfish will calculate to the newly set depth
println!("output from stockfish: {engine_output:?}");§Error
Returns an io::Error if an error occurred while trying to
communicate with the engine.
Examples found in repository?
3fn main() -> Result<(), std::io::Error> {
4 let path = if cfg!(target_os = "windows") {
5 "./stockfish.exe"
6 } else {
7 "stockfish"
8 };
9
10 let mut stockfish = Stockfish::new(&path)?;
11 stockfish.setup_for_new_game()?;
12 stockfish.print_board()?;
13
14 println!("Stockfish version: {:?}", stockfish.get_version());
15
16 stockfish.set_depth(20); // Optional; default depth is 15
17
18 let engine_output = stockfish.go()?;
19 println!("engine_output: {engine_output:?}");
20
21 // Play some moves!
22 let moves = ["e2e4", "e7e5", "g1f3"];
23 for move_str in moves {
24 stockfish.play_move(move_str)?;
25 stockfish.print_board()?;
26
27 let engine_output = stockfish.go()?;
28 println!("engine_output: {engine_output:?}");
29 }
30
31 stockfish.quit()?;
32
33 Ok(())
34}Sourcepub fn get_board_display(&mut self) -> Result<String>
pub fn get_board_display(&mut self) -> Result<String>
Returns a string showing a visual display of the current chess position in which Stockfish is playing.
§Example
let mut stockfish = Stockfish::new("stockfish.exe")?;
stockfish.play_move("d2d4")?;
let board = stockfish.get_board_display()?;
println!("board: {board}");§Illustration
Example of the output from Stockfish:
+---+---+---+---+---+---+---+---+
| r | n | b | q | k | b | n | r | 8
+---+---+---+---+---+---+---+---+
| p | p | p | p | p | p | p | p | 7
+---+---+---+---+---+---+---+---+
| | | | | | | | | 6
+---+---+---+---+---+---+---+---+
| | | | | | | | | 5
+---+---+---+---+---+---+---+---+
| | | | | | | | | 4
+---+---+---+---+---+---+---+---+
| | | | | | | | | 3
+---+---+---+---+---+---+---+---+
| P | P | P | P | P | P | P | P | 2
+---+---+---+---+---+---+---+---+
| R | N | B | Q | K | B | N | R | 1
+---+---+---+---+---+---+---+---+
a b c d e f g h§Error
Returns an io::Error if an error occurred while trying to
communicate with the engine.
Sourcepub fn print_board(&mut self) -> Result<()>
pub fn print_board(&mut self) -> Result<()>
This function simply prints the result from get_board_display.
§Example
let mut stockfish = Stockfish::new("stockfish.exe")?;
stockfish.play_move("d2d4")?;
stockfish.print_board()?;
stockfish.play_move("d7d5")?;
stockfish.print_board()?;§Error
Returns an io::Error if an error occurred while trying to
communicate with the engine.
Examples found in repository?
4fn main() -> Result<(), std::io::Error> {
5 let path = if cfg!(target_os = "windows") {
6 "./stockfish.exe"
7 } else {
8 "stockfish"
9 };
10
11 let mut stockfish = Stockfish::new(&path)?;
12 stockfish.setup_for_new_game()?;
13 stockfish.print_board()?;
14
15 let engine_output = stockfish.go_for(Duration::from_millis(5000))?;
16 println!("engine_output: {engine_output:?}");
17
18 Ok(())
19}More examples
3fn main() -> Result<(), std::io::Error> {
4 let path = if cfg!(target_os = "windows") {
5 "./stockfish.exe"
6 } else {
7 "stockfish"
8 };
9
10 let mut stockfish = Stockfish::new(&path)?;
11 stockfish.setup_for_new_game()?;
12 stockfish.print_board()?;
13
14 let engine_output = stockfish.go_based_on_times(Some(50000), Some(10))?;
15 println!("engine_output: {engine_output:?}");
16
17 let fen = "r1bqkb1r/pppp1ppp/2n2n2/4p3/4P3/2N2N2/PPPP1PPP/R1BQKB1R w KQkq - 0 1";
18
19 stockfish.set_fen_position(fen)?;
20
21 assert_eq!(fen, stockfish.get_fen()?);
22
23 // Testing
24 let moves = ["e2e4", "e7e5", "f1c4"];
25 stockfish.play_moves(&moves)?;
26 //
27
28 Ok(())
29}3fn main() -> Result<(), std::io::Error> {
4 let path = if cfg!(target_os = "windows") {
5 "./stockfish.exe"
6 } else {
7 "stockfish"
8 };
9
10 let mut stockfish = Stockfish::new(&path)?;
11 stockfish.setup_for_new_game()?;
12 stockfish.print_board()?;
13
14 println!("Stockfish version: {:?}", stockfish.get_version());
15
16 stockfish.set_depth(20); // Optional; default depth is 15
17
18 let engine_output = stockfish.go()?;
19 println!("engine_output: {engine_output:?}");
20
21 // Play some moves!
22 let moves = ["e2e4", "e7e5", "g1f3"];
23 for move_str in moves {
24 stockfish.play_move(move_str)?;
25 stockfish.print_board()?;
26
27 let engine_output = stockfish.go()?;
28 println!("engine_output: {engine_output:?}");
29 }
30
31 stockfish.quit()?;
32
33 Ok(())
34}Sourcepub fn set_option(
&mut self,
option_name: &str,
option_value: &str,
) -> Result<()>
pub fn set_option( &mut self, option_name: &str, option_value: &str, ) -> Result<()>
Sets a UCI option for the Stockfish engine. This is used for changing the engine’s internal parameters.
§Example
let mut stockfish = Stockfish::new("stockfish.exe")?;
stockfish.set_option("Move Overhead", "20")?;The following is a listing of some of the possible options and their default values. (Note: these may be subject to change, and may not be universal.)
"Threads": 1,"Hash": 16,"Debug Log File": “”,"Contempt": 0,"Min Split Depth": 0,"Ponder": “false”,"MultiPV": 1,"Move Overhead": 10,"Minimum Thinking Time": 20,"Slow Mover": 100,"UCI_Chess960": “false”,"UCI_LimitStrength": “false”,"UCI_Elo": 1350,"Skill Level": 20,
§Error
Returns an io::Error if an error occurred while trying to
communicate with the engine.
Sourcepub fn set_hash(&mut self, hash: u32) -> Result<()>
pub fn set_hash(&mut self, hash: u32) -> Result<()>
Sets the size of Stockfish’s hashtable/transposition table. Value is given in megabytes. Generally, the larger the table, the faster the engine will run.
§Example
let mut stockfish = Stockfish::new("stockfish.exe")?;
stockfish.set_hash(64)?;§Error
Returns an io::Error if an error occurred while trying to
communicate with the engine.
Sourcepub fn set_threads(&mut self, threads: u32) -> Result<()>
pub fn set_threads(&mut self, threads: u32) -> Result<()>
Sets the number of CPU threads that Stockfish will use in its calculations. For Stockfish, it’s recommended to set this equal to the number of available CPU cores on your machine.
§Example
let mut stockfish = Stockfish::new("stockfish.exe")?;
stockfish.set_threads(16)?;§Error
Returns an io::Error if an error occurred while trying to
communicate with the engine.
Sourcepub fn set_elo(&mut self, elo: u32) -> Result<()>
pub fn set_elo(&mut self, elo: u32) -> Result<()>
Sets the elo at which Stockfish will aim to play.
Similar to set_skill_level in functionality, however, calling
either one of these two functions will override the effect of the other.
§Example
let mut stockfish = Stockfish::new("stockfish.exe")?;
stockfish.set_fen_position("r1bqkbnr/ppp1pppp/2np4/8/8/3P4/PPPBPPPP/RN1QKBNR w KQkq - 0 1")?;
stockfish.set_skill_level(10)?; // The effect of this call is overridden by set_elo
stockfish.set_elo(1450)?;
let engine_output = stockfish.go()?;§Error
Returns an io::Error if an error occurred while trying to
communicate with the engine.
Sourcepub fn set_skill_level(&mut self, skill_level: u32) -> Result<()>
pub fn set_skill_level(&mut self, skill_level: u32) -> Result<()>
Sets the skill level at which Stockfish will aim to play. Skill level is given in the range of 0 to 20 (from weakest to strongest.)
Similar to set_elo in functionality, however, calling either one of
these two functions will override the effect of the other.
§Example
let mut stockfish = Stockfish::new("stockfish.exe")?;
stockfish.set_fen_position("r1bqkbnr/ppp1pppp/2np4/8/8/3P4/PPPBPPPP/RN1QKBNR w KQkq - 0 1")?;
stockfish.set_elo(2500)?; // The effect of this call is overridden by set_skill_level
stockfish.set_skill_level(16)?;
let engine_output = stockfish.go()?;§Error
Returns an io::Error if an error occurred while trying to
communicate with the engine.
Sourcepub fn get_version(&self) -> &Option<String>
pub fn get_version(&self) -> &Option<String>
Returns a string representing the version of Stockfish being run.
Returns None if the version wasn’t able to be parsed from Stockfish’s
output.
Examples found in repository?
3fn main() -> Result<(), std::io::Error> {
4 let path = if cfg!(target_os = "windows") {
5 "./stockfish.exe"
6 } else {
7 "stockfish"
8 };
9
10 let mut stockfish = Stockfish::new(&path)?;
11 stockfish.setup_for_new_game()?;
12 stockfish.print_board()?;
13
14 println!("Stockfish version: {:?}", stockfish.get_version());
15
16 stockfish.set_depth(20); // Optional; default depth is 15
17
18 let engine_output = stockfish.go()?;
19 println!("engine_output: {engine_output:?}");
20
21 // Play some moves!
22 let moves = ["e2e4", "e7e5", "g1f3"];
23 for move_str in moves {
24 stockfish.play_move(move_str)?;
25 stockfish.print_board()?;
26
27 let engine_output = stockfish.go()?;
28 println!("engine_output: {engine_output:?}");
29 }
30
31 stockfish.quit()?;
32
33 Ok(())
34}Sourcepub fn quit(&mut self) -> Result<()>
pub fn quit(&mut self) -> Result<()>
Sends the "quit" UCI command to the Stockfish process, whereupon it
will attempt to quit the program as soon as possible.
§Example
let mut stockfish = Stockfish::new("stockfish.exe")?;
stockfish.set_fen_position("rn1qkbnr/pbpppppp/1p6/8/8/1P2P3/PBPP1PPP/RN1QKBNR w KQkq - 0 1")?;
let engine_output = stockfish.go()?;
stockfish.quit()?;§Error
Returns an io::Error if an error occurred while trying to
communicate with the engine.
Examples found in repository?
3fn main() -> Result<(), std::io::Error> {
4 let path = if cfg!(target_os = "windows") {
5 "./stockfish.exe"
6 } else {
7 "stockfish"
8 };
9
10 let mut stockfish = Stockfish::new(&path)?;
11 stockfish.setup_for_new_game()?;
12 stockfish.print_board()?;
13
14 println!("Stockfish version: {:?}", stockfish.get_version());
15
16 stockfish.set_depth(20); // Optional; default depth is 15
17
18 let engine_output = stockfish.go()?;
19 println!("engine_output: {engine_output:?}");
20
21 // Play some moves!
22 let moves = ["e2e4", "e7e5", "g1f3"];
23 for move_str in moves {
24 stockfish.play_move(move_str)?;
25 stockfish.print_board()?;
26
27 let engine_output = stockfish.go()?;
28 println!("engine_output: {engine_output:?}");
29 }
30
31 stockfish.quit()?;
32
33 Ok(())
34}