use crate::pins::PinSet;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FoulStatus {
Clean,
Foul,
}
impl FoulStatus {
#[inline]
pub const fn is_foul(self) -> bool {
matches!(self, Self::Foul)
}
#[inline]
pub const fn is_clean(self) -> bool {
matches!(self, Self::Clean)
}
}
impl From<bool> for FoulStatus {
fn from(foul: bool) -> Self {
if foul { Self::Foul } else { Self::Clean }
}
}
impl From<FoulStatus> for bool {
fn from(status: FoulStatus) -> Self {
status.is_foul()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Roll {
knocked: PinSet,
foul: FoulStatus,
}
impl Roll {
#[inline]
pub const fn new(knocked: PinSet, foul: FoulStatus) -> Self {
Self { knocked, foul }
}
#[inline]
pub const fn clean(knocked: PinSet) -> Self {
Self {
knocked,
foul: FoulStatus::Clean,
}
}
#[inline]
pub const fn foul(knocked: PinSet) -> Self {
Self {
knocked,
foul: FoulStatus::Foul,
}
}
#[inline]
pub const fn knocked(self) -> PinSet {
self.knocked
}
#[inline]
pub const fn is_foul(self) -> bool {
self.foul.is_foul()
}
#[inline]
pub const fn foul_status(self) -> FoulStatus {
self.foul
}
#[inline]
pub const fn pin_count(self) -> u8 {
self.knocked.count()
}
#[inline]
pub const fn score(self) -> u8 {
if self.foul.is_foul() {
0
} else {
self.knocked.count()
}
}
}