Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import System.Environment
- import Data.Char
- import Data.Maybe
- import Control.Monad
- import Data.List
- data Type = Bug | Dark | Dragon | Electric | Fighting | Fire | Flying | Ghost | Grass | Ground | Ice | Normal | Poison | Psychic | Rock | Steel | Water
- deriving (Show, Ord, Eq, Enum, Bounded)
- data Typeset = Typeset { z :: [Type]
- , ie :: [Type]
- , se :: [Type]
- , n :: [Type]
- } deriving (Show, Ord, Eq)
- newtype Pokemon = Pokemon { t :: [Type] } deriving (Show)
- mkTypeset a b c = Typeset a b c $ remove allTypes (concat [a, b, c])
- lookupJust i set = fromJust $ lookup i set
- allTypes = [minBound..maxBound] :: [Type]
- remove = flip (filter . (not .) . flip elem)
- filterMulti :: [a -> Bool] -> [a] -> [a]
- filterMulti filters l = concat $ map (\f -> filter f l) filters
- types :: [(Type, Typeset)]
- types = [ (Normal, mkTypeset [Ghost] [] [Fighting])
- , (Fighting, mkTypeset [] [Rock, Bug, Dark] [Flying, Psychic])
- , (Flying, mkTypeset [Ground] [Fighting, Bug, Grass] [Rock, Electric, Ice])
- , (Poison, mkTypeset [] [Fighting, Poison, Bug, Grass] [Ground, Psychic])
- , (Ground, mkTypeset [Electric] [Poison, Rock] [Water, Grass, Ice])
- , (Rock, mkTypeset [] [Normal, Flying, Poison, Fire] [Fighting, Ground, Steel, Water, Grass])
- , (Bug, mkTypeset [] [Fighting, Ground, Grass] [Flying, Rock, Fire])
- , (Ghost, mkTypeset [Normal, Fighting] [Poison, Bug] [Ghost, Dark])
- , (Steel, mkTypeset [Poison] [Normal, Flying, Rock, Bug, Ghost, Steel, Grass, Psychic, Ice, Dragon, Dark] [Fighting, Ground, Fire])
- , (Fire, mkTypeset [] [Bug, Steel, Fire, Grass, Ice] [Ground, Rock, Water])
- , (Water, mkTypeset [] [Steel, Fire, Water, Ice] [Grass, Electric])
- , (Grass, mkTypeset [] [Ground, Water, Grass, Electric] [Flying, Poison, Bug, Fire, Ice])
- , (Electric, mkTypeset [] [Flying, Steel, Electric] [Ground])
- , (Psychic, mkTypeset [] [Fighting, Psychic] [Bug, Ghost, Dark])
- , (Ice, mkTypeset [] [Ice] [Fighting, Rock, Steel, Fire])
- , (Dragon, mkTypeset [] [Fire, Water, Grass, Electric] [Ice, Dragon])
- , (Dark, mkTypeset [Psychic] [Ghost, Dark] [Fighting, Bug])
- ]
- pokemon :: [(String, Pokemon)]
- pokemon = [ ("treecko", Pokemon [Grass])
- , ("grovyle", Pokemon [Grass])
- , ("sceptile", Pokemon [Grass])
- , ("torchic", Pokemon [Fire])
- , ("combusken", Pokemon [Fire, Fighting])
- , ("blaziken", Pokemon [Fire, Fighting])
- , ("mudkip", Pokemon [Water])
- , ("marshtomp", Pokemon [Water, Ground])
- , ("swampert", Pokemon [Water, Ground])
- , ("poochyena", Pokemon [Dark])
- , ("mightyena", Pokemon [Dark])
- , ("zigzagoon", Pokemon [Normal])
- , ("linoone", Pokemon [Normal])
- , ("wurmple", Pokemon [Bug])
- , ("silcoon", Pokemon [Bug])
- , ("beautifly", Pokemon [Bug, Flying])
- , ("cascoon", Pokemon [Bug])
- , ("dustox", Pokemon [Bug, Poison])
- , ("lotad", Pokemon [Water, Grass])
- , ("lombre", Pokemon [Water, Grass])
- , ("ludicolo", Pokemon [Water, Grass])
- , ("seedot", Pokemon [Grass])
- , ("nuzleaf", Pokemon [Grass, Dark])
- , ("shiftry", Pokemon [Grass, Dark])
- , ("taillow", Pokemon [Normal, Flying])
- , ("swellow", Pokemon [Normal, Flying])
- , ("wingull", Pokemon [Water, Flying])
- , ("pelipper", Pokemon [Water, Flying])
- , ("ralts", Pokemon [Psychic])
- , ("kirlia", Pokemon [Psychic])
- , ("gardevoir", Pokemon [Psychic])
- , ("surskit", Pokemon [Bug, Water])
- , ("masquerain", Pokemon [Bug, Flying])
- , ("shroomish", Pokemon [Grass])
- , ("breloom", Pokemon [Grass, Fighting])
- , ("slakoth", Pokemon [Normal])
- , ("vigoroth", Pokemon [Normal])
- , ("slaking", Pokemon [Normal])
- , ("nincada", Pokemon [Bug, Ground])
- , ("ninjask", Pokemon [Bug, Flying])
- , ("shedinja", Pokemon [Bug, Ghost])
- , ("whismur", Pokemon [Normal])
- , ("loudred", Pokemon [Normal])
- , ("exploud", Pokemon [Normal])
- , ("makuhita", Pokemon [Fighting])
- , ("hariyama", Pokemon [Fighting])
- , ("azurill", Pokemon [Water])
- , ("nosepass", Pokemon [Rock])
- , ("skitty", Pokemon [Normal])
- , ("delcatty", Pokemon [Normal])
- , ("sableye", Pokemon [Dark, Ghost])
- , ("mawile", Pokemon [Steel])
- , ("aron", Pokemon [Rock, Steel])
- , ("lairon", Pokemon [Rock, Steel])
- , ("aggron", Pokemon [Rock, Steel])
- , ("meditite", Pokemon [Fighting, Psychic])
- , ("medicham", Pokemon [Fighting, Psychic])
- , ("electrike", Pokemon [Electric])
- , ("manectric", Pokemon [Electric])
- , ("plusle", Pokemon [Electric])
- , ("minun", Pokemon [Electric])
- , ("volbeat", Pokemon [Bug])
- , ("illumise", Pokemon [Bug])
- , ("roselia", Pokemon [Grass, Poison])
- , ("gulpin", Pokemon [Poison])
- , ("swalot", Pokemon [Poison])
- , ("carvanha", Pokemon [Water, Dark])
- , ("sharpedo", Pokemon [Water, Dark])
- , ("wailmer", Pokemon [Water])
- , ("wailord", Pokemon [Water])
- , ("numel", Pokemon [Fire, Ground])
- , ("camerupt", Pokemon [Fire, Ground])
- , ("torkoal", Pokemon [Fire])
- , ("spoink", Pokemon [Psychic])
- , ("grumpig", Pokemon [Psychic])
- , ("spinda", Pokemon [Normal])
- , ("trapinch", Pokemon [Ground])
- , ("vibrava", Pokemon [Ground, Dragon])
- , ("flygon", Pokemon [Ground, Dragon])
- , ("cacnea", Pokemon [Grass])
- , ("cacturne", Pokemon [Grass, Dark])
- , ("swablu", Pokemon [Normal, Flying])
- , ("altaria", Pokemon [Dragon, Flying])
- , ("zangoose", Pokemon [Normal])
- , ("seviper", Pokemon [Poison])
- , ("lunatone", Pokemon [Rock, Psychic])
- , ("solrock", Pokemon [Rock, Psychic])
- , ("barboach", Pokemon [Water, Ground])
- , ("whiscash", Pokemon [Water, Ground])
- , ("corphish", Pokemon [Water])
- , ("crawdaunt", Pokemon [Water, Dark])
- , ("baltoy", Pokemon [Ground, Psychic])
- , ("claydol", Pokemon [Ground, Psychic])
- , ("lileep", Pokemon [Rock, Grass])
- , ("cradily", Pokemon [Rock, Grass])
- , ("anorith", Pokemon [Rock, Bug])
- , ("armaldo", Pokemon [Rock, Bug])
- , ("feebas", Pokemon [Water])
- , ("milotic", Pokemon [Water])
- , ("castform", Pokemon [Normal])
- , ("kecleon", Pokemon [Normal])
- , ("shuppet", Pokemon [Ghost])
- , ("banette", Pokemon [Ghost])
- , ("duskull", Pokemon [Ghost])
- , ("dusclops", Pokemon [Ghost])
- , ("tropius", Pokemon [Flying, Grass])
- , ("chimecho", Pokemon [Psychic])
- , ("absol", Pokemon [Dark])
- , ("wynaut", Pokemon [Psychic])
- , ("snorunt", Pokemon [Ice])
- , ("glalie", Pokemon [Ice])
- , ("spheal", Pokemon [Ice, Water])
- , ("sealeo", Pokemon [Ice, Water])
- , ("walrein", Pokemon [Ice, Water])
- , ("clamperl", Pokemon [Water])
- , ("huntail", Pokemon [Water])
- , ("gorebyss", Pokemon [Water])
- , ("relicanth", Pokemon [Water, Rock])
- , ("luvdisc", Pokemon [Water])
- , ("bagon", Pokemon [Dragon])
- , ("shelgon", Pokemon [Dragon])
- , ("salamence", Pokemon [Dragon, Flying])
- , ("beldum", Pokemon [Steel, Psychic])
- , ("metang", Pokemon [Steel, Psychic])
- , ("metagross", Pokemon [Steel, Psychic])
- , ("regirock", Pokemon [Rock])
- , ("regice", Pokemon [Ice])
- , ("registeel", Pokemon [Steel])
- , ("latias", Pokemon [Dragon, Psychic])
- , ("latios", Pokemon [Dragon, Psychic])
- , ("kyogre", Pokemon [Water])
- , ("groudon", Pokemon [Ground])
- , ("rayquaza", Pokemon [Dragon, Flying])
- , ("jirachi", Pokemon [Steel, Psychic])
- , ("deoxys", Pokemon [Psychic])]
- -- 0x 0.25x 0.5x 1x 2x 4x
- effective :: Pokemon -> ([Type], [Type], [Type], [Type], [Type], [Type])
- effective pok = case pok of
- Pokemon [t] -> (immune, [], nve, n, se, [])
- where
- Typeset immune nve se n = lookupJust t types
- Pokemon [t1,t2] -> (union immune1 immune2,
- intersect nve1 nve2,
- concat [intersect nve1 n2, intersect nve2 n1],
- concat [intersect n1 n2, intersect se1 nve2, intersect se2 nve1],
- concat [intersect se1 n2, intersect se2 n1],
- intersect se1 se2)
- where
- Typeset immune1 nve1 se1 n1 = lookupJust t1 types
- Typeset immune2 nve2 se2 n2 = lookupJust t2 types
- printTypes :: ([Type], [Type], [Type], [Type], [Type], [Type]) -> IO ()
- printTypes (zero, dot25, dot5, one, two, four) = do
- put gray zero
- put boldred dot25
- put red dot5
- put id one
- put green two
- put boldgreen four
- where
- put f ts = unless (null ts) $ putStrLn $ intercalate ", " $ map (f . map (toLower) . show) ts
- color d s = "\27[" ++ d ++ "m" ++ s ++ "\27[0m"
- gray = color "30"
- red = color "31"
- boldred = color "31;1"
- green = color "32"
- boldgreen = color "32;1"
- main = do
- args <- getArgs
- case args of
- [] -> putStrLn "Usage: pokeman [pokemon name]"
- (p:_) -> case lookup (map toLower p) pokemon of
- Just pok -> printTypes $ effective pok
- Nothing -> putStrLn $ "Unknown pokemon " ++ show (map toLower p)
Add Comment
Please, Sign In to add comment