diff options
Diffstat (limited to 'src/grossmeister/UCI.rs')
-rw-r--r-- | src/grossmeister/UCI.rs | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/grossmeister/UCI.rs b/src/grossmeister/UCI.rs new file mode 100644 index 0000000..2c09a7b --- /dev/null +++ b/src/grossmeister/UCI.rs @@ -0,0 +1,71 @@ +use std::{io::stdin, thread::Builder}; + +use crate::{board::{Board, io::IO}, moves::Move, player::Player}; + +use super::Grossmeister; + +const NAME: &str = "Chessnost"; +const AUTHOR: &str = "Eugene Sokolov"; + +impl Grossmeister { + pub fn start(&mut self) { + let mut board = Board::new(); + let mut handle = None; + + loop { + let mut cmd = String::new(); + stdin().read_line(&mut cmd).unwrap(); + let tokens: Vec<&str> = cmd.trim().split(' ').collect(); + println!("Command: {:?}, tokens: {:?}", cmd, tokens); + + match tokens[0] { + "uci" => { + println!("id name {}", NAME); + println!("id author {}", AUTHOR); + println!("uciok"); + } + "isready" => { + println!("readyok"); + } + "position" => { + match tokens[1] { + "startpos" => { + board = Board::new(); + } + _ => { + todo!("Parse FEN") + } + } + assert!(tokens[2] == "moves"); + for move_token in tokens.iter().skip(3) { + let mov = Move::from_notation(move_token.chars()); + board.make_move(mov); + println!("{:?}", mov); + board.print(); + } + } + "go" => { + match tokens[1] { + "infinite" => { + let mut gm = self.clone(); + let builder = Builder::new(); + + handle = Some(builder.spawn(move || { + gm.analyze(board); + }).unwrap()); + }, + _ => todo!() + } + }, + "stop" => { + self.should_halt.store(true, std::sync::atomic::Ordering::Relaxed); + if let Some(hand) = handle.take() { + hand.join().unwrap(); + } + self.should_halt.store(false, std::sync::atomic::Ordering::Relaxed); + } + _ => {}, + } + } + } +} |