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
|
, match
|
||||||
, packOfCards
|
, packOfCards
|
||||||
, remove
|
, remove
|
||||||
|
, sameMonth
|
||||||
, shuffle
|
, shuffle
|
||||||
, size
|
, size
|
||||||
) where
|
) where
|
||||||
|
@ -111,8 +112,8 @@ intersection = portBinary (.&.)
|
||||||
difference :: Pack -> Pack -> Pack
|
difference :: Pack -> Pack -> Pack
|
||||||
difference = portBinary (\a b -> a `xor` (a .&. b))
|
difference = portBinary (\a b -> a `xor` (a .&. b))
|
||||||
|
|
||||||
sameMonth :: Card -> Pack
|
sameMonth :: Card -> Pack -> Pack
|
||||||
sameMonth card = Pack $ 0xf `shift` (fromEnum card .&. 0xfc)
|
sameMonth card (Pack p) = Pack $ (0xf `shift` (fromEnum card .&. 0xfc)) .&. p
|
||||||
|
|
||||||
cards :: [Card]
|
cards :: [Card]
|
||||||
cards = [Pine0 .. Phoenix]
|
cards = [Pine0 .. Phoenix]
|
||||||
|
@ -130,7 +131,7 @@ shuffle l =
|
||||||
|
|
||||||
match :: Card -> Pack -> Either String (Pack, [Card])
|
match :: Card -> Pack -> Either String (Pack, [Card])
|
||||||
match card pack =
|
match card pack =
|
||||||
let sameMonthCards = sameMonth card `intersection` pack in
|
let sameMonthCards = sameMonth card pack in
|
||||||
case size sameMonthCards of
|
case size sameMonthCards of
|
||||||
0 -> Right (add pack card, [])
|
0 -> Right (add pack card, [])
|
||||||
1 -> Right (difference pack sameMonthCards, card : cardsOfPack sameMonthCards)
|
1 -> Right (difference pack sameMonthCards, card : cardsOfPack sameMonthCards)
|
||||||
|
|
Loading…
Reference in a new issue