fork download
  1. import Control.Monad
  2. import Data.Ratio
  3. import Data.List
  4.  
  5. data Type
  6. = Normal
  7. | Fighting
  8. | Flying
  9. | Poison
  10. | Ground
  11. | Rock
  12. | Bug
  13. | Ghost
  14. | Steel
  15. | Fire
  16. | Water
  17. | Grass
  18. | Electric
  19. | Psychic
  20. | Ice
  21. | Dragon
  22. | Dark
  23. | Fairy
  24. deriving (Enum, Show, Eq, Ord)
  25.  
  26. everyType :: [Type]
  27. everyType = enumFrom Normal
  28.  
  29. everyTypeCombo :: [[Type]]
  30. everyTypeCombo = filter (not . null) rawPairs
  31. where
  32. rawPairs = liftM2 makePair everyType everyType
  33. makePair t1 t2
  34. | t1 == t2 = [t1]
  35. | t1 < t2 = [t1, t2]
  36. | otherwise = []
  37.  
  38. weightTypes :: [[Type]] -> [(Float, [Type])]
  39. weightTypes ts = map (\ts -> (typeDefRank ts, ts)) ts
  40.  
  41. bestTypes :: [(Float, [Type])]
  42. bestTypes = sortBy (\a b -> fst b `compare` fst a) $ weightTypes everyTypeCombo
  43.  
  44. multiTypeEff :: Type -> [Type] -> Rational
  45. multiTypeEff attack defendList =
  46. foldr effMul 1 defendList
  47. where effMul ty r = typeEff attack ty * r
  48.  
  49. typeDefRank :: [Type] -> Float
  50. typeDefRank ts =
  51. rankList everyType
  52. where
  53. rankList ots =
  54. sum $ map (\t -> typeEffRank (multiTypeEff t ts) * offensiveTypeRank t) ots
  55.  
  56. main :: IO ()
  57. main = mapM_ print bestTypes
  58.  
  59. -- This determines how resistances and weaknesses are weighted.
  60. typeEffRank :: Rational -> Float
  61. typeEffRank r
  62. | r == 0 = 3.3
  63. | r == 1 = 0.0
  64. | r < 1 = 0.7 / fromRational r
  65. | r > 1 = negate ((fromRational r + 1.0) ^^ 2) / 16.0
  66.  
  67. -- Weighting of attacking types. Use this to specify what you're
  68. -- defending from.
  69. offensiveTypeRank :: Type -> Float
  70. offensiveTypeRank Normal = 40.0
  71. offensiveTypeRank Fighting = 30.0
  72. offensiveTypeRank Flying = 80.0
  73. offensiveTypeRank Poison = 0.0
  74. offensiveTypeRank Ground = 20.0
  75. offensiveTypeRank Rock = 0.0
  76. offensiveTypeRank Bug = 10.0
  77. offensiveTypeRank Ghost = 0.0
  78. offensiveTypeRank Steel = 0.0
  79. offensiveTypeRank Fire = 40.0
  80. offensiveTypeRank Water = 0.0
  81. offensiveTypeRank Grass = 0.0
  82. offensiveTypeRank Electric = 0.0
  83. offensiveTypeRank Psychic = 0.0
  84. offensiveTypeRank Ice = 0.0
  85. offensiveTypeRank Dragon = 0.0
  86. offensiveTypeRank Dark = 0.0
  87. offensiveTypeRank Fairy = 0.0
  88.  
  89. typeEff :: Type -> Type -> Rational
  90. typeEff Normal Rock = 1 % 2
  91. typeEff Normal Steel = 1 % 2
  92. typeEff Normal Ghost = 0
  93. typeEff Fighting Normal = 2
  94. typeEff Fighting Rock = 2
  95. typeEff Fighting Steel = 2
  96. typeEff Fighting Ice = 2
  97. typeEff Fighting Dark = 2
  98. typeEff Fighting Flying = 1 % 2
  99. typeEff Fighting Poison = 1 % 2
  100. typeEff Fighting Bug = 1 % 2
  101. typeEff Fighting Psychic = 1 % 2
  102. typeEff Fighting Fairy = 1 % 2
  103. typeEff Fighting Ghost = 0
  104. typeEff Flying Fighting = 2
  105. typeEff Flying Bug = 2
  106. typeEff Flying Grass = 2
  107. typeEff Flying Rock = 1 % 2
  108. typeEff Flying Steel = 1 % 2
  109. typeEff Flying Electric = 1 % 2
  110. typeEff Poison Grass = 2
  111. typeEff Poison Fairy = 2
  112. typeEff Poison Poison = 1 % 2
  113. typeEff Poison Ground = 1 % 2
  114. typeEff Poison Rock = 1 % 2
  115. typeEff Poison Ghost = 1 % 2
  116. typeEff Poison Steel = 0
  117. typeEff Ground Poison = 2
  118. typeEff Ground Rock = 2
  119. typeEff Ground Steel = 2
  120. typeEff Ground Fire = 2
  121. typeEff Ground Electric = 2
  122. typeEff Ground Bug = 1 % 2
  123. typeEff Ground Grass = 1 % 2
  124. typeEff Ground Flying = 0
  125. typeEff Rock Flying = 2
  126. typeEff Rock Bug = 2
  127. typeEff Rock Fire = 2
  128. typeEff Rock Ice = 2
  129. typeEff Rock Fighting = 1 % 2
  130. typeEff Rock Ground = 1 % 2
  131. typeEff Rock Steel = 1 % 2
  132. typeEff Bug Grass = 2
  133. typeEff Bug Psychic = 2
  134. typeEff Bug Dark = 2
  135. typeEff Bug Fighting = 1 % 2
  136. typeEff Bug Flying = 1 % 2
  137. typeEff Bug Poison = 1 % 2
  138. typeEff Bug Ghost = 1 % 2
  139. typeEff Bug Steel = 1 % 2
  140. typeEff Bug Fire = 1 % 2
  141. typeEff Bug Fairy = 1 % 2
  142. typeEff Ghost Ghost = 2
  143. typeEff Ghost Psychic = 2
  144. typeEff Ghost Dark = 1 % 2
  145. typeEff Ghost Normal = 0
  146. typeEff Steel Rock = 2
  147. typeEff Steel Ice = 2
  148. typeEff Steel Fairy = 2
  149. typeEff Steel Steel = 1 % 2
  150. typeEff Steel Fire = 1 % 2
  151. typeEff Steel Water = 1 % 2
  152. typeEff Steel Electric = 1 % 2
  153. typeEff Fire Bug = 2
  154. typeEff Fire Steel = 2
  155. typeEff Fire Grass = 2
  156. typeEff Fire Ice = 2
  157. typeEff Fire Rock = 1 % 2
  158. typeEff Fire Fire = 1 % 2
  159. typeEff Fire Water = 1 % 2
  160. typeEff Fire Dragon = 1 % 2
  161. typeEff Water Ground = 2
  162. typeEff Water Rock = 2
  163. typeEff Water Fire = 2
  164. typeEff Water Water = 1 % 2
  165. typeEff Water Grass = 1 % 2
  166. typeEff Water Dragon = 1 % 2
  167. typeEff Grass Ground = 2
  168. typeEff Grass Rock = 2
  169. typeEff Grass Water = 2
  170. typeEff Grass Flying = 1 % 2
  171. typeEff Grass Poison = 1 % 2
  172. typeEff Grass Bug = 1 % 2
  173. typeEff Grass Steel = 1 % 2
  174. typeEff Grass Fire = 1 % 2
  175. typeEff Grass Grass = 1 % 2
  176. typeEff Grass Dragon = 1 % 2
  177. typeEff Electric Flying = 2
  178. typeEff Electric Water = 2
  179. typeEff Electric Grass = 1 % 2
  180. typeEff Electric Electric = 1 % 2
  181. typeEff Electric Dragon = 1 % 2
  182. typeEff Electric Ground = 0
  183. typeEff Psychic Fighting = 2
  184. typeEff Psychic Poison = 2
  185. typeEff Psychic Steel = 1 % 2
  186. typeEff Psychic Psychic = 1 % 2
  187. typeEff Psychic Dark = 0
  188. typeEff Ice Flying = 2
  189. typeEff Ice Ground = 2
  190. typeEff Ice Grass = 2
  191. typeEff Ice Dragon = 2
  192. typeEff Ice Steel = 1 % 2
  193. typeEff Ice Fire = 1 % 2
  194. typeEff Ice Water = 1 % 2
  195. typeEff Ice Ice = 1 % 2
  196. typeEff Dragon Dragon = 2
  197. typeEff Dragon Steel = 1 % 2
  198. typeEff Dragon Fairy = 0
  199. typeEff Dark Ghost = 2
  200. typeEff Dark Psychic = 2
  201. typeEff Dark Fighting = 1 % 2
  202. typeEff Dark Dark = 1 % 2
  203. typeEff Dark Fairy = 1 % 2
  204. typeEff Fairy Fighting = 2
  205. typeEff Fairy Dragon = 2
  206. typeEff Fairy Dark = 2
  207. typeEff Fairy Poison = 1 % 2
  208. typeEff Fairy Steel = 1 % 2
  209. typeEff Fairy Fire = 1 % 2
  210. typeEff _ _ = 1
  211.  
  212.  
  213.  
Success #stdin #stdout 0s 6332KB
stdin
Standard input is empty
stdout
(401.75,[Rock,Ghost])
(345.75,[Ghost,Electric])
(337.25,[Ghost,Steel])
(325.0,[Flying,Ghost])
(304.0,[Flying,Rock])
(303.75,[Ghost,Fire])
(301.0,[Ghost,Water])
(301.0,[Ghost,Dragon])
(287.875,[Rock,Electric])
(271.875,[Rock,Steel])
(259.0,[Ghost,Fairy])
(251.875,[Rock,Water])
(251.875,[Rock,Dragon])
(247.75,[Poison,Ghost])
(245.875,[Rock,Fire])
(245.0,[Normal,Ghost])
(245.0,[Ground,Ghost])
(245.0,[Ghost])
(239.5,[Flying,Steel])
(234.0,[Flying,Electric])
(231.0,[Ghost,Psychic])
(231.0,[Ghost,Dark])
(226.75,[Rock,Fairy])
(223.375,[Steel,Electric])
(222.5,[Ghost,Ice])
(214.0,[Fighting,Ghost])
(207.125,[Rock,Psychic])
(206.75,[Poison,Rock])
(205.5,[Bug,Ghost])
(195.875,[Ground,Rock])
(195.875,[Rock])
(192.0,[Flying,Fire])
(191.5,[Ghost,Grass])
(178.0,[Flying,Poison])
(178.0,[Flying,Water])
(178.0,[Flying,Dragon])
(178.0,[Flying,Fairy])
(165.875,[Normal,Rock])
(162.25,[Steel,Fairy])
(160.25,[Rock,Dark])
(156.75,[Water,Electric])
(156.75,[Electric,Dragon])
(156.75,[Electric,Fairy])
(153.875,[Steel,Water])
(153.875,[Steel,Dragon])
(150.75,[Fire,Electric])
(150.0,[Flying,Psychic])
(147.875,[Steel,Fire])
(142.25,[Poison,Steel])
(137.125,[Electric,Psychic])
(136.75,[Poison,Electric])
(134.25,[Steel,Psychic])
(131.375,[Ground,Steel])
(131.375,[Steel])
(122.0,[Flying])
(122.0,[Flying,Ground])
(114.75,[Fire,Water])
(114.75,[Fire,Dragon])
(114.75,[Fire,Fairy])
(112.0,[Water,Dragon])
(112.0,[Water,Fairy])
(112.0,[Dragon,Fairy])
(109.875,[Rock,Ice])
(101.375,[Normal,Steel])
(100.75,[Poison,Water])
(100.75,[Poison,Dragon])
(100.75,[Poison,Fairy])
(100.75,[Ground,Electric])
(100.75,[Electric])
(97.875,[Fighting,Rock])
(96.5,[Flying,Bug])
(94.75,[Poison,Fire])
(92.375,[Water,Psychic])
(92.375,[Psychic,Dragon])
(91.0,[Fighting,Flying])
(87.375,[Steel,Dark])
(86.75,[Fire,Psychic])
(84.0,[Psychic,Fairy])
(83.875,[Normal,Electric])
(80.0,[Normal,Flying])
(78.25,[Electric,Dark])
(72.75,[Poison,Psychic])
(66.0,[Flying,Dark])
(61.375,[Steel,Ice])
(61.375,[Electric,Ice])
(58.75,[Ground,Fire])
(58.75,[Fire])
(58.5,[Bug,Fairy])
(57.5,[Flying,Ice])
(56.0,[Ground,Water])
(56.0,[Ground,Dragon])
(56.0,[Ground,Fairy])
(56.0,[Rock,Bug])
(56.0,[Water])
(56.0,[Dragon])
(56.0,[Fairy])
(44.75,[Poison])
(44.75,[Poison,Ground])
(41.875,[Normal,Fire])
(40.5,[Flying,Grass])
(39.125,[Normal,Water])
(39.125,[Normal,Dragon])
(38.875,[Bug,Psychic])
(36.375,[Ground,Psychic])
(36.375,[Psychic])
(33.5,[Rock,Grass])
(33.5,[Water,Dark])
(33.5,[Dragon,Dark])
(33.375,[Fighting,Steel])
(30.5,[Poison,Bug])
(27.875,[Fire,Dark])
(27.75,[Fighting,Fire])
(25.0,[Fighting,Water])
(25.0,[Fighting,Dragon])
(25.0,[Fighting,Fairy])
(25.0,[Bug,Water])
(25.0,[Bug,Dragon])
(19.5,[Bug,Electric])
(14.0,[Normal,Fairy])
(13.75,[Fighting,Poison])
(11.0,[Bug,Fire])
(7.5,[Bug,Steel])
(2.75,[Normal,Poison])
(2.75,[Fighting,Electric])
(2.5,[Ground,Bug])
(2.5,[Bug])
(2.5,[Grass,Fairy])
(0.0,[Ground])
(0.0,[Dark,Fairy])
(-3.0,[Fighting,Psychic])
(-5.625,[Normal,Psychic])
(-8.5,[Ice,Fairy])
(-11.25,[Poison,Dark])
(-13.125,[Grass,Psychic])
(-14.125,[Fire,Ice])
(-15.625,[Psychic,Dark])
(-16.875,[Normal])
(-16.875,[Normal,Ground])
(-16.875,[Water,Ice])
(-16.875,[Ice,Dragon])
(-19.75,[Poison,Ice])
(-22.5,[Ground,Dark])
(-22.5,[Dark])
(-22.625,[Water,Grass])
(-22.625,[Grass,Dragon])
(-23.375,[Steel,Grass])
(-25.5,[Poison,Grass])
(-28.125,[Grass,Electric])
(-28.125,[Psychic,Ice])
(-31.0,[Fighting])
(-31.0,[Fighting,Ground])
(-39.375,[Ground,Ice])
(-39.375,[Ice])
(-39.5,[Normal,Bug])
(-45.0,[Fire,Grass])
(-45.125,[Ground,Grass])
(-45.125,[Bug,Dark])
(-45.125,[Grass])
(-47.875,[Normal,Fighting])
(-52.5,[Normal,Dark])
(-61.875,[Fighting,Dark])
(-62.0,[Normal,Grass])
(-63.5,[Fighting,Bug])
(-69.375,[Normal,Ice])
(-70.375,[Fighting,Ice])
(-72.0,[Grass,Dark])
(-75.0,[Ice,Dark])
(-79.5,[Bug,Ice])
(-95.125,[Bug,Grass])
(-102.0,[Grass,Ice])
(-119.5,[Fighting,Grass])