use crate::state::*;
use crate::utils::panic_fast;
use pst::*;
use std::ops;
#[cfg(feature = "dev")]
use crate::tuning::tuner::TunerParameter;
pub mod material;
pub mod mobility;
pub mod params;
pub mod pawns;
pub mod pst;
pub mod safety;
pub const INITIAL_GAME_PHASE: u8 = 24;
pub const PIECE_VALUES: [i16; 6] = [100, 337, 338, 521, 1050, 10000];
pub const PIECE_PHASE_VALUES: [u8; 6] = [0, 1, 1, 2, 4, 0];
macro_rules! s {
($opening_score: expr, $ending_score: expr) => {
PackedEval::new($opening_score, $ending_score)
};
}
pub(crate) use s;
#[derive(Copy, Clone, Default)]
pub struct PackedEval {
pub data: i32,
}
impl PackedEval {
pub const fn new(opening: i16, ending: i16) -> Self {
Self { data: ((ending as i32) << 16) + opening as i32 }
}
pub const fn new_raw(data: i32) -> Self {
Self { data }
}
pub fn get_opening(&self) -> i16 {
self.data as i16
}
pub fn get_ending(&self) -> i16 {
((self.data + 0x8000) >> 16) as i16
}
pub fn taper_score(&self, game_phase: u8) -> i16 {
let opening_score = (self.get_opening() as i32) * (game_phase as i32);
let ending_score = (self.get_ending() as i32) * ((INITIAL_GAME_PHASE as i32) - (game_phase as i32));
((opening_score + ending_score) / (INITIAL_GAME_PHASE as i32)) as i16
}
#[cfg(feature = "dev")]
pub fn to_tuner_params(&self, min: i16, min_init: i16, max_init: i16, max: i16, offset: i16) -> [TunerParameter; 2] {
use crate::utils::assert_fast;
assert_fast!(min <= max);
assert_fast!(min_init <= max_init);
assert_fast!(min_init >= min && min_init <= max);
assert_fast!(max_init >= min && max_init <= max);
[
TunerParameter::new(self.get_opening() + offset, min, min_init, max_init, max),
TunerParameter::new(self.get_ending() + offset, min, min_init, max_init, max),
]
}
}
impl ops::Add<PackedEval> for PackedEval {
type Output = PackedEval;
fn add(self, rhs: PackedEval) -> PackedEval {
PackedEval::new_raw(self.data + rhs.data)
}
}
impl ops::AddAssign<PackedEval> for PackedEval {
fn add_assign(&mut self, rhs: PackedEval) {
self.data += rhs.data;
}
}
impl ops::Sub<PackedEval> for PackedEval {
type Output = PackedEval;
fn sub(self, rhs: PackedEval) -> PackedEval {
PackedEval::new_raw(self.data - rhs.data)
}
}
impl ops::SubAssign<PackedEval> for PackedEval {
fn sub_assign(&mut self, rhs: PackedEval) {
self.data -= rhs.data;
}
}
impl ops::Mul<PackedEval> for i8 {
type Output = PackedEval;
fn mul(self, rhs: PackedEval) -> PackedEval {
PackedEval::new_raw(self as i32 * rhs.data)
}
}
impl ops::Mul<PackedEval> for i16 {
type Output = PackedEval;
fn mul(self, rhs: PackedEval) -> PackedEval {
PackedEval::new_raw(self as i32 * rhs.data)
}
}
impl ops::Mul<PackedEval> for i32 {
type Output = PackedEval;
fn mul(self, rhs: PackedEval) -> PackedEval {
PackedEval::new_raw(self * rhs.data)
}
}