use crate::types::Color;
use super::types::Evaluation;
const CP_GRADIENT: f64 = 0.0035;
pub fn get_expected_points(eval: &Evaluation, color: Option<Color>) -> f64 {
match eval {
Evaluation::Mate(0) => {
color.map(|c| if c == Color::White { 1.0 } else { 0.0 })
.unwrap_or(0.5)
}
Evaluation::Mate(v) => {
if *v > 0 { 1.0 } else { 0.0 }
}
Evaluation::Centipawn(cp) => {
1.0 / (1.0 + (-CP_GRADIENT * *cp as f64).exp())
}
}
}
pub fn get_expected_points_loss(
before: &Evaluation,
after: &Evaluation,
color: Color,
) -> f64 {
let before_pts = get_expected_points(before, Some(color.opposite()));
let after_pts = get_expected_points(after, Some(color));
let raw_loss = match color {
Color::White => before_pts - after_pts,
Color::Black => after_pts - before_pts,
};
raw_loss.clamp(0.0, 1.0)
}