This commit is contained in:
dece 2020-06-28 19:53:38 +02:00
parent 94bd4ec01c
commit c5d07db007
3 changed files with 45 additions and 19 deletions

View file

@ -49,6 +49,20 @@ pub struct AnalysisParams {
pub black_time: i32, pub black_time: i32,
pub white_inc: i32, pub white_inc: i32,
pub black_inc: i32, pub black_inc: i32,
pub focus: Option<Move>,
}
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. /// Analysis info to report.
@ -105,6 +119,9 @@ impl Analyzer {
self.log(format!("Analyzing node:\n{}", &self.node)); self.log(format!("Analyzing node:\n{}", &self.node));
let moves = self.node.get_player_moves(); let moves = self.node.get_player_moves();
self.log(format!("Legal moves: {}", Move::list_to_uci_string(&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)); self.log(format!("Move time: {}", self.time_limit));
} }

View file

@ -64,6 +64,8 @@ pub enum Cmd {
WorkerBestMove(Option<Move>), WorkerBestMove(Option<Move>),
/// Log current node. /// Log current node.
LogNode, LogNode,
/// Log debug information about a move.
LogMove(Move),
// Commands that can be sent by the engine. // 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::WorkerInfo(infos) => self.reply(Cmd::Info(infos.to_vec())),
Cmd::WorkerBestMove(m) => self.reply(Cmd::BestMove(m.clone())), Cmd::WorkerBestMove(m) => self.reply(Cmd::BestMove(m.clone())),
// Other commands. // Other commands.
Cmd::LogNode => { Cmd::LogNode => self.log_node(),
let mut s = vec!(); Cmd::LogMove(m) => self.log_move(m),
self.node.board.draw_to(&mut s);
self.reply(Cmd::Log(format!(
"Current node:\n{}{}",
String::from_utf8_lossy(&s),
self.node.game_state
)));
}
_ => eprintln!("Not an engine input command: {:?}", cmd), _ => eprintln!("Not an engine input command: {:?}", cmd),
} }
} }
@ -208,10 +203,7 @@ impl Engine {
fn stop(&mut self) { fn stop(&mut self) {
self.working.store(false, atomic::Ordering::SeqCst); self.working.store(false, atomic::Ordering::SeqCst);
} }
}
/// UCI commands management.
impl Engine {
/// Setup engine for UCI communication. /// Setup engine for UCI communication.
pub fn setup_uci(&mut self, uci_s: mpsc::Sender<uci::Cmd>) { pub fn setup_uci(&mut self, uci_s: mpsc::Sender<uci::Cmd>) {
// Create a channel to receive commands from Uci. // Create a channel to receive commands from Uci.
@ -241,13 +233,7 @@ impl Engine {
/// Start working using parameters passed with a "go" command. /// Start working using parameters passed with a "go" command.
fn uci_go(&mut self, g_args: &Vec<uci::GoArgs>) { fn uci_go(&mut self, g_args: &Vec<uci::GoArgs>) {
let mut args = analysis::AnalysisParams { let mut args = analysis::AnalysisParams::new();
move_time: -1,
white_time: -1,
black_time: -1,
white_inc: -1,
black_inc: -1,
};
for arg in g_args { for arg in g_args {
match arg { match arg {
uci::GoArgs::MoveTime(ms) => args.move_time = *ms, uci::GoArgs::MoveTime(ms) => args.move_time = *ms,
@ -261,4 +247,22 @@ impl Engine {
} }
self.work(&args); 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);
}
} }

View file

@ -60,6 +60,7 @@ pub enum UciCmd {
// Unofficial commands mostly for debugging. // Unofficial commands mostly for debugging.
VatuNode, VatuNode,
VatuMove(String),
Unknown(String), Unknown(String),
} }
@ -205,6 +206,9 @@ impl Uci {
UciCmd::VatuNode => { UciCmd::VatuNode => {
self.send_engine_command(engine::Cmd::LogNode); 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)); } UciCmd::Unknown(c) => { self.log(format!("Unknown command: {}", c)); }
} }
true true
@ -316,6 +320,7 @@ fn parse_command(s: &str) -> UciCmd {
"go" => parse_go_command(&fields[1..]), "go" => parse_go_command(&fields[1..]),
"quit" => UciCmd::Quit, "quit" => UciCmd::Quit,
"vatunode" => UciCmd::VatuNode, "vatunode" => UciCmd::VatuNode,
"vatumove" => UciCmd::VatuMove(fields[1].to_string()),
c => UciCmd::Unknown(c.to_string()), c => UciCmd::Unknown(c.to_string()),
} }
} }