Skip to main content

demo/
demo.rs

1use stockfish::Stockfish;
2
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}