Skip to content

Instantly share code, notes, and snippets.

@kabirahuja2431
Last active June 4, 2019 09:48
Show Gist options
  • Save kabirahuja2431/a7f7584ed5cb25287205f5da39feee2d to your computer and use it in GitHub Desktop.
Save kabirahuja2431/a7f7584ed5cb25287205f5da39feee2d to your computer and use it in GitHub Desktop.
'''
A simple python script to figure out which 4 types of attacks will be
super effective to maximum types of pokemons.
Inorder to run this script you will need:
- numpy
- pandas
- pokemon chart available here: https://github.com/zonination/pokemon-chart
Clone the pokemon chart repo and keep it in the current working directory
'''
import numpy as np
import pandas as pd
import copy
class TypesFinder(object):
def __init__(self, types, super_effectives):
self.types = types
self.super_effectives = super_effectives
self.best_set = []
self.best_ses = []
self.max_ses = -1
def find(self, depth, types, attack_set, sup_efs):
if depth == 4:
if len(sup_efs) > self.max_ses:
self.best_set = [sorted(attack_set)]
self.best_ses = [sorted(sup_efs)]
self.max_ses = len(sup_efs)
if len(sup_efs) == self.max_ses:
if sorted(attack_set) not in self.best_set:
self.best_set.append(sorted(attack_set))
self.best_ses.append(sorted(sup_efs))
return
for i,typ in enumerate(types):
new_attack_set = copy.copy(attack_set)
new_sup_efs = copy.copy(sup_efs)
new_attack_set.append(typ)
new_sup_efs += self.super_effectives[typ]
new_sup_efs = list(set(new_sup_efs))
if i < len(types)-1:
self.find(depth+1, types[:i]+types[i+1:],new_attack_set, new_sup_efs)
else:
self.find(depth+1, types[:i], new_attack_set, new_sup_efs)
def __call__(self):
attack_set = []
sup_efs = []
self.find(0,self.types, attack_set, sup_efs)
return self.best_set, self.best_ses
if __name__ == "__main__":
df = pd.read_csv('pokemon-chart/chart.csv')
print(df.head())
super_effectives = {}
for i in range(len(df)):
attack_dict = dict(df.loc[i])
typ = attack_dict['Attacking']
super_effectives[typ] = []
for key, value in attack_dict.items():
if key == 'Attacking':
continue
if value == 2.0:
super_effectives[typ].append(key)
print(super_effectives)
types = list(super_effectives.keys())
tp_finder = TypesFinder(types, super_effectives)
best_set, best_ses = tp_finder()
print("Best Attacks set: \n",best_set)
print("Super effective agains: \n",best_ses)
@kabirahuja2431
Copy link
Author

A script to find the best set of attacks a pokemon can have in order to be super effective against maximum types of pokemon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment