summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2023-01-08 21:48:32 +0800
committerFrederick Yin <fkfd@fkfd.me>2023-01-08 21:48:32 +0800
commit347cee5089d0d0d3300fa4cfc1ec1181e179ee2b (patch)
treec2e82e8f05adbec18d099a5dc52618f93dad8a75
parent63c6921b102b5b97bc3d030b22fc941c64c0acd2 (diff)
Force special card after attack cards only
-rw-r--r--Card.hs9
1 files changed, 8 insertions, 1 deletions
diff --git a/Card.hs b/Card.hs
index 64c74c8..98e76fe 100644
--- a/Card.hs
+++ b/Card.hs
@@ -47,8 +47,15 @@ isSpecial (Card _ rk)
| rk `elem` [Two, Three, Seven, Jack, Queen] = True
| otherwise = False
+-- | Check if card attacks.
+isAttack :: Card -> Bool
+isAttack (Card _ rk)
+ | rk `elem` [Two, Three] = True
+ | otherwise = False
+
-- | Check if `card` is valid after `prev`.
+-- | If `prev` attacks, `card` must be special.
isValid :: Card -> Card -> Bool
isValid prev@(Card st' rk') card@(Card st rk) =
- match && (not (isSpecial prev) || isSpecial card)
+ match && (not (isAttack prev) || isSpecial card)
where match = (st == st') || (rk == rk')