sashite-qi 0.1.0

Qi: an immutable, format-agnostic position model for two-player board games (chess, shogi, xiangqi, and beyond).
Documentation
//! The active-player side.

/// Which of the two players is to move.
///
/// This mirrors the Game Protocol's two-side model. It is the active player of a
/// [`Qi`](crate::Qi) position; [`flip`](Player::flip) swaps it.
///
/// # Examples
///
/// ```
/// use sashite_qi::Player;
///
/// assert_eq!(Player::First.flip(), Player::Second);
/// assert_eq!(Player::Second.flip(), Player::First);
/// assert!(Player::First.is_first());
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Player {
    /// The first player.
    First,
    /// The second player.
    Second,
}

impl Player {
    /// Returns the other player.
    #[must_use]
    pub const fn flip(self) -> Self {
        match self {
            Self::First => Self::Second,
            Self::Second => Self::First,
        }
    }

    /// Returns `true` for the first player.
    #[must_use]
    pub const fn is_first(self) -> bool {
        matches!(self, Self::First)
    }

    /// Returns `true` for the second player.
    #[must_use]
    pub const fn is_second(self) -> bool {
        matches!(self, Self::Second)
    }
}