Reduce size of eval to i16

This commit is contained in:
stefiosif
2025-02-04 20:02:29 +02:00
parent 55056537f3
commit 908a87bd26
7 changed files with 21 additions and 19 deletions

View File

@@ -1,5 +1,5 @@
pub mod pesto;
pub const MAX_SCORE: i32 = 100000;
pub const MIN_SCORE: i32 = -100000;
pub const MATE_SCORE: i32 = 50000;
pub const MAX_SCORE: i16 = 10000;
pub const MIN_SCORE: i16 = -10000;
pub const MATE_SCORE: i16 = 5000;

View File

@@ -224,7 +224,7 @@ impl Pesto {
Self { mg_table, eg_table }
}
pub fn eval(&self, game: &Game) -> i32 {
pub fn eval(&self, game: &Game) -> i16 {
let mut mg = [0, 0];
let mut eg = [0, 0];
let mut phase = 0;
@@ -243,7 +243,7 @@ impl Pesto {
let mg_phase = std::cmp::min(phase, 24);
let eg_phase = 24 - mg_phase;
(mg_score * mg_phase + eg_score * eg_phase) / 24
((mg_score * mg_phase + eg_score * eg_phase) / 24) as i16
}
}

View File

@@ -55,7 +55,7 @@ fn log_depth_results(
seconds: u64,
nodes: u64,
nps: u64,
best_score: i32,
best_score: i16,
best_move: Option<Move>,
) -> Response {
Response::Info(format!(

View File

@@ -5,7 +5,7 @@ pub fn score_move(
mv: Move,
killer_move: Option<Move>,
tt_move: Option<Move>,
) -> i32 {
) -> i16 {
if Some(mv) == tt_move {
return -100;
}
@@ -15,9 +15,11 @@ pub fn score_move(
}
let aggressor = mailbox.piece_at(mv.src()).expect("No aggressor found.");
mailbox.piece_at(mv.dst()).map_or(100, |victim| {
aggressor.0.idx() as i32 - (victim.0.idx() * 8) as i32
})
if let Some(victim) = mailbox.piece_at(mv.dst()) {
return (aggressor.0.idx() - 8 * victim.0.idx()) as i16;
}
100
}
#[cfg(test)]

View File

@@ -14,14 +14,14 @@ use super::{
pub fn negamax(
game: &mut Game,
mut alpha: i32,
beta: i32,
mut alpha: i16,
beta: i16,
mut depth: u8,
plies: u8,
time: &TimeInfo,
nodes: &mut u64,
do_nmp: bool,
) -> Result<i32> {
) -> Result<i16> {
if time.exceed_hard_limit() {
bail!("Hard limit exceeded in negamax");
}
@@ -137,7 +137,7 @@ pub fn negamax(
if legal_moves == 0 {
if in_check {
return Ok(-MATE_SCORE + plies as i32);
return Ok(-MATE_SCORE + plies as i16);
}
return Ok(0);
}

View File

@@ -6,11 +6,11 @@ use super::{move_ordering::score_move, time::TimeInfo, transposition_table::Node
pub fn quiescence(
game: &mut Game,
mut alpha: i32,
beta: i32,
mut alpha: i16,
beta: i16,
time: &TimeInfo,
nodes: &mut u64,
) -> Result<i32> {
) -> Result<i16> {
if *nodes & 1024 == 0 && time.exceed_hard_limit() {
bail!("Hard limit exceeded in quiescence");
}

View File

@@ -31,7 +31,7 @@ pub struct TTEntry {
pub hash: ZobristHash,
pub mv: Option<Move>,
pub depth: u8,
pub score: i32,
pub score: i16,
pub node_type: NodeType,
}
@@ -40,7 +40,7 @@ impl TTEntry {
hash: ZobristHash,
mv: Option<Move>,
depth: u8,
score: i32,
score: i16,
node_type: NodeType,
) -> Self {
Self {