extern crate chess; extern crate chess_uci; use chess::ChessMove; use chess_uci::*; use chess_uci::uci_command::EngineCommand; use std::process::{Command, Stdio}; use std::str::FromStr; pub fn main(){ env_logger::init(); println!("Launching hardcoded stockfish program (should be in PATH)"); // launch chess program let process = match Command::new("stockfish") .stdin(Stdio::piped()) .stdout(Stdio::piped()) .spawn() { Err(why) => panic!("couldn't spawn stockfish: {}", why), Ok(process) => process, }; let (sf_in,sf_out) = (process.stdin.expect("Program stdin"), process.stdout.expect("Program stdout")); let mut uci = UciEngine::new(Some(sf_out), Some(sf_in)); uci.game_option(GameOption::WhitePlayer { value: Player::Human { elo: None } }); uci.game_option(GameOption::BlackPlayer { value: Player::Machine { elo: Some(1500) } }); uci.init(); println!("Engine: {} \nby: {}", if let Some(name) = uci.name() {name} else {"Not defined".to_string()}, if let Some(author) = uci.author() {author} else {"Not defined".to_string()}); uci.push(uci_command::GuiCommand::SetOption { option: uci_command::Opt::SlowMover { value: 11 }}); uci.new_game(); uci.push_raw("d\n"); uci.human_play(ChessMove::from_str("e2e4").expect("error converting e2e4")).expect("can not make human move"); uci.push_raw("d\n"); uci.go().expect("can not make engine move"); loop { match uci.pull() { Some(EngineCommand::BestMove { best_move, .. }) => { uci.make_move(best_move); break }, Some(EngineCommand::Info { .. }) => continue, _ => continue, } } uci.push_raw("d\n"); uci.push_raw("quit\n"); while uci.pull_raw().is_some() {} }