diff --git a/Magic.hs b/Magic.hs index 228a6fc..3c2b054 100644 --- a/Magic.hs +++ b/Magic.hs @@ -18,12 +18,12 @@ data Mana = Mana Int Color data Cost = Cost [Mana] deriving (Show, Eq) -converted :: Cost -> Int -converted (Cost []) = 0 -converted (Cost cost) = (foldl (\t (Mana x _) -> t + x) 0) cost +class ManaCost a where + converted :: a -> Int -converted_card :: Card -> Int -converted_card (Card _ _ cost) = converted cost +instance ManaCost Cost where + converted (Cost []) = 0 + converted (Cost cost) = (foldl (\t (Mana x _) -> t + x) 0) cost color :: Color -> Cost -> Int color c (Cost cost) = converted (Cost (filter (\(Mana _ col) -> col == c) cost)) @@ -52,5 +52,8 @@ data Rarity = Land data Card = Card Rarity String Cost deriving (Show, Eq) +instance ManaCost Card where + converted (Card _ _ cost) = converted cost + deck = (replicate 13 (Card Land "Swamp" (Cost []))) ++ (replicate 13 (Card Land "Plains" (Cost []))) ++ replicate 4 (Card Mythic "Jace Beleren" (Cost [Mana 1 Colorless, Mana 2 Blue]))