From c5d07db00711bc9e62ff020c4036946d35f5b922 Mon Sep 17 00:00:00 2001 From: dece Date: Sun, 28 Jun 2020 19:53:38 +0200 Subject: [PATCH] WIP --- src/analysis.rs | 17 +++++++++++++++++ src/engine.rs | 42 +++++++++++++++++++++++------------------- src/uci.rs | 5 +++++ 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/src/analysis.rs b/src/analysis.rs index b80b99f..3ce647a 100644 --- a/src/analysis.rs +++ b/src/analysis.rs @@ -49,6 +49,20 @@ pub struct AnalysisParams { pub black_time: i32, pub white_inc: i32, pub black_inc: i32, + pub focus: Option, +} + +impl AnalysisParams { + pub fn new() -> AnalysisParams { + AnalysisParams { + move_time: -1, + white_time: -1, + black_time: -1, + white_inc: -1, + black_inc: -1, + focus: None, + } + } } /// Analysis info to report. @@ -105,6 +119,9 @@ impl Analyzer { self.log(format!("Analyzing node:\n{}", &self.node)); let moves = self.node.get_player_moves(); self.log(format!("Legal moves: {}", Move::list_to_uci_string(&moves))); + if let Some(focus) = &args.focus { + self.log(format!("Focus on: {}", focus.to_uci_string())); + } self.log(format!("Move time: {}", self.time_limit)); } diff --git a/src/engine.rs b/src/engine.rs index 79822e3..68cf1ed 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -64,6 +64,8 @@ pub enum Cmd { WorkerBestMove(Option), /// Log current node. LogNode, + /// Log debug information about a move. + LogMove(Move), // Commands that can be sent by the engine. @@ -127,15 +129,8 @@ impl Engine { Cmd::WorkerInfo(infos) => self.reply(Cmd::Info(infos.to_vec())), Cmd::WorkerBestMove(m) => self.reply(Cmd::BestMove(m.clone())), // Other commands. - Cmd::LogNode => { - let mut s = vec!(); - self.node.board.draw_to(&mut s); - self.reply(Cmd::Log(format!( - "Current node:\n{}{}", - String::from_utf8_lossy(&s), - self.node.game_state - ))); - } + Cmd::LogNode => self.log_node(), + Cmd::LogMove(m) => self.log_move(m), _ => eprintln!("Not an engine input command: {:?}", cmd), } } @@ -208,10 +203,7 @@ impl Engine { fn stop(&mut self) { self.working.store(false, atomic::Ordering::SeqCst); } -} -/// UCI commands management. -impl Engine { /// Setup engine for UCI communication. pub fn setup_uci(&mut self, uci_s: mpsc::Sender) { // Create a channel to receive commands from Uci. @@ -241,13 +233,7 @@ impl Engine { /// Start working using parameters passed with a "go" command. fn uci_go(&mut self, g_args: &Vec) { - let mut args = analysis::AnalysisParams { - move_time: -1, - white_time: -1, - black_time: -1, - white_inc: -1, - black_inc: -1, - }; + let mut args = analysis::AnalysisParams::new(); for arg in g_args { match arg { uci::GoArgs::MoveTime(ms) => args.move_time = *ms, @@ -261,4 +247,22 @@ impl Engine { } self.work(&args); } + + /// Log current node information. + fn log_node(&mut self) { + let mut s = vec!(); + self.node.board.draw_to(&mut s); + self.reply(Cmd::Log(format!( + "Current node:\n{}{}", + String::from_utf8_lossy(&s), + self.node.game_state + ))); + } + + /// Log a move information. + fn log_move(&mut self, m: &Move) { + let mut args = analysis::AnalysisParams::new(); + args.focus = Some(m.clone()); + self.work(&args); + } } diff --git a/src/uci.rs b/src/uci.rs index 0dee8a8..29a580d 100644 --- a/src/uci.rs +++ b/src/uci.rs @@ -60,6 +60,7 @@ pub enum UciCmd { // Unofficial commands mostly for debugging. VatuNode, + VatuMove(String), Unknown(String), } @@ -205,6 +206,9 @@ impl Uci { UciCmd::VatuNode => { self.send_engine_command(engine::Cmd::LogNode); } + UciCmd::VatuMove(m) => { + self.send_engine_command(engine::Cmd::LogMove(Move::from_uci_string(m))); + } UciCmd::Unknown(c) => { self.log(format!("Unknown command: {}", c)); } } true @@ -316,6 +320,7 @@ fn parse_command(s: &str) -> UciCmd { "go" => parse_go_command(&fields[1..]), "quit" => UciCmd::Quit, "vatunode" => UciCmd::VatuNode, + "vatumove" => UciCmd::VatuMove(fields[1].to_string()), c => UciCmd::Unknown(c.to_string()), } }