From 659094b2695f12215990f07a46f31f15638b97eb Mon Sep 17 00:00:00 2001 From: dece Date: Sat, 6 Jun 2020 00:58:11 +0200 Subject: [PATCH] engine: fix wrong best move selection --- src/engine.rs | 15 +++++++-------- src/uci.rs | 6 ++++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/engine.rs b/src/engine.rs index f427e68..46b0c8c 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -72,6 +72,7 @@ enum Mode { pub enum Cmd { // Commands that can be received by the engine. UciChannel(mpsc::Sender), // Provide a sender to UCI to start receiving commands. + UciDebug(bool), // UCI "debug" command. UciPosition(Vec), // UCI "position" command. UciGo(Vec), // UCI "go" command. Stop, // Stop working ASAP. @@ -110,7 +111,7 @@ pub enum Info { impl Engine { pub fn new() -> Engine { Engine { - debug: true, + debug: false, node: Node::new(), mode: Mode::No, listening: false, @@ -141,8 +142,9 @@ impl Engine { fn handle_command(&mut self, cmd: &Cmd) { match cmd { // UCI commands. - Cmd::UciPosition(args) => self.uci_position(&args), - Cmd::UciGo(args) => self.uci_go(&args), + Cmd::UciDebug(on) => self.debug = *on, + Cmd::UciPosition(args) => self.uci_position(args), + Cmd::UciGo(args) => self.uci_go(args), Cmd::Stop => self.stop(), // Workers commands. Cmd::Log(s) => self.reply(Cmd::Log(s.to_string())), @@ -199,7 +201,6 @@ impl Engine { } fn apply_move(&mut self, m: &rules::Move) { - eprintln!("Applying {}...", notation::move_to_string(m)); rules::apply_move_to(&mut self.node.board, &mut self.node.game_state, m); } @@ -314,11 +315,9 @@ fn analyze( rules::apply_move_to(&mut board, &mut game_state, &m); let stats = board::compute_stats(&board); let e = evaluate(&stats); - tx.send(Cmd::Log(format!("Move {} eval {}", notation::move_to_string(&m), e))).unwrap(); - if - (board::is_white(game_state.color) && e > best_e) || - (board::is_black(game_state.color) && e < best_e) + (board::is_white(node.game_state.color) && e > best_e) || + (board::is_black(node.game_state.color) && e < best_e) { best_e = e; best_move = Some(m.clone()); diff --git a/src/uci.rs b/src/uci.rs index 91670c1..fb51ea1 100644 --- a/src/uci.rs +++ b/src/uci.rs @@ -43,6 +43,7 @@ pub enum Cmd { #[derive(Debug)] pub enum UciCmd { Uci, + Debug(bool), IsReady, UciNewGame, Stop, @@ -173,6 +174,10 @@ impl Uci { self.send_identities(); self.setup_engine(); }, + UciCmd::Debug(on) => { + let args = engine::Cmd::UciDebug(*on); + self.engine_in.as_ref().unwrap().send(args).unwrap(); + } UciCmd::IsReady => if self.state == State::Ready { self.send_ready() }, UciCmd::UciNewGame => if self.state == State::Ready { /* Nothing to do. */ }, UciCmd::Position(args) => if self.state == State::Ready { @@ -269,6 +274,7 @@ fn parse_command(s: &str) -> UciCmd { let fields: Vec<&str> = s.split_whitespace().collect(); match fields[0] { "uci" => UciCmd::Uci, + "debug" => UciCmd::Debug(fields[1] == "on"), "isready" => UciCmd::IsReady, "ucinewgame" => UciCmd::UciNewGame, "stop" => UciCmd::Stop,