Skip to content

Commit

Permalink
reduce Value range to +-4000
Browse files Browse the repository at this point in the history
  • Loading branch information
brunocodutra committed Aug 25, 2024
1 parent 4e2e118 commit a653976
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/nnue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ mod tests {
for weights in features.array_chunks_mut::<768>() {
let (small, _, _) = weights.select_nth_unstable(32);
assert!(small.iter().fold(bias, |s, &v| s + v).abs() <= i16::MAX as i32);
let (_, _, large) = weights.select_nth_unstable(Positional::LEN - 33);
let (_, _, large) = weights.select_nth_unstable(735);
assert!(large.iter().fold(bias, |s, &v| s + v).abs() <= i16::MAX as i32);
}
});
Expand Down
2 changes: 1 addition & 1 deletion lib/nnue/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Accumulator for Material {

#[inline(always)]
fn evaluate(&self, turn: Color, phase: usize) -> i32 {
(self.0[turn as usize][phase] - self.0[turn.flip() as usize][phase]) / 32
(self.0[turn as usize][phase] - self.0[turn.flip() as usize][phase]) / 80
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/nnue/positional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Accumulator for Positional {

#[inline(always)]
fn evaluate(&self, turn: Color, phase: usize) -> i32 {
Nnue::hidden(phase).forward([&self.0[turn as usize], &self.0[turn.flip() as usize]]) / 16
Nnue::hidden(phase).forward([&self.0[turn as usize], &self.0[turn.flip() as usize]]) / 40
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/nnue/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct ValueRepr(#[cfg_attr(test, strategy(Self::MIN..=Self::MAX))] <Self as
unsafe impl Integer for ValueRepr {
type Repr = i16;
const MIN: Self::Repr = -Self::MAX;
const MAX: Self::Repr = 8000;
const MAX: Self::Repr = 4000;
}

/// A position's static evaluation.
Expand Down
12 changes: 6 additions & 6 deletions lib/search/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ impl Engine {
depth: Depth,
ply: Ply,
) -> Option<Depth> {
let bounds = -(alpha - 60)..-(alpha - 401);
let bounds = -(alpha - 24)..-(alpha - 161);
let r = match (alpha + next.clone().see(m.whither(), bounds)).get() {
..=60 => return None,
61..=200 => 1,
201..=400 => 2,
..=24 => return None,
25..=80 => 1,
81..=160 => 2,
_ => 3,
};

Expand Down Expand Up @@ -222,7 +222,7 @@ impl Engine {
if Some(m) == transposition.map(|t| t.best()) {
(m, Value::upper())
} else if Self::KILLERS.with_borrow(|ks| ks.contains(ply, pos.turn(), m)) {
(m, Value::new(100))
(m, Value::new(40))
} else if m.is_quiet() {
(m, Value::new(0))
} else {
Expand Down Expand Up @@ -308,7 +308,7 @@ impl Engine {
'id: for d in depth.get()..=limit.get() {
let mut overtime = time.end - time.start;
let mut depth = Depth::new(d);
let mut delta: i16 = 24;
let mut delta: i16 = 10;

let (mut lower, mut upper) = match d {
..=4 => (Score::lower(), Score::upper()),
Expand Down
2 changes: 1 addition & 1 deletion lib/search/ply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ unsafe impl Integer for PlyRepr {
const MIN: Self::Repr = -Self::MAX;

#[cfg(not(test))]
const MAX: Self::Repr = 127;
const MAX: Self::Repr = 95;

#[cfg(test)]
const MAX: Self::Repr = 3;
Expand Down
4 changes: 2 additions & 2 deletions lib/search/score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct ScoreRepr(#[cfg_attr(test, strategy(Self::MIN..=Self::MAX))] <Self as
unsafe impl Integer for ScoreRepr {
type Repr = i16;
const MIN: Self::Repr = -Self::MAX;
const MAX: Self::Repr = 8191;
const MAX: Self::Repr = 4095;
}

/// The minimax score.
Expand Down Expand Up @@ -50,7 +50,7 @@ impl Perspective for Score {
}

impl Binary for Score {
type Bits = Bits<u16, 14>;
type Bits = Bits<u16, 13>;

#[inline(always)]
fn encode(&self) -> Self::Bits {
Expand Down
4 changes: 2 additions & 2 deletions lib/search/transposition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl Transposition {
}

impl Binary for Transposition {
type Bits = Bits<u64, 38>;
type Bits = Bits<u64, 37>;

#[inline(always)]
fn encode(&self) -> Self::Bits {
Expand All @@ -125,7 +125,7 @@ impl Binary for Transposition {
}
}

type Signature = Bits<u32, 26>;
type Signature = Bits<u32, 27>;

#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
#[cfg_attr(test, derive(test_strategy::Arbitrary))]
Expand Down

0 comments on commit a653976

Please sign in to comment.