-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhands.hs
More file actions
25 lines (20 loc) · 1.04 KB
/
hands.hs
File metadata and controls
25 lines (20 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
module Hands where
import Cards
{-
- use the "record syntax" to define the combo data types.
- for example a "Three of a kind"
- the benefit: cards don't have to be in any order as long as there present in a _Hand_
-}
type Hand = [Card]
data Combo = StraightFlush | FourOfAKind | FullHouse | Flush |
Straight | ThreeOfAKind | OnePair Card Card | HighCards
deriving (Show, Ord, Eq)
isOnePair :: Hand -> Maybe Combo
isOnePair (card1@(Card value1 _) :card2@(Card value2 _) :xs) = case value1 == value2 of
True -> Just (OnePair card1 card2)
False -> isOnePair (card2:xs)
isOnePair (_:xs) = Nothing
-- quickcheck... isOnePair [Card {value = Two, suit = Spades }, Card {value = Two, suit = Hearts}]
-- [9C,5H,9S,KS,KD]
--
-- isOnePair [Card {value = Two, suit = Spades }, Card {value = Three, suit = Diamonds}, Card {value = Four, suit = Clubs}, Card {value = Two, suit = Hearts}, Card {value = Five, suit = Spades}]