modes:*: Implement Hand::high_card on consumers.

This commit is contained in:
2026-04-14 21:23:48 +01:00
committed by oreodave
parent 25511443a5
commit f3d0d6dab2
3 changed files with 18 additions and 3 deletions

View File

@@ -46,6 +46,10 @@ impl Hand for Pair {
!self.0.is_joker() !self.0.is_joker()
} }
fn high_card(&self) -> Card {
self.1
}
fn footstool(&self, b: &Self) -> Footstool { fn footstool(&self, b: &Self) -> Footstool {
match self.cmp(b) { match self.cmp(b) {
// There is no footstool if self is beaten by other. // There is no footstool if self is beaten by other.
@@ -57,8 +61,10 @@ impl Hand for Pair {
Ordering::Greater => { Ordering::Greater => {
// By construction, Pair::1 is always a playing card so we may // By construction, Pair::1 is always a playing card so we may
// safely unwrap here. // safely unwrap here.
let s1 = Single::new(self.1).unwrap(); let [s1, s2] = [self, b]
let s2 = Single::new(b.1).unwrap(); .map(Hand::high_card)
.map(Single::new)
.map(Option::unwrap);
match s1.footstool(&s2) { match s1.footstool(&s2) {
Footstool::Full => Footstool::Half, Footstool::Full => Footstool::Half,
_ => Footstool::None, _ => Footstool::None,

View File

@@ -22,6 +22,11 @@ impl Hand for Single {
true true
} }
fn high_card(&self) -> Card {
// I am the high card???
self.0
}
fn footstool(&self, other: &Self) -> Footstool { fn footstool(&self, other: &Self) -> Footstool {
// We use deck_abs() to get an index in the overall deck ordering. // We use deck_abs() to get an index in the overall deck ordering.
match (self.0.deck_abs(), other.0.deck_abs()) { match (self.0.deck_abs(), other.0.deck_abs()) {

View File

@@ -24,7 +24,7 @@ impl Triple {
} }
} }
fn high_pair(&self) -> Pair { pub fn high_pair(&self) -> Pair {
Pair::new(self.1, self.2).unwrap() Pair::new(self.1, self.2).unwrap()
} }
@@ -71,6 +71,10 @@ impl Hand for Triple {
self.count_jokers() == 0 self.count_jokers() == 0
} }
fn high_card(&self) -> Card {
self.2
}
fn footstool(&self, other: &Self) -> Footstool { fn footstool(&self, other: &Self) -> Footstool {
match self.cmp(other) { match self.cmp(other) {
// There is no footstool if self is beaten by other. // There is no footstool if self is beaten by other.