Guest User

Untitled

a guest
Oct 21st, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.75 KB | None | 0 0
  1. import System.Environment
  2. import Data.Char
  3. import Data.Maybe
  4. import Control.Monad
  5. import Data.List
  6.  
  7. data Type = Bug | Dark | Dragon | Electric | Fighting | Fire | Flying | Ghost | Grass | Ground | Ice | Normal | Poison | Psychic | Rock | Steel | Water
  8. deriving (Show, Ord, Eq, Enum, Bounded)
  9.  
  10. data Typeset = Typeset { z :: [Type]
  11. , ie :: [Type]
  12. , se :: [Type]
  13. , n :: [Type]
  14. } deriving (Show, Ord, Eq)
  15.  
  16. newtype Pokemon = Pokemon { t :: [Type] } deriving (Show)
  17.  
  18. mkTypeset a b c = Typeset a b c $ remove allTypes (concat [a, b, c])
  19.  
  20. lookupJust i set = fromJust $ lookup i set
  21.  
  22. allTypes = [minBound..maxBound] :: [Type]
  23.  
  24. remove = flip (filter . (not .) . flip elem)
  25.  
  26. filterMulti :: [a -> Bool] -> [a] -> [a]
  27. filterMulti filters l = concat $ map (\f -> filter f l) filters
  28.  
  29. types :: [(Type, Typeset)]
  30. types = [ (Normal, mkTypeset [Ghost] [] [Fighting])
  31. , (Fighting, mkTypeset [] [Rock, Bug, Dark] [Flying, Psychic])
  32. , (Flying, mkTypeset [Ground] [Fighting, Bug, Grass] [Rock, Electric, Ice])
  33. , (Poison, mkTypeset [] [Fighting, Poison, Bug, Grass] [Ground, Psychic])
  34. , (Ground, mkTypeset [Electric] [Poison, Rock] [Water, Grass, Ice])
  35. , (Rock, mkTypeset [] [Normal, Flying, Poison, Fire] [Fighting, Ground, Steel, Water, Grass])
  36. , (Bug, mkTypeset [] [Fighting, Ground, Grass] [Flying, Rock, Fire])
  37. , (Ghost, mkTypeset [Normal, Fighting] [Poison, Bug] [Ghost, Dark])
  38. , (Steel, mkTypeset [Poison] [Normal, Flying, Rock, Bug, Ghost, Steel, Grass, Psychic, Ice, Dragon, Dark] [Fighting, Ground, Fire])
  39. , (Fire, mkTypeset [] [Bug, Steel, Fire, Grass, Ice] [Ground, Rock, Water])
  40. , (Water, mkTypeset [] [Steel, Fire, Water, Ice] [Grass, Electric])
  41. , (Grass, mkTypeset [] [Ground, Water, Grass, Electric] [Flying, Poison, Bug, Fire, Ice])
  42. , (Electric, mkTypeset [] [Flying, Steel, Electric] [Ground])
  43. , (Psychic, mkTypeset [] [Fighting, Psychic] [Bug, Ghost, Dark])
  44. , (Ice, mkTypeset [] [Ice] [Fighting, Rock, Steel, Fire])
  45. , (Dragon, mkTypeset [] [Fire, Water, Grass, Electric] [Ice, Dragon])
  46. , (Dark, mkTypeset [Psychic] [Ghost, Dark] [Fighting, Bug])
  47. ]
  48.  
  49. pokemon :: [(String, Pokemon)]
  50. pokemon = [ ("treecko", Pokemon [Grass])
  51. , ("grovyle", Pokemon [Grass])
  52. , ("sceptile", Pokemon [Grass])
  53. , ("torchic", Pokemon [Fire])
  54. , ("combusken", Pokemon [Fire, Fighting])
  55. , ("blaziken", Pokemon [Fire, Fighting])
  56. , ("mudkip", Pokemon [Water])
  57. , ("marshtomp", Pokemon [Water, Ground])
  58. , ("swampert", Pokemon [Water, Ground])
  59. , ("poochyena", Pokemon [Dark])
  60. , ("mightyena", Pokemon [Dark])
  61. , ("zigzagoon", Pokemon [Normal])
  62. , ("linoone", Pokemon [Normal])
  63. , ("wurmple", Pokemon [Bug])
  64. , ("silcoon", Pokemon [Bug])
  65. , ("beautifly", Pokemon [Bug, Flying])
  66. , ("cascoon", Pokemon [Bug])
  67. , ("dustox", Pokemon [Bug, Poison])
  68. , ("lotad", Pokemon [Water, Grass])
  69. , ("lombre", Pokemon [Water, Grass])
  70. , ("ludicolo", Pokemon [Water, Grass])
  71. , ("seedot", Pokemon [Grass])
  72. , ("nuzleaf", Pokemon [Grass, Dark])
  73. , ("shiftry", Pokemon [Grass, Dark])
  74. , ("taillow", Pokemon [Normal, Flying])
  75. , ("swellow", Pokemon [Normal, Flying])
  76. , ("wingull", Pokemon [Water, Flying])
  77. , ("pelipper", Pokemon [Water, Flying])
  78. , ("ralts", Pokemon [Psychic])
  79. , ("kirlia", Pokemon [Psychic])
  80. , ("gardevoir", Pokemon [Psychic])
  81. , ("surskit", Pokemon [Bug, Water])
  82. , ("masquerain", Pokemon [Bug, Flying])
  83. , ("shroomish", Pokemon [Grass])
  84. , ("breloom", Pokemon [Grass, Fighting])
  85. , ("slakoth", Pokemon [Normal])
  86. , ("vigoroth", Pokemon [Normal])
  87. , ("slaking", Pokemon [Normal])
  88. , ("nincada", Pokemon [Bug, Ground])
  89. , ("ninjask", Pokemon [Bug, Flying])
  90. , ("shedinja", Pokemon [Bug, Ghost])
  91. , ("whismur", Pokemon [Normal])
  92. , ("loudred", Pokemon [Normal])
  93. , ("exploud", Pokemon [Normal])
  94. , ("makuhita", Pokemon [Fighting])
  95. , ("hariyama", Pokemon [Fighting])
  96. , ("azurill", Pokemon [Water])
  97. , ("nosepass", Pokemon [Rock])
  98. , ("skitty", Pokemon [Normal])
  99. , ("delcatty", Pokemon [Normal])
  100. , ("sableye", Pokemon [Dark, Ghost])
  101. , ("mawile", Pokemon [Steel])
  102. , ("aron", Pokemon [Rock, Steel])
  103. , ("lairon", Pokemon [Rock, Steel])
  104. , ("aggron", Pokemon [Rock, Steel])
  105. , ("meditite", Pokemon [Fighting, Psychic])
  106. , ("medicham", Pokemon [Fighting, Psychic])
  107. , ("electrike", Pokemon [Electric])
  108. , ("manectric", Pokemon [Electric])
  109. , ("plusle", Pokemon [Electric])
  110. , ("minun", Pokemon [Electric])
  111. , ("volbeat", Pokemon [Bug])
  112. , ("illumise", Pokemon [Bug])
  113. , ("roselia", Pokemon [Grass, Poison])
  114. , ("gulpin", Pokemon [Poison])
  115. , ("swalot", Pokemon [Poison])
  116. , ("carvanha", Pokemon [Water, Dark])
  117. , ("sharpedo", Pokemon [Water, Dark])
  118. , ("wailmer", Pokemon [Water])
  119. , ("wailord", Pokemon [Water])
  120. , ("numel", Pokemon [Fire, Ground])
  121. , ("camerupt", Pokemon [Fire, Ground])
  122. , ("torkoal", Pokemon [Fire])
  123. , ("spoink", Pokemon [Psychic])
  124. , ("grumpig", Pokemon [Psychic])
  125. , ("spinda", Pokemon [Normal])
  126. , ("trapinch", Pokemon [Ground])
  127. , ("vibrava", Pokemon [Ground, Dragon])
  128. , ("flygon", Pokemon [Ground, Dragon])
  129. , ("cacnea", Pokemon [Grass])
  130. , ("cacturne", Pokemon [Grass, Dark])
  131. , ("swablu", Pokemon [Normal, Flying])
  132. , ("altaria", Pokemon [Dragon, Flying])
  133. , ("zangoose", Pokemon [Normal])
  134. , ("seviper", Pokemon [Poison])
  135. , ("lunatone", Pokemon [Rock, Psychic])
  136. , ("solrock", Pokemon [Rock, Psychic])
  137. , ("barboach", Pokemon [Water, Ground])
  138. , ("whiscash", Pokemon [Water, Ground])
  139. , ("corphish", Pokemon [Water])
  140. , ("crawdaunt", Pokemon [Water, Dark])
  141. , ("baltoy", Pokemon [Ground, Psychic])
  142. , ("claydol", Pokemon [Ground, Psychic])
  143. , ("lileep", Pokemon [Rock, Grass])
  144. , ("cradily", Pokemon [Rock, Grass])
  145. , ("anorith", Pokemon [Rock, Bug])
  146. , ("armaldo", Pokemon [Rock, Bug])
  147. , ("feebas", Pokemon [Water])
  148. , ("milotic", Pokemon [Water])
  149. , ("castform", Pokemon [Normal])
  150. , ("kecleon", Pokemon [Normal])
  151. , ("shuppet", Pokemon [Ghost])
  152. , ("banette", Pokemon [Ghost])
  153. , ("duskull", Pokemon [Ghost])
  154. , ("dusclops", Pokemon [Ghost])
  155. , ("tropius", Pokemon [Flying, Grass])
  156. , ("chimecho", Pokemon [Psychic])
  157. , ("absol", Pokemon [Dark])
  158. , ("wynaut", Pokemon [Psychic])
  159. , ("snorunt", Pokemon [Ice])
  160. , ("glalie", Pokemon [Ice])
  161. , ("spheal", Pokemon [Ice, Water])
  162. , ("sealeo", Pokemon [Ice, Water])
  163. , ("walrein", Pokemon [Ice, Water])
  164. , ("clamperl", Pokemon [Water])
  165. , ("huntail", Pokemon [Water])
  166. , ("gorebyss", Pokemon [Water])
  167. , ("relicanth", Pokemon [Water, Rock])
  168. , ("luvdisc", Pokemon [Water])
  169. , ("bagon", Pokemon [Dragon])
  170. , ("shelgon", Pokemon [Dragon])
  171. , ("salamence", Pokemon [Dragon, Flying])
  172. , ("beldum", Pokemon [Steel, Psychic])
  173. , ("metang", Pokemon [Steel, Psychic])
  174. , ("metagross", Pokemon [Steel, Psychic])
  175. , ("regirock", Pokemon [Rock])
  176. , ("regice", Pokemon [Ice])
  177. , ("registeel", Pokemon [Steel])
  178. , ("latias", Pokemon [Dragon, Psychic])
  179. , ("latios", Pokemon [Dragon, Psychic])
  180. , ("kyogre", Pokemon [Water])
  181. , ("groudon", Pokemon [Ground])
  182. , ("rayquaza", Pokemon [Dragon, Flying])
  183. , ("jirachi", Pokemon [Steel, Psychic])
  184. , ("deoxys", Pokemon [Psychic])]
  185.  
  186. -- 0x 0.25x 0.5x 1x 2x 4x
  187. effective :: Pokemon -> ([Type], [Type], [Type], [Type], [Type], [Type])
  188. effective pok = case pok of
  189. Pokemon [t] -> (immune, [], nve, n, se, [])
  190. where
  191. Typeset immune nve se n = lookupJust t types
  192. Pokemon [t1,t2] -> (union immune1 immune2,
  193. intersect nve1 nve2,
  194. concat [intersect nve1 n2, intersect nve2 n1],
  195. concat [intersect n1 n2, intersect se1 nve2, intersect se2 nve1],
  196. concat [intersect se1 n2, intersect se2 n1],
  197. intersect se1 se2)
  198. where
  199. Typeset immune1 nve1 se1 n1 = lookupJust t1 types
  200. Typeset immune2 nve2 se2 n2 = lookupJust t2 types
  201.  
  202. printTypes :: ([Type], [Type], [Type], [Type], [Type], [Type]) -> IO ()
  203. printTypes (zero, dot25, dot5, one, two, four) = do
  204. put gray zero
  205. put boldred dot25
  206. put red dot5
  207. put id one
  208. put green two
  209. put boldgreen four
  210. where
  211. put f ts = unless (null ts) $ putStrLn $ intercalate ", " $ map (f . map (toLower) . show) ts
  212. color d s = "\27[" ++ d ++ "m" ++ s ++ "\27[0m"
  213. gray = color "30"
  214. red = color "31"
  215. boldred = color "31;1"
  216. green = color "32"
  217. boldgreen = color "32;1"
  218.  
  219. main = do
  220. args <- getArgs
  221. case args of
  222. [] -> putStrLn "Usage: pokeman [pokemon name]"
  223. (p:_) -> case lookup (map toLower p) pokemon of
  224. Just pok -> printTypes $ effective pok
  225. Nothing -> putStrLn $ "Unknown pokemon " ++ show (map toLower p)
Add Comment
Please, Sign In to add comment