Advertisement
Guest User

101d

a guest
Oct 2nd, 2012
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.75 KB | None | 0 0
  1. #!/usr/bin/python3.2
  2.  
  3. import re
  4. import urllib.request
  5.  
  6. def getPokemans():
  7.     url = 'http://bulbapedia.bulbagarden.net/w/index.php?title=List_of_Pok%C3%A9mon_by_type&action=edit'
  8.     data = urllib.request.urlopen(url).read().decode('utf8')
  9.     data = data[data.find('>', data.find('textarea')) + 1:data.find('</textarea>')]
  10.     data = [i[:i.find('}')].split('|') for i in data.split('{{Abilityentry1|')][1:]
  11.  
  12.     names = [i[1] for i in data]
  13.     types = [i[3:] for i in data]
  14.     pokemans = dict(zip(names,types))
  15.     print('Got pokemon types...')
  16.     return pokemans
  17.  
  18. def getMoves():
  19.     url = 'http://bulbapedia.bulbagarden.net/w/index.php?title=List_of_moves&action=edit'
  20.     data = urllib.request.urlopen(url).read().decode('utf8')
  21.     data = data[data.find('>', data.find('textarea')) + 1:data.find('</textarea>')]
  22.  
  23.     names = [i[1:i.find('}')] for i in re.split('{{m', data)][1:]
  24.     types = [i[1:i.find('}')] for i in re.split('{{typetable', data)][1:]
  25.  
  26.     moves = dict(zip(names, types))
  27.     print('Got move list...')
  28.     return moves
  29.  
  30. def getModifiers():
  31.     indexes = 'Normal', 'Fighting', 'Flying', 'Poison', 'Ground', 'Rock', 'Bug', 'Ghost', 'Steel', 'Fire', 'Water', 'Grass', 'Electric', 'Psychic', 'Ice', 'Dragon', 'Dark'
  32.     copypasta = [line.split(' ') for line in
  33.     '''1×   1×  1×  1×  1×  ½×  1×  0×  ½×  1×  1×  1×  1×  1×  1×  1×  1×
  34.    2×  1×  ½×  ½×  1×  2×  ½×  0×  2×  1×  1×  1×  1×  ½×  2×  1×  2×
  35.    1×  2×  1×  1×  1×  ½×  2×  1×  ½×  1×  1×  2×  ½×  1×  1×  1×  1×
  36.    1×  1×  1×  ½×  ½×  ½×  1×  ½×  0×  1×  1×  2×  1×  1×  1×  1×  1×
  37.    1×  1×  0×  2×  1×  2×  ½×  1×  2×  2×  1×  ½×  2×  1×  1×  1×  1×
  38.    1×  ½×  2×  1×  ½×  1×  2×  1×  ½×  2×  1×  1×  1×  1×  2×  1×  1×
  39.    1×  ½×  ½×  ½×  1×  1×  1×  ½×  ½×  ½×  1×  2×  1×  2×  1×  1×  2×
  40.    0×  1×  1×  1×  1×  1×  1×  2×  ½×  1×  1×  1×  1×  2×  1×  1×  ½×
  41.    1×  1×  1×  1×  1×  2×  1×  1×  ½×  ½×  ½×  1×  ½×  1×  2×  1×  1×
  42.    1×  1×  1×  1×  1×  ½×  2×  1×  2×  ½×  ½×  2×  1×  1×  2×  ½×  1×
  43.    1×  1×  1×  1×  2×  2×  1×  1×  1×  2×  ½×  ½×  1×  1×  1×  ½×  1×
  44.    1×  1×  ½×  ½×  2×  2×  ½×  1×  ½×  ½×  2×  ½×  1×  1×  1×  ½×  1×
  45.    1×  1×  2×  1×  0×  1×  1×  1×  1×  1×  2×  ½×  ½×  1×  1×  ½×  1×
  46.    1×  2×  1×  2×  1×  1×  1×  1×  ½×  1×  1×  1×  1×  ½×  1×  1×  0×
  47.    1×  1×  2×  1×  2×  1×  1×  1×  ½×  ½×  ½×  2×  1×  1×  ½×  2×  1×
  48.    1×  1×  1×  1×  1×  1×  1×  1×  ½×  1×  1×  1×  1×  1×  1×  2×  1×
  49.    1×  ½×  1×  1×  1×  1×  1×  2×  ½×  1×  1×  1×  1×  2×  1×  1×  ½×'''.replace('×','').replace('½', '0.5').splitlines()]
  50.     copypasta = [[float(i) for i in line if i!=''] for line in copypasta]
  51.     modifiers = dict(zip(indexes, copypasta))
  52.     for k in modifiers:
  53.         modifiers[k] = dict(zip(indexes, modifiers[k]))
  54.  
  55.     return modifiers
  56.  
  57. if __name__=='__main__':
  58.     modifiers = getModifiers()
  59.     moves = getMoves()
  60.     pokemans = getPokemans()
  61.     while True:
  62.         x = input().split(' -> ')
  63.         if x == '': break
  64.         try:
  65.             move = moves[x[0]]
  66.             def_type = pokemans[x[1]]
  67.  
  68.             result = 1
  69.             for t in def_type:
  70.                 result *= modifiers[move][t]
  71.  
  72.             if result == 0: print('It has no effect')
  73.             elif result < 1: print('Not very effective...')
  74.             elif result == 1: print('It hit!')
  75.             elif result > 1: print("It's super effective!")
  76.         except:
  77.             print('Entry not found.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement