aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-02-26 21:26:09 +0300
committereug-vs <eugene@eug-vs.xyz>2023-02-26 21:26:09 +0300
commitef9156656c752c6e1bd52f8b0c77bd101e464f7b (patch)
tree6aa0964f665bf3177a45437a39015b07105342fd
parent6a92408ef0209e48c2a09ab3c7c33d0e5a8dddce (diff)
downloadchessnost-ef9156656c752c6e1bd52f8b0c77bd101e464f7b.tar.gz
feat: provide sane default behavior to GO command
-rw-r--r--src/grossmeister/UCI.rs101
1 files changed, 45 insertions, 56 deletions
diff --git a/src/grossmeister/UCI.rs b/src/grossmeister/UCI.rs
index 7c3cfb5..cd00ad7 100644
--- a/src/grossmeister/UCI.rs
+++ b/src/grossmeister/UCI.rs
@@ -1,4 +1,4 @@
-use std::{io::stdin, thread::Builder};
+use std::{io::stdin, thread::{Builder, JoinHandle}, str::Split};
use crate::{board::{Board, io::IO}, moves::Move};
@@ -78,61 +78,8 @@ 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!(),
- "ponder" => todo!(),
- "wtime" => todo!(),
- "btime" => todo!(),
- "winc" => todo!(),
- "binc" => todo!(),
- "movestogo" => 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!(),
- "infinite" => {
- // 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(u8::MAX);
- gm
- }).unwrap());
- },
- _ => todo!()
- }
- }
- },
+ search_handle = Some(self.parse_go(tokens));
+ }
"stop" => {
self.should_halt.store(true, std::sync::atomic::Ordering::Relaxed);
if let Some(hand) = search_handle.take() {
@@ -150,4 +97,46 @@ impl Grossmeister {
}
}
}
+
+ fn parse_go(&mut self, mut tokens: Split<char>) -> JoinHandle<Self> {
+ if let Some(token) = tokens.next() {
+ match token {
+ "searchmoves" => todo!(),
+ "ponder" => todo!(),
+ "wtime" => {}
+ "btime" => {}
+ "winc" => {}
+ "binc" => {}
+ "movestogo" => {}
+ "depth" => {
+ if let Some(depth) = tokens.next() {
+ let depth: u8 = depth.parse().unwrap();
+ return self.create_search_thread(depth);
+ }
+ },
+ "nodes" => todo!(),
+ "mate" => todo!(),
+ "movetime" => todo!(),
+ "infinite" => {
+ return self.create_search_thread(u8::MAX);
+ },
+ _ => {}
+ }
+ return self.parse_go(tokens)
+ }
+ self.create_search_thread(6)
+ }
+
+ fn create_search_thread(&self, depth: u8) -> JoinHandle<Self> {
+ // Clone current self and move it
+ // into thread to analyze a position
+ let mut gm = self.clone();
+ let builder = Builder::new();
+
+
+ builder.spawn(move || {
+ gm.iterative_deepening(depth);
+ gm
+ }).unwrap()
+ }
}