Take KoiKoi-specific objects out of Cards module

This commit is contained in:
Sasha 2018-02-03 18:08:17 +01:00
parent 3ffabc578e
commit 3f43d960f4

View file

@ -1,7 +1,7 @@
module CCard where
import Data.Word (Word64)
import Data.Bits (setBit, (.|.), (.&.), shift, xor, testBit)
import Data.Bits (setBit, shift, testBit)
import System.Random (randomRIO)
data Flower =
@ -34,39 +34,19 @@ data Card =
| Paulownia0 | Paulownia1 | Sand | Phoenix
deriving (Eq, Ord, Enum, Show)
type Pack = Word64
flower :: Card -> Flower
flower = toEnum . (`div` 4) . fromEnum
set :: [Card] -> Pack
set = foldl setBit 0 . map fromEnum
type Pack = Word64
packOfCards :: [Card] -> Pack
packOfCards = foldl setBit 0 . map fromEnum
contains :: Pack -> Card -> Bool
contains pack = testBit pack . fromEnum
inoshikacho :: Pack
inoshikacho = set [Butterflies, Boar, Deer]
animals :: Pack
animals = set [BushWarbler, Cuckoo, EightPlankBridge, Geese, SakeCup, Swallow] .|. inoshikacho
blue :: Pack
blue = set [PeonyBlue, ChrysanthemumBlue, MapleBlue]
poetry :: Pack
poetry = set [PinePoetry, PlumPoetry, CherryPoetry]
ribbons = set [WisteriaRed, IrisRed, BushCloverRed, WillowRed] .|. blue .|. poetry
lights :: Pack
lights = set [Crane, CampCurtain, FullMoon, RainMan, Phoenix]
plain :: Pack
plain = pack `xor` (lights .|. ribbons .|. animals) .&. pack
pack :: Pack
pack = 1 `shift` (fromEnum Phoenix + 1) - 1
add :: Pack -> Card -> Pack
add pack = setBit pack . fromEnum
pair :: Card -> Card -> Bool
pair card1 card2 = flower card1 == flower card2