Convert cost of costs and cards

This commit is contained in:
Correl Roush 2011-10-14 00:51:34 -04:00
parent eae41ba556
commit c820551baa

View file

@ -18,13 +18,13 @@ data Mana = Mana Int Color
data Cost = Cost [Mana] data Cost = Cost [Mana]
deriving (Show, Eq) deriving (Show, Eq)
converted :: Cost -> Int class ManaCost a where
converted :: a -> Int
instance ManaCost Cost where
converted (Cost []) = 0 converted (Cost []) = 0
converted (Cost cost) = (foldl (\t (Mana x _) -> t + x) 0) cost converted (Cost cost) = (foldl (\t (Mana x _) -> t + x) 0) cost
converted_card :: Card -> Int
converted_card (Card _ _ cost) = converted cost
color :: Color -> Cost -> Int color :: Color -> Cost -> Int
color c (Cost cost) = converted (Cost (filter (\(Mana _ col) -> col == c) cost)) 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 data Card = Card Rarity String Cost
deriving (Show, Eq) 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 []))) 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])) ++ replicate 4 (Card Mythic "Jace Beleren" (Cost [Mana 1 Colorless, Mana 2 Blue]))