chess_uci/chess_uci_demo/src/main.rs

42 lines
1.1 KiB
Rust

extern crate chess;
extern crate chess_uci;
use chess::ChessMove;
use chess_uci::*;
use std::process::{Command, Stdio};
use std::io::BufReader;
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(BufReader::new(sf_out), sf_in);
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.new_game();
uci.make_move(ChessMove::from_str("e2e4").expect("error converting e2e4"));
uci.push_raw("d\n");
uci.push_raw("quit\n");
while uci.pull_raw() != None {}
}