diff options
author | eug-vs <eugene@eug-vs.xyz> | 2023-02-26 21:08:37 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2023-02-26 21:08:37 +0300 |
commit | 6a92408ef0209e48c2a09ab3c7c33d0e5a8dddce (patch) | |
tree | 18f067486c30fe0251468b98f5f0d0b76c7206d8 | |
parent | fe952d63dc26c787350c9b3259d037344241665b (diff) | |
download | chessnost-6a92408ef0209e48c2a09ab3c7c33d0e5a8dddce.tar.gz |
feat: finish very basic UCI implementation
-rw-r--r-- | src/grossmeister/UCI.rs | 35 | ||||
-rw-r--r-- | src/grossmeister/mod.rs | 9 | ||||
-rw-r--r-- | src/grossmeister/search.rs | 9 | ||||
-rw-r--r-- | src/lib.rs | 1 | ||||
-rw-r--r-- | src/player.rs | 7 |
5 files changed, 38 insertions, 23 deletions
diff --git a/src/grossmeister/UCI.rs b/src/grossmeister/UCI.rs index 1e85b71..7c3cfb5 100644 --- a/src/grossmeister/UCI.rs +++ b/src/grossmeister/UCI.rs @@ -1,6 +1,6 @@ use std::{io::stdin, thread::Builder}; -use crate::{board::{Board, io::IO}, moves::Move, player::Player}; +use crate::{board::{Board, io::IO}, moves::Move}; use super::Grossmeister; @@ -41,7 +41,7 @@ impl Grossmeister { todo!() } "ucinewgame" => { - todo!("What should we even do here?") + // TODO: clear transposition table } "position" => { if let Some(token) = tokens.next() { @@ -78,6 +78,18 @@ impl Grossmeister { } } "go" => { + // Clone current self and move it + // into thread to analyze a position + let mut gm = self.clone(); + let builder = Builder::new(); + + search_handle = Some(builder.spawn(move || { + gm.iterative_deepening(6); + gm + }).unwrap()); + + continue; + if let Some(token) = tokens.next() { match token { "searchmoves" => todo!(), @@ -87,7 +99,22 @@ impl Grossmeister { "winc" => todo!(), "binc" => todo!(), "movestogo" => todo!(), - "depth" => todo!(), + "depth" => { + if let Some(depth) = tokens.next() { + let depth: u8 = depth.parse().unwrap(); + + // Clone current self and move it + // into thread to analyze a position + let mut gm = self.clone(); + let builder = Builder::new(); + + + search_handle = Some(builder.spawn(move || { + gm.iterative_deepening(depth); + gm + }).unwrap()); + } + }, "nodes" => todo!(), "mate" => todo!(), "movetime" => todo!(), @@ -98,7 +125,7 @@ impl Grossmeister { let builder = Builder::new(); search_handle = Some(builder.spawn(move || { - gm.analyze(gm.board); + gm.iterative_deepening(u8::MAX); gm }).unwrap()); }, diff --git a/src/grossmeister/mod.rs b/src/grossmeister/mod.rs index db9cb58..3473d1e 100644 --- a/src/grossmeister/mod.rs +++ b/src/grossmeister/mod.rs @@ -1,6 +1,6 @@ use std::sync::{atomic::AtomicBool, Arc}; -use crate::{board::Board, player::Player, moves::Move}; +use crate::{board::Board, moves::Move}; use self::ttable::{TranspositionTable, TTABLE_SIZE}; mod ttable; @@ -42,10 +42,3 @@ impl Grossmeister { } } } - -impl Player for Grossmeister { - fn analyze(&mut self, board: Board) -> (f32, Vec<Move>) { - self.board = board; // Copy the board into GM's head - self.iterative_deepening(8) - } -} diff --git a/src/grossmeister/search.rs b/src/grossmeister/search.rs index 2c2a296..def4305 100644 --- a/src/grossmeister/search.rs +++ b/src/grossmeister/search.rs @@ -199,8 +199,8 @@ impl Grossmeister { let mut gradual_widening_counter = 0; let mut root_killers: Vec<Move> = Vec::new(); - println!("info depth 1"); while depth <= max_depth { + println!("info depth {}", depth); if self.debug { println!("info string window {:?}", (alpha, beta)); } @@ -245,7 +245,6 @@ impl Grossmeister { print!("{} ", mov); } println!(); - println!("info depth {}", depth); } result = Some(search_result); @@ -254,8 +253,12 @@ impl Grossmeister { } } + match result { - Some(r) => r, + Some(r) => { + println!("bestmove {}", r.1[0]); + r + } None => panic!("Could not find a move in time"), } } @@ -3,5 +3,4 @@ pub mod bitboard; pub mod board; pub mod attacks; pub mod moves; -pub mod player; pub mod grossmeister; diff --git a/src/player.rs b/src/player.rs deleted file mode 100644 index 0257024..0000000 --- a/src/player.rs +++ /dev/null @@ -1,7 +0,0 @@ -use crate::{board::Board, moves::Move}; - -pub trait Player { - /// Analyze a position on a given board, giving - /// the score for the side to move and Principal Variation. - fn analyze(&mut self, board: Board) -> (f32, Vec<Move>); -} |