hearts 0.1.1

Cards, tricks, and a rules-driven state machine for the card game Hearts
Documentation
//! Game configuration.
//!
//! Version 0.1 plays standard Hearts only, so [`Rules`] has a single knob:
//! the score that ends the game.  The struct is `#[non_exhaustive]` to leave
//! room for the documented variant roadmap (moon add/subtract choice, the
//! Omnibus J♦, Q♠ breaking hearts, no-passing games) without breakage:
//! start from [`Rules::new`] and mutate fields, e.g.
//! `rules.game_target = 50;`.

/// The rules of a game
///
/// All fields are public knobs; see the [module documentation](self) for the
/// preset-and-adjust pattern.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub struct Rules {
    /// The score that ends the game: 100 traditionally; shorter games play
    /// to 50, and the lowest total wins
    pub game_target: u16,
}

impl Rules {
    /// Standard Hearts, first to 100 loses
    #[must_use]
    #[inline]
    pub const fn new() -> Self {
        Self { game_target: 100 }
    }
}

impl Default for Rules {
    #[inline]
    fn default() -> Self {
        Self::new()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn presets() {
        let rules = Rules::default();
        assert_eq!(rules, Rules::new());
        assert_eq!(rules.game_target, 100);
    }
}