2011-10-14 04:35:15 +00:00
|
|
|
module Magic where
|
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
-- Mana
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
data Color = Colorless
|
|
|
|
| Black
|
|
|
|
| White
|
|
|
|
| Red
|
|
|
|
| Blue
|
|
|
|
| Green
|
|
|
|
deriving (Show, Eq)
|
|
|
|
|
|
|
|
data Mana = Mana Int Color
|
|
|
|
deriving (Show, Eq)
|
|
|
|
|
|
|
|
data Cost = Cost [Mana]
|
|
|
|
deriving (Show, Eq)
|
|
|
|
|
2011-10-14 04:51:34 +00:00
|
|
|
class ManaCost a where
|
|
|
|
converted :: a -> Int
|
2011-10-14 04:35:15 +00:00
|
|
|
|
2011-10-14 04:51:34 +00:00
|
|
|
instance ManaCost Cost where
|
|
|
|
converted (Cost []) = 0
|
|
|
|
converted (Cost cost) = (foldl (\t (Mana x _) -> t + x) 0) cost
|
2011-10-14 04:35:15 +00:00
|
|
|
|
|
|
|
color :: Color -> Cost -> Int
|
|
|
|
color c (Cost cost) = converted (Cost (filter (\(Mana _ col) -> col == c) cost))
|
|
|
|
|
|
|
|
pretty :: Cost -> String
|
|
|
|
pretty c = concat ( [show (color Colorless c)
|
|
|
|
, replicate (color Black c) 'B'
|
|
|
|
, replicate (color White c) 'W'
|
|
|
|
, replicate (color Red c) 'R'
|
|
|
|
, replicate (color Blue c) 'U'
|
|
|
|
, replicate (color Green c) 'G'
|
|
|
|
])
|
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
-- Cards
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
data Rarity = Land
|
|
|
|
| Common
|
|
|
|
| Uncommon
|
|
|
|
| Rare
|
|
|
|
| Mythic
|
|
|
|
| Special
|
|
|
|
deriving (Show, Eq)
|
|
|
|
|
|
|
|
data Card = Card Rarity String Cost
|
|
|
|
deriving (Show, Eq)
|
|
|
|
|
2011-10-14 04:51:34 +00:00
|
|
|
instance ManaCost Card where
|
|
|
|
converted (Card _ _ cost) = converted cost
|
|
|
|
|
2011-10-14 05:31:33 +00:00
|
|
|
data Deck = Deck [Card]
|
|
|
|
|
|
|
|
curve :: Deck -> [(Int, Int)]
|
|
|
|
curve (Deck cards) = do
|
|
|
|
let largest = maximum (map converted cards)
|
|
|
|
map (\x -> (x, length (filter (\(Card rarity _ cost) -> rarity /= Land && converted cost == x) cards))) [0..largest]
|
|
|
|
|
|
|
|
deck = 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])))
|