Are poker hands Ord or PartialOrd?

I forgot to add the kicker for TwoPair. You have to add kickers for HighCard, Pair, TwoPair. On the other hand, StraightFlush doesn't need other_cards. So it should be more like:

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum HandValue {
    HighCard {
        ranks: [Rank; 5],
    },
    Pair {
        pair: Rank,
        kickers: [Rank; 3],
    },
    TwoPair {
        high_pair: Rank,
        low_pair: Rank,
        kicker: Rank,
    },
    ThreeOfAKind(Rank),
    Straight {
        highest: Rank,
    },
    Flush {
        ranks: [Rank; 5],
    },
    FullHouse {
        triple: Rank,
        pair: Rank,
    },
    FourOfAKind(Rank),
    StraightFlush {
        highest: Rank,
    },
}
1 Like

ThreeOfAKind and FourOfAKind should also have kickers. In community card games like texas hold 'em multiple people can have those hands.

4 Likes

I created PR #103046 for that matter.

I came here to understand the theory (and there is so much) behind Ord, PartialOrd, Eq and PartialEq. But I ended up getting a solution to my exercise. Not bad.

I love the HandValue approach mostly because how enum variants are ordered in Rust. :exploding_head:

Im mostly exploring these concepts (also watching the PR by @jbe) and I have nothing more to add here. All comments were very insightful so I dont know which one to mark as the solution.

I'll just let this topic die a slow death. Unless someone thinks otherwise.

5 Likes

Wait...not sure why I was surprised by this. This is valid even for Java.

When I used enums, I never felt the need to compare invariants variants. The order of invariants variants matters only when you want enum instances to be ordered.

Going forward Im going to be cognizant of this fact. It'll save me some refactoring (and weird bugs) in case there is a future requirement to make my enum ordered.

@scottmcm Thanks for pointing out the nit.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.