Skip to content

Commit

Permalink
Merge pull request #16 from eboatwright/dev
Browse files Browse the repository at this point in the history
v3.0.8-1
  • Loading branch information
eboatwright authored Jan 6, 2024
2 parents d02dbb1 + 065959d commit 7956081
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 32 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
- opening_book=\<BOOLEAN>: Toggle opening book (default=true)
- time_management=\<BOOLEAN>: 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
Expand Down Expand Up @@ -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/)
Binary file added icon/Maxwell_100x100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 17 additions & 12 deletions src/bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -201,14 +204,16 @@ 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();
}
}

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
}

Expand Down
48 changes: 30 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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::*;
Expand Down Expand Up @@ -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" => {
Expand Down Expand Up @@ -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
Expand All @@ -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::<u8>() {
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()));
Expand All @@ -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"),

Expand All @@ -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(),
Expand Down

0 comments on commit 7956081

Please sign in to comment.