lib/CCard.hs

61 lines
1 KiB
Haskell
Raw Normal View History

module CCard where
import Data.Word (Word64)
2018-01-30 18:17:52 +01:00
import Data.Bits (setBit, (.|.), (.&.), shift, xor)
newtype Card = Card Int
type Pack = Word64
data Flower =
Pine
| Plum
| Cherry
| Wisteria
| Iris
| Peony
| BushClover
| SusukiGrass
| Chrysanthemum
| Maple
| Willow
| Paulownia
deriving (Eq, Ord, Enum, Show)
flower :: Card -> Flower
flower (Card n) = toEnum $ n `div` 4
set :: [Int] -> Pack
set = foldl setBit 0
inoshikacho :: Pack
inoshikacho = set [23, 27, 39]
animals :: Pack
animals = set [7, 15, 19, 30, 35, 42] .|. inoshikacho
blue :: Pack
blue = set [22, 37, 41]
poetry :: Pack
poetry = set [2, 6, 10]
ribbons = set [14, 18, 26, 41] .|. blue .|. poetry
lights :: Pack
lights = set [3, 11, 31, 43, 47]
2018-01-30 18:17:52 +01:00
lastIndex :: Int
lastIndex = 47
plain :: Pack
plain = pack `xor` (lights .|. ribbons .|. animals) .&. pack
pack :: Pack
pack = 1 `shift` (lastIndex + 1) - 1
pair :: Card -> Card -> Bool
pair card1 card2 = flower card1 == flower card2
cards :: [Card]
2018-01-30 18:17:52 +01:00
cards = map Card [0..lastIndex]