chessfriend/core/src/score.rs

72 lines
1.3 KiB
Rust
Raw Normal View History

// Eryn Wells <eryn@erynwells.me>
use std::ops::{Add, AddAssign, Mul, Sub, SubAssign};
pub(crate) type ScoreInner = i32;
/// A score for a position in centipawns.
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct Score(ScoreInner);
impl Score {
#[must_use]
pub const fn zero() -> Self {
Self(0)
}
#[must_use]
pub const fn new(value: ScoreInner) -> Self {
Self(value)
}
}
impl Add for Score {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Score(self.0 + rhs.0)
}
}
impl AddAssign for Score {
fn add_assign(&mut self, rhs: Self) {
self.0 += rhs.0;
}
}
impl Sub for Score {
type Output = Self;
fn sub(self, rhs: Self) -> Self::Output {
Score(self.0 - rhs.0)
}
}
impl SubAssign for Score {
fn sub_assign(&mut self, rhs: Self) {
self.0 -= rhs.0;
}
}
impl Mul<ScoreInner> for Score {
type Output = Score;
fn mul(self, rhs: ScoreInner) -> Self::Output {
Score(self.0 * rhs)
}
}
impl Mul<Score> for ScoreInner {
type Output = Score;
fn mul(self, rhs: Score) -> Self::Output {
Score(self * rhs.0)
}
}
impl From<ScoreInner> for Score {
fn from(value: ScoreInner) -> Self {
Score(value)
}
}