[core, position] Rename the type of Score's inner value → Value
This commit is contained in:
parent
4e80cc36ca
commit
1ae6d5df48
3 changed files with 57 additions and 18 deletions
|
@ -1,6 +1,6 @@
|
|||
// Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
use crate::{Direction, score::ScoreInner};
|
||||
use crate::{Direction, score};
|
||||
use std::fmt;
|
||||
use thiserror::Error;
|
||||
|
||||
|
@ -59,7 +59,7 @@ impl Color {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub const fn score_factor(self) -> ScoreInner {
|
||||
pub const fn score_factor(self) -> score::Value {
|
||||
match self {
|
||||
Color::White => 1,
|
||||
Color::Black => -1,
|
||||
|
|
|
@ -5,22 +5,53 @@ use std::{
|
|||
ops::{Add, AddAssign, Mul, Neg, Sub, SubAssign},
|
||||
};
|
||||
|
||||
pub(crate) type ScoreInner = i32;
|
||||
pub(crate) type Value = i32;
|
||||
|
||||
/// A score for a position in centipawns.
|
||||
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||
pub struct Score(ScoreInner);
|
||||
pub struct Score(Value);
|
||||
|
||||
impl Score {
|
||||
#[must_use]
|
||||
pub const fn zero() -> Self {
|
||||
Self(0)
|
||||
}
|
||||
pub const ZERO: Score = Score(0);
|
||||
|
||||
/// The minimum possible value of a score. Notably, this is *not* the
|
||||
/// minimum value for the inner integer value so negation works correctly.
|
||||
/// This property is important during search, which relies on being able to
|
||||
/// negate "infinity".
|
||||
///
|
||||
/// ## Examples
|
||||
///
|
||||
/// ```
|
||||
/// use chessfriend_core::score::Score;
|
||||
/// assert_eq!(!Score::MIN, Score::MAX);
|
||||
/// ```
|
||||
///
|
||||
pub const MIN: Score = Score(Value::MIN + 1);
|
||||
|
||||
/// The maximum possible value of a score.
|
||||
pub const MAX: Score = Score(Value::MAX);
|
||||
|
||||
const CENTIPAWNS_PER_POINT: f32 = 100.0;
|
||||
|
||||
#[must_use]
|
||||
pub const fn new(value: ScoreInner) -> Self {
|
||||
pub const fn new(value: Value) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
|
||||
/// Returns `true` if this [`Score`] is zero.
|
||||
///
|
||||
/// ## Examples
|
||||
///
|
||||
/// ```
|
||||
/// use chessfriend_core::score::Score;
|
||||
/// assert!(Score::ZERO.is_zero());
|
||||
/// assert!(Score::new(0).is_zero());
|
||||
/// ```
|
||||
///
|
||||
#[must_use]
|
||||
pub const fn is_zero(&self) -> bool {
|
||||
self.0 == 0
|
||||
}
|
||||
}
|
||||
|
||||
impl Add for Score {
|
||||
|
@ -51,15 +82,15 @@ impl SubAssign for Score {
|
|||
}
|
||||
}
|
||||
|
||||
impl Mul<ScoreInner> for Score {
|
||||
type Output = Score;
|
||||
impl Mul<Value> for Score {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(self, rhs: ScoreInner) -> Self::Output {
|
||||
fn mul(self, rhs: Value) -> Self::Output {
|
||||
Score(self.0 * rhs)
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<Score> for ScoreInner {
|
||||
impl Mul<Score> for Value {
|
||||
type Output = Score;
|
||||
|
||||
fn mul(self, rhs: Score) -> Self::Output {
|
||||
|
@ -67,8 +98,16 @@ impl Mul<Score> for ScoreInner {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<ScoreInner> for Score {
|
||||
fn from(value: ScoreInner) -> Self {
|
||||
impl Neg for Score {
|
||||
type Output = Self;
|
||||
|
||||
fn neg(self) -> Self::Output {
|
||||
Score(-self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Value> for Score {
|
||||
fn from(value: Value) -> Self {
|
||||
Score(value)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue