Add log product formula for LMR

This commit is contained in:
stefiosif
2025-03-28 23:32:44 +02:00
parent 0c953c4ac1
commit 2d04a07b2a
2 changed files with 13 additions and 5 deletions

View File

@@ -18,7 +18,8 @@ pub const ASPIRATION_WINDOW_DEPTH_THRESHOLD: u8 = 4;
pub const ASPIRATION_WINDOW_EXPANSION: i16 = 2; pub const ASPIRATION_WINDOW_EXPANSION: i16 = 2;
pub const LMR_DEPTH_THRESHOLD: u8 = 2; pub const LMR_DEPTH_THRESHOLD: u8 = 2;
pub const LMR_MOVE_COUNT_THRESHOLD: u8 = 3; pub const LMR_MOVE_COUNT_THRESHOLD: u8 = 3;
pub const LMR_REDUCTION: u8 = 2; pub const LMR_BASE: f32 = 1.0;
pub const LMR_DIVISION: f32 = 2.0;
pub const NMP_REDUCTION: u8 = 2; pub const NMP_REDUCTION: u8 = 2;
pub const NMP_DEPTH_THRESHOLD: u8 = 2; pub const NMP_DEPTH_THRESHOLD: u8 = 2;
pub const RFP_DEPTH_LIMIT: u8 = 6; pub const RFP_DEPTH_LIMIT: u8 = 6;

View File

@@ -10,7 +10,7 @@ use super::{
quiescence::quiescence, quiescence::quiescence,
time::TimeInfo, time::TimeInfo,
transposition_table::{NodeType, TTEntry}, transposition_table::{NodeType, TTEntry},
CHECK_EXTENSION, LMR_DEPTH_THRESHOLD, LMR_MOVE_COUNT_THRESHOLD, LMR_REDUCTION, MAX_HISTORY, CHECK_EXTENSION, LMR_BASE, LMR_DEPTH_THRESHOLD, LMR_DIVISION, LMR_MOVE_COUNT_THRESHOLD,
NMP_DEPTH_THRESHOLD, NMP_REDUCTION, RFP_DEPTH_LIMIT, RFP_MARGIN, NMP_DEPTH_THRESHOLD, NMP_REDUCTION, RFP_DEPTH_LIMIT, RFP_MARGIN,
}; };
@@ -123,22 +123,29 @@ pub fn negamax(
let score = if legal_moves == 1 { let score = if legal_moves == 1 {
-negamax(game, -beta, -alpha, depth - 1, plies + 1, time, nodes, true)? -negamax(game, -beta, -alpha, depth - 1, plies + 1, time, nodes, true)?
} else { } else {
#[rustfmt::skip]
let lmr_reduction = if !in_check let lmr_reduction = if !in_check
&& !mv.is_capture() && !mv.is_capture()
&& depth > LMR_DEPTH_THRESHOLD && depth > LMR_DEPTH_THRESHOLD
&& legal_moves > LMR_MOVE_COUNT_THRESHOLD { LMR_REDUCTION } else { 0 }; && legal_moves > LMR_MOVE_COUNT_THRESHOLD
{
let log_product = (depth as f32).ln() * (legal_moves as f32).ln();
let reduction = LMR_BASE + (log_product / LMR_DIVISION);
reduction.clamp(1.0, (depth - 1) as f32).floor() as u8
} else {
1
};
let mut score = -negamax( let mut score = -negamax(
game, game,
-alpha - 1, -alpha - 1,
-alpha, -alpha,
depth - 1 - lmr_reduction, depth - lmr_reduction,
plies + 1, plies + 1,
time, time,
nodes, nodes,
true, true,
)?; )?;
if score > alpha && score < beta { if score > alpha && score < beta {
score = -negamax(game, -beta, -alpha, depth - 1, plies + 1, time, nodes, true)?; score = -negamax(game, -beta, -alpha, depth - 1, plies + 1, time, nodes, true)?;
} }