card: split up into its own module.

This commit is contained in:
2026-04-05 05:02:17 +01:00
committed by oreodave
parent 0d2eed5369
commit 285d816707
6 changed files with 398 additions and 1 deletions

46
src/card/ord.rs Normal file
View File

@@ -0,0 +1,46 @@
use crate::card::{Card, PlayingCard};
use std::cmp::Ordering;
impl Ord for PlayingCard {
fn cmp(&self, other: &Self) -> Ordering {
self.abs().cmp(&other.abs())
}
}
impl Ord for Card {
fn cmp(&self, other: &Self) -> Ordering {
match (self, other) {
(Self::PlayingCard(c1), Self::PlayingCard(c2)) => c1.cmp(c2),
// Jokers should not really care about internal ordering.
(Self::Joker(_), Self::Joker(_)) => Ordering::Equal,
// Jokers are the lowest possible card so any Playing Cards are
// better than them.
(Self::Joker(_), _) => Ordering::Less,
(_, Self::Joker(_)) => Ordering::Greater,
}
}
}
impl PartialEq for PlayingCard {
fn eq(&self, other: &Self) -> bool {
self.cmp(other) == Ordering::Equal
}
}
impl PartialEq for Card {
fn eq(&self, other: &Self) -> bool {
self.cmp(other) == Ordering::Equal
}
}
impl PartialOrd for PlayingCard {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl PartialOrd for Card {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}