podch 0.1.0

Game engine for the podch abstract board game
Documentation
use std::fmt;

/// Player's color or color of their stone
///
/// # Examples
/// ```
/// assert_eq!(-podch::Stone::None, podch::Stone::None);
/// assert_eq!(-podch::Stone::Dark, podch::Stone::Light);
/// assert_eq!(-podch::Stone::Light, podch::Stone::Dark);
/// ```
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum Stone {
    /// Square without stones
    None,
    /// Player starting turn
    Dark,
    /// Player finishing turn
    Light,
}

impl Default for Stone {
    fn default() -> Self {
        Self::None
    }
}

impl std::ops::Neg for Stone {
    type Output = Stone;

    fn neg(self) -> Self::Output {
        match self {
            Stone::None => Stone::None,
            Stone::Dark => Stone::Light,
            Stone::Light => Stone::Dark,
        }
    }
}

impl From<Stone> for u8 {
    fn from(stone: Stone) -> Self {
        match stone {
            Stone::None => 0,
            Stone::Dark => 1,
            Stone::Light => 2,
        }
    }
}

impl From<Stone> for char {
    fn from(stone: Stone) -> Self {
        match stone {
            Stone::None => '0',
            Stone::Dark => '1',
            Stone::Light => '2',
        }
    }
}

impl From<u8> for Stone {
    fn from(x: u8) -> Self {
        match x {
            0 => Stone::None,
            1 => Stone::Dark,
            2 => Stone::Light,
            _ => panic!("invalid Stone value {}", x),
        }
    }
}

impl fmt::Display for Stone {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        <Self as Into<u8>>::into(*self).fmt(f)
    }
}