From eae41ba55645823244ac83e8f1442ec674d26794 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Fri, 14 Oct 2011 00:35:15 -0400 Subject: [PATCH] Initial --- Magic.hs | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Magic.hs diff --git a/Magic.hs b/Magic.hs new file mode 100644 index 0000000..228a6fc --- /dev/null +++ b/Magic.hs @@ -0,0 +1,56 @@ +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) + +converted :: Cost -> Int +converted (Cost []) = 0 +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 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) + +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]))