From e0377481995c937677468865edd96ce6d2fa28c5 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Tue, 20 Aug 2019 14:15:49 +0200 Subject: [PATCH] Expose function sameMonth useful for clients too, and make it more handy --- src/Hanafuda.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Hanafuda.hs b/src/Hanafuda.hs index e1fe004..a19357e 100644 --- a/src/Hanafuda.hs +++ b/src/Hanafuda.hs @@ -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)