Skip to content

Commit

Permalink
Add search noise as UCI option
Browse files Browse the repository at this point in the history
  • Loading branch information
Tearth committed Nov 23, 2024
1 parent 8187cd9 commit 072c98a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/engine/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct SearchContext {
pub uci_debug: bool,
pub ponder_mode: bool,
pub soft_nodes: bool,
pub search_noise: bool,
pub syzygy_enabled: bool,
pub syzygy_probe_limit: u32,
pub syzygy_probe_depth: i8,
Expand Down Expand Up @@ -91,6 +92,7 @@ impl SearchContext {
uci_debug: false,
ponder_mode: false,
soft_nodes: false,
search_noise: false,
syzygy_enabled: false,
syzygy_probe_limit: 0,
syzygy_probe_depth: 0,
Expand Down
7 changes: 6 additions & 1 deletion src/engine/search/movepick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::utils::assert_fast;
use crate::utils::bithelpers::BitHelpers;
use crate::utils::dev;
use crate::utils::panic_fast;
use crate::utils::rand;
use crate::MoveScores;
use crate::Moves;
use std::mem::MaybeUninit;
Expand Down Expand Up @@ -332,7 +333,11 @@ fn assign_quiet_scores(context: &SearchContext, state: &mut MoveGenState, start_
continue;
}

let value = context.htable.get(r#move.get_from(), r#move.get_to(), MOVEORD_HISTORY_MOVE) as i16;
let mut value = context.htable.get(r#move.get_from(), r#move.get_to(), MOVEORD_HISTORY_MOVE) as i16;
if context.search_noise {
value = i16::clamp(value + rand::i16(-5..5), 0, MOVEORD_HISTORY_MOVE as i16);
}

state.move_scores[move_index].write(value + MOVEORD_HISTORY_MOVE_OFFSET);
} else if r#move.is_promotion() {
state.move_scores[move_index].write(match r#move.get_promotion_piece() {
Expand Down
3 changes: 3 additions & 0 deletions src/interface/uci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ pub fn run() {
#[cfg(feature = "dev")]
{
options_lock.insert("Soft Nodes".to_string(), UciOption::new(50, "check", false, false, false));
options_lock.insert("Search Noise".to_string(), UciOption::new(50, "check", false, false, false));
options_lock.insert("Crash Files".to_string(), UciOption::new(50, "check", false, false, false));
}

Expand Down Expand Up @@ -388,6 +389,7 @@ fn handle_go(params: &[String], state: &UciState) {
let syzygy_probe_limit = options_lock["SyzygyProbeLimit"].value.parse::<u32>().unwrap();
let syzygy_probe_depth = options_lock["SyzygyProbeDepth"].value.parse::<i8>().unwrap();
let soft_nodes = options_lock["Soft Nodes"].value.parse::<bool>().unwrap();
let search_noise = options_lock["Search Noise"].value.parse::<bool>().unwrap();

#[cfg(not(feature = "dev"))]
let search_params = SearchParams::default();
Expand Down Expand Up @@ -456,6 +458,7 @@ fn handle_go(params: &[String], state: &UciState) {
context_lock.uci_debug = debug_mode;
context_lock.ponder_mode = ponder_mode;
context_lock.soft_nodes = soft_nodes;
context_lock.search_noise = search_noise;
context_lock.syzygy_enabled = syzygy_enabled;
context_lock.syzygy_probe_limit = syzygy_probe_limit;
context_lock.syzygy_probe_depth = syzygy_probe_depth;
Expand Down

0 comments on commit 072c98a

Please sign in to comment.