diff --git a/README.md b/README.md index ae3477b..c4f4bd8 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ - opening_book=\: Toggle opening book (default=true) - time_management=\: Toggle time management, if false the bot will use all the remaining time (default=true) #### UCI Interface - - Only supports games from startpos - uci, isready, ucinewgame, position, go, stop, and quit commands + - "position" is only implemented for "position startpos", "position fen" is not yet implemented #### Board Representation - Purely bitboards - Supports loading from FEN strings @@ -60,4 +60,4 @@ - [The Chess Programming Wiki](https://www.chessprogramming.org/Main_Page) - [BBC Engine Development](https://www.youtube.com/playlist?list=PLmN0neTso3Jxh8ZIylk74JpwfiWNI76Cs) - [Lynx](https://github.com/lynx-chess/Lynx/) - - [Weiawaga](https://github.com/Heiaha/Weiawaga/) + - [Weiawaga](https://github.com/Heiaha/Weiawaga/) \ No newline at end of file diff --git a/icon/Maxwell_100x100.png b/icon/Maxwell_100x100.png new file mode 100644 index 0000000..a5966d4 Binary files /dev/null and b/icon/Maxwell_100x100.png differ diff --git a/src/bot.rs b/src/bot.rs index 0058451..ba51174 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -112,7 +112,7 @@ impl Bot { } } - pub fn start(&mut self, board: &mut Board, moves: String, my_time: f32) { + pub fn start(&mut self, board: &mut Board, moves: String, my_time: f32, depth_to_search: u8) { if self.in_opening_book { let opening_move = self.opening_book.get_opening_move(moves); if opening_move == NULL_MOVE { @@ -123,18 +123,21 @@ impl Bot { } } - self.time_to_think = if self.config.time_management { - let time_percentage = if board.moves.len() / 2 <= 6 { - PERCENT_OF_TIME_TO_USE_BEFORE_6_FULL_MOVES + self.time_to_think = + if my_time == 0.0 { // This means we're in a "go depth X" command + 0.0 + } else if self.config.time_management { + let time_percentage = if board.moves.len() / 2 <= 6 { + PERCENT_OF_TIME_TO_USE_BEFORE_6_FULL_MOVES + } else { + PERCENT_OF_TIME_TO_USE_AFTER_6_FULL_MOVES + }; + + (my_time * time_percentage).clamp(MIN_TIME_PER_MOVE, MAX_TIME_PER_MOVE) } else { - PERCENT_OF_TIME_TO_USE_AFTER_6_FULL_MOVES + my_time }; - (my_time * time_percentage).clamp(MIN_TIME_PER_MOVE, MAX_TIME_PER_MOVE) - } else { - my_time - }; - self.search_cancelled = false; let last_evaluation = self.evaluation; @@ -151,7 +154,7 @@ impl Bot { let mut window = 40; self.think_timer = Instant::now(); - for depth in 1..=(255 - MAX_SEARCH_EXTENSIONS) { + for depth in 1..=depth_to_search { self.searched_one_move = false; self.best_move_this_iteration = NULL_MOVE; self.evaluation_this_iteration = 0; @@ -201,6 +204,8 @@ impl Bot { } } + self.println(format!("{} seconds", self.think_timer.elapsed().as_secs_f32())); + self.transposition_table.update(); if self.config.debug_output { self.transposition_table.print_size(); @@ -208,7 +213,7 @@ impl Bot { } fn should_cancel_search(&mut self) -> bool { - self.search_cancelled = self.search_cancelled || self.think_timer.elapsed().as_secs_f32() >= self.time_to_think; + self.search_cancelled = (self.search_cancelled || self.think_timer.elapsed().as_secs_f32() >= self.time_to_think) && self.time_to_think > 0.0; self.search_cancelled } diff --git a/src/main.rs b/src/main.rs index 66ff87e..b54a4b3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,11 +16,9 @@ https://www.chessprogramming.org/Futility_Pruning#MoveCountBasedPruning https://www.chessprogramming.org/Triangular_PV-Table https://www.chessprogramming.org/Static_Exchange_Evaluation -Some random resources I found: -https://analog-hors.github.io/site/magic-bitboards/ (didn't use this for my initial implementation, but that might change ;)) +Some random resources I found: (Not using them right now but they could be useful) +https://analog-hors.github.io/site/magic-bitboards/ https://web.archive.org/web/20071030220825/http://www.brucemo.com/compchess/programming/pvs.htm -https://github.com/lynx-chess/Lynx/ -https://github.com/Heiaha/Weiawaga/ */ #![allow(dead_code)] @@ -47,7 +45,7 @@ mod bot; mod move_sorter; use crate::castling_rights::print_castling_rights; -use crate::bot::{Bot, BotConfig}; +use crate::bot::{Bot, BotConfig, MAX_SEARCH_EXTENSIONS}; use crate::perft::*; use crate::move_data::MoveData; use crate::pieces::*; @@ -93,7 +91,13 @@ fn main() { match command_split[0] { // UCI protocol - "uci" => println!("uciok"), + "uci" => { + println!("id name Maxwell v3.0.8-1"); + println!("id author eboatwright"); + + println!("uciok"); + } + "isready" => println!("readyok"), "ucinewgame" => { @@ -121,10 +125,13 @@ fn main() { moves.pop(); } - // Format: go (movetime, wtime) X (btime Y) + // Format: + // go (movetime, wtime) X (btime Y) + // go depth X "go" => { let my_time_label = if board.white_to_move { "wtime" } else { "btime" }; let mut my_time = 0.0; + let mut depth_to_search = 255 - MAX_SEARCH_EXTENSIONS; for i in [1, 3] { if command_split[i] == my_time_label @@ -133,10 +140,15 @@ fn main() { my_time = time_in_millis as f32 / 1000.0; break; } + } else if command_split[i] == "depth" { + if let Ok(_depth_to_search) = command_split[i + 1].parse::() { + depth_to_search = _depth_to_search; + break; + } } } - bot.start(&mut board, moves.clone(), my_time); + bot.start(&mut board, moves.clone(), my_time, depth_to_search); println!("bestmove {}", bot.best_move.to_coordinates()); // log.write(format!("bestmove {}", bot.best_move.to_coordinates())); @@ -145,7 +157,7 @@ fn main() { "stop" => bot.search_cancelled = true, "quit" => break, - // My debug tools :] + // My debug tools // "play" => play(command_split[1] == "white"), @@ -162,15 +174,15 @@ fn main() { } } - "clearlogs" => { - if let Ok(logs_folder) = std::fs::read_dir("./logs/") { - for log_file in logs_folder { - std::fs::remove_file(log_file.unwrap().path()).expect("Failed to clear logs"); - } - } else { - println!("No logs folder"); - } - } + // "clearlogs" => { + // if let Ok(logs_folder) = std::fs::read_dir("./logs/") { + // for log_file in logs_folder { + // std::fs::remove_file(log_file.unwrap().path()).expect("Failed to clear logs"); + // } + // } else { + // println!("No logs folder"); + // } + // } "print" => board.print(), "bitboards" => board.print_bitboards(),