From 81ea0f259a49d1a66374afe747334d96eee34b6a Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Sat, 7 Jan 2023 20:29:29 +0800 Subject: Card.isSpecial and isValid --- Card.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'Card.hs') diff --git a/Card.hs b/Card.hs index 3ba3ce1..321df84 100644 --- a/Card.hs +++ b/Card.hs @@ -35,3 +35,15 @@ shuffle gen xs = (head right):(shuffle newGen (left ++ (tail right))) where (rand, newGen) = random gen i = rand `mod` (length xs) (left, right) = splitAt i xs + +-- | Check if card is special. +isSpecial :: Card -> Bool +isSpecial (Card _ rk) + | rk `elem` [Two, Three, Seven, Jack, Queen] = True + | otherwise = False + +-- | Check if `card` is valid after `prev`. +isValid :: Card -> Card -> Bool +isValid prev@(Card st' rk') card@(Card st rk) = + match && (not (isSpecial prev) || isSpecial card) + where match = (st == st') || (rk == rk') -- cgit v1.2.3