Add history maluses

This commit is contained in:
stefiosif
2025-03-28 23:35:02 +02:00
parent 2d04a07b2a
commit 6211e5be89
4 changed files with 23 additions and 10 deletions

View File

@@ -320,6 +320,20 @@ impl Game {
.step_by(2)
.any(|mp| mp.zobrist_hash.expect("State without hash.") == self.hash)
}
pub fn update_history(&mut self, color: Color, mv: Move, depth: u8, punish: bool) {
const MAX_HISTORY: i32 = 8192;
let bonus = if punish {
-(depth as i32 * depth as i32)
} else {
depth as i32 * depth as i32
};
let clamped_bonus = bonus.clamp(-MAX_HISTORY, MAX_HISTORY);
let history_value = self.history_heuristic[color][mv.src()][mv.dst()];
self.history_heuristic[color][mv.src()][mv.dst()] +=
clamped_bonus - history_value * clamped_bonus.abs() / MAX_HISTORY;
}
}
#[derive(Default, Debug, Clone, PartialEq, Eq)]

View File

@@ -12,7 +12,7 @@ pub const INC: u128 = 80;
pub const HARD_LIMIT_DIVISION: u128 = 3;
pub const SOFT_LIMIT_DIVISION: u128 = 20;
pub const TT_SIZE_IN_MB: usize = 64;
pub const MAX_HISTORY: i16 = 8192;
pub const MAX_HISTORY: i32 = 8192;
pub const ASPIRATION_WINDOW_INITIAL: i16 = 20;
pub const ASPIRATION_WINDOW_DEPTH_THRESHOLD: u8 = 4;
pub const ASPIRATION_WINDOW_EXPANSION: i16 = 2;

View File

@@ -11,9 +11,9 @@ pub fn score_move(
mv: Move,
killer_move: Option<Move>,
color: Color,
history_heuristic: &[[[i16; 64]; 64]; 2],
history_heuristic: &[[[i32; 64]; 64]; 2],
tt_move: Option<Move>,
) -> i16 {
) -> i32 {
if Some(mv) == tt_move {
return -100;
}

View File

@@ -109,6 +109,7 @@ pub fn negamax(
let mut legal_moves = 0;
let mut best_move = entry.and_then(|entry| entry.mv);
let mut best_score = MIN_SCORE;
let mut quiets_tried: Vec<Move> = Vec::new();
for mv in moves {
game.make_move(&mv);
@@ -166,16 +167,14 @@ pub fn negamax(
if score >= beta {
if !mv.is_capture() {
game.killer[plies as usize] = Some(mv);
let current_score = game.history_heuristic[color][mv.src()][mv.dst()];
let bonus = (depth * depth) as i16;
let clamped_bonus = bonus.clamp(-MAX_HISTORY, MAX_HISTORY);
game.history_heuristic[color][mv.src()][mv.dst()] +=
clamped_bonus - current_score * clamped_bonus.abs() / MAX_HISTORY;
game.update_history(color, mv, depth, false);
for q in quiets_tried {
game.update_history(color, q, depth, true);
}
}
break;
} else if !mv.is_capture() {
game.history_heuristic[color][mv.src()][mv.dst()] -= 1;
quiets_tried.push(mv);
}
}