Convert cost of costs and cards
This commit is contained in:
parent
eae41ba556
commit
c820551baa
1 changed files with 8 additions and 5 deletions
13
Magic.hs
13
Magic.hs
|
@ -18,12 +18,12 @@ 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 (Cost []) = 0
|
converted :: a -> Int
|
||||||
converted (Cost cost) = (foldl (\t (Mana x _) -> t + x) 0) cost
|
|
||||||
|
|
||||||
converted_card :: Card -> Int
|
instance ManaCost Cost where
|
||||||
converted_card (Card _ _ cost) = converted cost
|
converted (Cost []) = 0
|
||||||
|
converted (Cost cost) = (foldl (\t (Mana x _) -> t + x) 0) 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]))
|
||||||
|
|
Loading…
Reference in a new issue