Przeglądaj źródła

some cleanig up

Nicolas Winkler 2 lat temu
rodzic
commit
19047b2fa8
4 zmienionych plików z 7 dodań i 105 usunięć
  1. 0 28
      src/engine.rs
  2. 4 8
      src/search.rs
  3. 1 1
      src/ttable.rs
  4. 2 68
      src/uci.rs

+ 0 - 28
src/engine.rs

@@ -202,32 +202,4 @@ impl Engine {
             let _res = st.join_handle.join().unwrap();
         }
     }
-
-    fn reconstruct_pv(game: &Board, hash: &Cache) -> Vec<Move> {
-        let mut pv: Vec<Move> = Vec::new();
-        let mut g = game.clone();
-
-        // max 100 to avoid infinite loops
-        for _ in 0..100 {
-            let mce = hash.lookup(&g);
-            if let Some(ce) = mce {
-                if ce.mov == (SimpleMove{ from: 0, to: 0 }) {
-                    break;
-                }
-                let movs = generate_moves(&g, g.turn);
-                let bm = movs.iter().find(|m| (**m).to_simple() == ce.mov);
-                if let Some(found) = bm {
-                    g.apply(*found);
-                    pv.push(*found);
-                }
-                else {
-                    break;
-                }
-            }
-            else {
-                break;
-            }
-        }
-        return pv;
-    }
 }

+ 4 - 8
src/search.rs

@@ -1,4 +1,5 @@
-use std::{clone, sync::{Arc, RwLock, mpsc, Mutex}, cell::{RefCell, UnsafeCell}, time::{Instant, Duration}, ops::Add, borrow::BorrowMut};
+use std::sync::{RwLock, Arc, Mutex, mpsc};
+use std::time::{Instant, Duration};
 
 use movegen::*;
 use board::Board;
@@ -262,7 +263,7 @@ impl SearchControl {
             }
         }
 
-        if let (Some(bm), Some(bv)) = (best_move, best_val) {
+        if let (Some(bm), Some(_bv)) = (best_move, best_val) {
             info!("bestmove {}", bm.to_string());
             println!("bestmove {}", bm.to_string());
         }
@@ -513,7 +514,7 @@ pub fn negamax(game: &mut Board, sc: &mut SearchControl, hash: &mut Cache, mut a
             alpha = val;
             best_move = Some(mov);
             if depth >= 2 {
-                if let Some(lm) = last_move {
+                if let Some(_lm) = last_move {
                     //sc.countermoves.as_ref().lock().unwrap().update_score(lm, mov, (depth * depth) as i16);
                 }
             }
@@ -521,17 +522,12 @@ pub fn negamax(game: &mut Board, sc: &mut SearchControl, hash: &mut Cache, mut a
                 break;
             }
         }
-
-        if let Some(lm) = last_move {
-            //moves.update_counter(sc.countermove_to(lm));
-        }
     }
 
 
     if let Some(mov) = best_move {
         // alpha is exact
         hash.cache(game, CacheEntry::new_value(depth as _, sc.halfmove_age as _, mov.to_simple(), alpha));
-        let cur_depth = (sc.initial_depth - depth) as usize;
     }
     else {
         hash.cache(game, CacheEntry::new_upper(depth as _, sc.halfmove_age as _, SimpleMove { from: 0, to: 0 }, alpha));

+ 1 - 1
src/ttable.rs

@@ -5,7 +5,7 @@ use std::collections::{HashMap};
 use log::info;
 use zobrist;
 
-use crate::movegen::{Move, SimpleMove};
+use crate::movegen::{SimpleMove};
 use crate::zobrist::Hash;
 
 #[derive(Clone, PartialEq)]

+ 2 - 68
src/uci.rs

@@ -1,16 +1,8 @@
-use std::io::{self, BufRead};
 use std::collections::BTreeMap;
-use std::sync::mpsc::{Receiver, Sender};
-
-use std::process::exit;
 
 use engine::{Command, SearchInfo};
 use board::Board;
 
-use log::info;
-
-use crate::evaluate::PosValue;
-
 
 pub fn parse_command(command: &str) -> Result<Command, String> {
     let parts = command.split_whitespace().collect::<Vec<&str>>();
@@ -32,7 +24,8 @@ pub fn parse_command(command: &str) -> Result<Command, String> {
             "ucinewgame" => cmd_newgame(cmd, r, s),
             //"setoption" => cmd_setoption(cmd, r, s),
             "quit" | "exit" => cmd_quit(cmd, r, s),*/
-            cmd => { Err("unknown command".to_owned()) }
+            "" =>  Ok(Command::Ping),
+            _cmd => { Err("unknown command".to_owned()) }
         }
     }
     else {
@@ -81,65 +74,6 @@ fn parse_position(args: &Vec<&str>) -> Result<Command, String> {
 }
 
 
-/*fn run_command(mut cmd: Vec<&str>, r: &Receiver<InterfaceMsg>, s: &Sender<Command>) {
-    if cmd.len() > 0 {
-        let command = cmd[0];
-        cmd.drain(0..1);
-        match command {
-            "uci" => cmd_uci(cmd),
-            "isready" => cmd_isready(cmd, r, s),
-            "position" => cmd_position(cmd, r, s),
-            "print" => cmd_print(cmd, r, s),
-            "go" => cmd_go(cmd, r, s),
-            "stop" => cmd_stop(cmd, r, s),
-            "ucinewgame" => cmd_newgame(cmd, r, s),
-            //"setoption" => cmd_setoption(cmd, r, s),
-            "quit" | "exit" => cmd_quit(cmd, r, s),
-            cmd => { println!("unknown command: {}", cmd); }
-        }
-    }
-}*/
-
-/*fn cmd_isready(_args: Vec<&str>, _r: &Receiver<InterfaceMsg>, s: &Sender<Command>) {
-    s.send(Command::IsReady).unwrap();
-}
-
-fn cmd_position(mut args: Vec<&str>, _r: &Receiver<InterfaceMsg>, s: &Sender<Command>) {
-    let position = args[0];
-    args.drain(0..1);
-
-    let mut game = Board::default();
-
-    if position == "startpos" {
-    }
-    else if position == "fen" {
-        let fen_parts: Vec<&str> = Vec::from(&args[0..6]).into_iter().collect::<Vec<&str>>();
-        game = Board::from_fen(fen_parts.as_slice()).unwrap_or_else(|| {
-            info!("invalid fen");
-            println!("invalid fen");
-            Board::default()
-        });
-        args.drain(0..6);
-    }
-    let moves = 
-        if args.len() > 0 {
-            if args[0] != "moves" {
-                info!("unexpected {}", args[6]);
-                println!("unexpected {}", args[6]);
-            }
-            args.drain(0..1);
-
-
-            args.into_iter().map(|m| String::from(m)).collect::<Vec<String>>()
-        }
-        else {
-            Vec::new()
-        };
-
-    s.send(Command::Position{ pos: game, moves }).unwrap();
-}*/
-
-
 pub fn parse_go(args: &Vec<&str>) -> Result<Command, String> {
     let mut options: BTreeMap<String, String> = BTreeMap::new();
     let mut opt_name: Option<&str> = None;