use std::fmt::Display;
use strum::{EnumIter, FromRepr};
use crate::core::{Card, Suit};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct FrenchCard {
rank: FrenchRank,
suit: Suit,
}
impl FrenchCard {
pub fn new(rank: FrenchRank, suit: Suit) -> Self {
Self { rank, suit }
}
pub fn rank(&self) -> FrenchRank {
self.rank
}
pub fn suit(&self) -> Suit {
self.suit
}
}
impl Default for FrenchCard {
fn default() -> Self {
FrenchCard {
rank: FrenchRank::Ace,
suit: Suit::Hearts,
}
}
}
impl Display for FrenchCard {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}{}", self.rank as u8, self.suit)
}
}
impl Card for FrenchCard {}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct Joker;
impl Card for Joker {}
impl Display for Joker {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "JK")
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FrenchWithJoker {
Normal(FrenchCard),
Joker(Joker),
}
impl Card for FrenchWithJoker {}
impl Default for FrenchWithJoker {
fn default() -> Self {
Self::Normal(FrenchCard {
rank: FrenchRank::Ace,
suit: Suit::Hearts,
})
}
}
impl Display for FrenchWithJoker {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
FrenchWithJoker::Normal(c) => write!(f, "{c}"),
FrenchWithJoker::Joker(c) => write!(f, "{c}"),
}
}
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, EnumIter, FromRepr, Hash)]
#[repr(u8)]
pub enum FrenchRank {
Ace = 1,
Two,
Three,
Four,
Five,
Six,
Seven,
Eight,
Nine,
Ten,
Jack,
Queen,
King,
}