feat(card_game): add Suit::is_black and Rank::value convenience methods

This commit is contained in:
funman300
2026-06-08 10:55:05 -07:00
parent 0cdfa5446a
commit 2eaa99e82d
+8
View File
@@ -72,6 +72,10 @@ impl Suit {
pub const fn is_red(self) -> bool { pub const fn is_red(self) -> bool {
self as u8 & 0b01 != 0 self as u8 & 0b01 != 0
} }
/// Is the suit black.
pub const fn is_black(self) -> bool {
!self.is_red()
}
/// Suit value is 2 bits, is_red is the low bit. /// Suit value is 2 bits, is_red is the low bit.
pub const fn suit_high_bit(self) -> bool { pub const fn suit_high_bit(self) -> bool {
self as u8 & 0b10 != 0 self as u8 & 0b10 != 0
@@ -130,6 +134,10 @@ impl Rank {
_ => return None, _ => return None,
}) })
} }
/// Numeric value: Ace = 1, King = 13.
pub const fn value(self) -> u8 {
self as u8
}
pub const fn checked_add(self, offset: u8) -> Option<Rank> { pub const fn checked_add(self, offset: u8) -> Option<Rank> {
match (self as u8).checked_add(offset) { match (self as u8).checked_add(offset) {
Some(rank) => Self::new(rank), Some(rank) => Self::new(rank),