Expose function sameMonth useful for clients too, and make it more handy
This commit is contained in:
parent
3056974e12
commit
e037748199
1 changed files with 4 additions and 3 deletions
|
@ -13,6 +13,7 @@ module Hanafuda (
|
|||
, match
|
||||
, packOfCards
|
||||
, remove
|
||||
, sameMonth
|
||||
, shuffle
|
||||
, size
|
||||
) where
|
||||
|
@ -111,8 +112,8 @@ intersection = portBinary (.&.)
|
|||
difference :: Pack -> Pack -> Pack
|
||||
difference = portBinary (\a b -> a `xor` (a .&. b))
|
||||
|
||||
sameMonth :: Card -> Pack
|
||||
sameMonth card = Pack $ 0xf `shift` (fromEnum card .&. 0xfc)
|
||||
sameMonth :: Card -> Pack -> Pack
|
||||
sameMonth card (Pack p) = Pack $ (0xf `shift` (fromEnum card .&. 0xfc)) .&. p
|
||||
|
||||
cards :: [Card]
|
||||
cards = [Pine0 .. Phoenix]
|
||||
|
@ -130,7 +131,7 @@ shuffle l =
|
|||
|
||||
match :: Card -> Pack -> Either String (Pack, [Card])
|
||||
match card pack =
|
||||
let sameMonthCards = sameMonth card `intersection` pack in
|
||||
let sameMonthCards = sameMonth card pack in
|
||||
case size sameMonthCards of
|
||||
0 -> Right (add pack card, [])
|
||||
1 -> Right (difference pack sameMonthCards, card : cardsOfPack sameMonthCards)
|
||||
|
|
Loading…
Reference in a new issue