import Control.Monad import Data.Ratio import Data.List data Type = Normal | Fighting | Flying | Poison | Ground | Rock | Bug | Ghost | Steel | Fire | Water | Grass | Electric | Psychic | Ice | Dragon | Dark | Fairy deriving (Enum, Show, Eq, Ord) everyType :: [Type] everyType = enumFrom Normal everyTypeCombo :: [[Type]] everyTypeCombo = filter (not . null) rawPairs where rawPairs = liftM2 makePair everyType everyType makePair t1 t2 | t1 == t2 = [t1] | t1 < t2 = [t1, t2] | otherwise = [] weightTypes :: [[Type]] -> [(Float, [Type])] weightTypes ts = map (\ts -> (typeDefRank ts, ts)) ts bestTypes :: [(Float, [Type])] bestTypes = sortBy (\a b -> fst b `compare` fst a) $ weightTypes everyTypeCombo multiTypeEff :: Type -> [Type] -> Rational multiTypeEff attack defendList = foldr effMul 1 defendList where effMul ty r = typeEff attack ty * r typeDefRank :: [Type] -> Float typeDefRank ts = rankList everyType where rankList ots = sum $ map (\t -> typeEffRank (multiTypeEff t ts) * offensiveTypeRank t) ots main :: IO () main = mapM_ print bestTypes -- This determines how resistances and weaknesses are weighted. typeEffRank :: Rational -> Float typeEffRank r | r == 0 = 3.3 | r == 1 = 0.0 | r < 1 = 0.7 / fromRational r | r > 1 = negate ((fromRational r + 1.0) ^^ 2) / 16.0 -- Weighting of attacking types. Use this to specify what you're -- defending from. offensiveTypeRank :: Type -> Float offensiveTypeRank Normal = 40.0 offensiveTypeRank Fighting = 30.0 offensiveTypeRank Flying = 80.0 offensiveTypeRank Poison = 0.0 offensiveTypeRank Ground = 20.0 offensiveTypeRank Rock = 0.0 offensiveTypeRank Bug = 10.0 offensiveTypeRank Ghost = 0.0 offensiveTypeRank Steel = 0.0 offensiveTypeRank Fire = 40.0 offensiveTypeRank Water = 0.0 offensiveTypeRank Grass = 0.0 offensiveTypeRank Electric = 0.0 offensiveTypeRank Psychic = 0.0 offensiveTypeRank Ice = 0.0 offensiveTypeRank Dragon = 0.0 offensiveTypeRank Dark = 0.0 offensiveTypeRank Fairy = 0.0 typeEff :: Type -> Type -> Rational typeEff Normal Rock = 1 % 2 typeEff Normal Steel = 1 % 2 typeEff Normal Ghost = 0 typeEff Fighting Normal = 2 typeEff Fighting Rock = 2 typeEff Fighting Steel = 2 typeEff Fighting Ice = 2 typeEff Fighting Dark = 2 typeEff Fighting Flying = 1 % 2 typeEff Fighting Poison = 1 % 2 typeEff Fighting Bug = 1 % 2 typeEff Fighting Psychic = 1 % 2 typeEff Fighting Fairy = 1 % 2 typeEff Fighting Ghost = 0 typeEff Flying Fighting = 2 typeEff Flying Bug = 2 typeEff Flying Grass = 2 typeEff Flying Rock = 1 % 2 typeEff Flying Steel = 1 % 2 typeEff Flying Electric = 1 % 2 typeEff Poison Grass = 2 typeEff Poison Fairy = 2 typeEff Poison Poison = 1 % 2 typeEff Poison Ground = 1 % 2 typeEff Poison Rock = 1 % 2 typeEff Poison Ghost = 1 % 2 typeEff Poison Steel = 0 typeEff Ground Poison = 2 typeEff Ground Rock = 2 typeEff Ground Steel = 2 typeEff Ground Fire = 2 typeEff Ground Electric = 2 typeEff Ground Bug = 1 % 2 typeEff Ground Grass = 1 % 2 typeEff Ground Flying = 0 typeEff Rock Flying = 2 typeEff Rock Bug = 2 typeEff Rock Fire = 2 typeEff Rock Ice = 2 typeEff Rock Fighting = 1 % 2 typeEff Rock Ground = 1 % 2 typeEff Rock Steel = 1 % 2 typeEff Bug Grass = 2 typeEff Bug Psychic = 2 typeEff Bug Dark = 2 typeEff Bug Fighting = 1 % 2 typeEff Bug Flying = 1 % 2 typeEff Bug Poison = 1 % 2 typeEff Bug Ghost = 1 % 2 typeEff Bug Steel = 1 % 2 typeEff Bug Fire = 1 % 2 typeEff Bug Fairy = 1 % 2 typeEff Ghost Ghost = 2 typeEff Ghost Psychic = 2 typeEff Ghost Dark = 1 % 2 typeEff Ghost Normal = 0 typeEff Steel Rock = 2 typeEff Steel Ice = 2 typeEff Steel Fairy = 2 typeEff Steel Steel = 1 % 2 typeEff Steel Fire = 1 % 2 typeEff Steel Water = 1 % 2 typeEff Steel Electric = 1 % 2 typeEff Fire Bug = 2 typeEff Fire Steel = 2 typeEff Fire Grass = 2 typeEff Fire Ice = 2 typeEff Fire Rock = 1 % 2 typeEff Fire Fire = 1 % 2 typeEff Fire Water = 1 % 2 typeEff Fire Dragon = 1 % 2 typeEff Water Ground = 2 typeEff Water Rock = 2 typeEff Water Fire = 2 typeEff Water Water = 1 % 2 typeEff Water Grass = 1 % 2 typeEff Water Dragon = 1 % 2 typeEff Grass Ground = 2 typeEff Grass Rock = 2 typeEff Grass Water = 2 typeEff Grass Flying = 1 % 2 typeEff Grass Poison = 1 % 2 typeEff Grass Bug = 1 % 2 typeEff Grass Steel = 1 % 2 typeEff Grass Fire = 1 % 2 typeEff Grass Grass = 1 % 2 typeEff Grass Dragon = 1 % 2 typeEff Electric Flying = 2 typeEff Electric Water = 2 typeEff Electric Grass = 1 % 2 typeEff Electric Electric = 1 % 2 typeEff Electric Dragon = 1 % 2 typeEff Electric Ground = 0 typeEff Psychic Fighting = 2 typeEff Psychic Poison = 2 typeEff Psychic Steel = 1 % 2 typeEff Psychic Psychic = 1 % 2 typeEff Psychic Dark = 0 typeEff Ice Flying = 2 typeEff Ice Ground = 2 typeEff Ice Grass = 2 typeEff Ice Dragon = 2 typeEff Ice Steel = 1 % 2 typeEff Ice Fire = 1 % 2 typeEff Ice Water = 1 % 2 typeEff Ice Ice = 1 % 2 typeEff Dragon Dragon = 2 typeEff Dragon Steel = 1 % 2 typeEff Dragon Fairy = 0 typeEff Dark Ghost = 2 typeEff Dark Psychic = 2 typeEff Dark Fighting = 1 % 2 typeEff Dark Dark = 1 % 2 typeEff Dark Fairy = 1 % 2 typeEff Fairy Fighting = 2 typeEff Fairy Dragon = 2 typeEff Fairy Dark = 2 typeEff Fairy Poison = 1 % 2 typeEff Fairy Steel = 1 % 2 typeEff Fairy Fire = 1 % 2 typeEff _ _ = 1