summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2023-01-07 20:29:29 +0800
committerFrederick Yin <fkfd@fkfd.me>2023-01-07 20:29:29 +0800
commit81ea0f259a49d1a66374afe747334d96eee34b6a (patch)
tree033eb983ed84d54e542c0930942a84a9874ccc39
parentba61f2b7363116f6530fc6c256b1ad97ef0e0861 (diff)
Card.isSpecial and isValid
-rw-r--r--Card.hs12
1 files changed, 12 insertions, 0 deletions
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')