I am trying to implement a poker hand evaluator, and it has gone good so far! As of right now, it’s possible to identify complete hands (5 cards), and kickers where needed. Main business is shown below (but here’s a link to the source):
data Card = Card {rank :: Rank, suit :: Suit}
-- A hand with it's highest rank(s), and kickers where needed
data Hand
= High Rank [Rank]
| Pair Rank [Rank]
| TwoPair Rank Rank (Maybe Rank)
| ThreeKind Rank [Rank]
| Straight Rank
| Flush Rank
| FullHouse Rank Rank
| FourKind Rank
| StraightFlush Rank
deriving (Show)
identifyHands :: [Card] -> [Hand]
identifyHands cs =
straightFlushes cs
<++ catMaybes [fourKind cs]
<++ fullHouses cs
<++ flushes cs
<++ straights cs
<++ threeKinds cs
<++ twoPairs cs
<++ pairs cs
<++ [high cs]
where
[] <++ xs = xs
xs <++ _ = xs
Now I need to compare the identified hands, but the Ord instance will be very, very long and repetitive as I need to compare “all” combinations. Looking at my Hand
data type, it doesn’t offer any Enum instances, so it’s hard. Do you have any suggestion as to how I can make modifications so that it would be easier to compare hands?