From c820551baa82214c8ddc16bee2ae549965bae79d Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Fri, 14 Oct 2011 00:51:34 -0400 Subject: [PATCH] Convert cost of costs and cards --- Magic.hs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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]))