1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
//! Flag bitmask indicates special information about the turn
/// Bitmask flag depicts special capabilities of a chess turn (*check*,
/// *checkmate*, *capture*)
///
/// *Note:* `CHECK` and `CHECKMATE` are mutually exclusive flags.
#[allow(non_snake_case)]
pub mod Flag {
    /// Turn will result in a check
    pub const NONE: u8 = 0;
    /// Turn will result in a check
    pub const CHECK: u8 = 0x01 << 0;
    /// Turn will result in a checkmate
    pub const CHECKMATE: u8 = 0x01 << 1;
    /// Turn captures a piece of the opponent
    pub const CAPTURE: u8 = 0x01 << 2;
}
/// Implements function to easily check *chess turn* flags
pub trait FlagCheck {
    /// Getter function for `flags`
    fn get_flags(&self) -> u8;
    /// Returns true if flag is present
    ///
    /// # Example
    /// ```
    /// use chess_notation_parser::{Turn, Move, Square, Piece, Flag, FlagCheck};
    ///
    /// let r#move = Move {
    ///     who: Piece::King,
    ///     dst: Square::D5,
    ///     flags: Flag::CAPTURE,
    ///     src: None,
    ///     promotion: None
    /// };
    ///
    /// assert!(r#move.check_flag(Flag::CAPTURE));
    /// assert!(!r#move.check_flag(Flag::CHECK));
    /// ```
    fn check_flag(&self, flag: u8) -> bool {
        self.get_flags() & flag != 0
    }
}