#!/usr/bin/python # # Poketypes allows you to list the types your team has, and prints # how many / which types you have effectiveness, weakness, normal damage, or immunity towards import argparse type_index = ['normal', 'fire', 'water', 'electric', 'grass', 'ice', 'fighting', 'poison', 'ground', 'flying', 'psychic', 'bug', 'rock', 'ghost', 'dragon', 'dark', 'steel'] type_chart =[ [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.5, 0.0, 1.0, 1.0, 0.5], # Normal [1.0, 0.5, 0.5, 1.0, 2.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 0.5, 1.0, 0.5, 1.0, 2.0], # Fire [1.0, 2.0, 0.5, 1.0, 0.5, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 2.0, 1.0, 0.5, 1.0, 1.0], # Water [1.0, 1.0, 2.0, 0.5, 0.5, 1.0, 1.0, 1.0, 0.0, 2.0, 1.0, 1.0, 1.0, 1.0, 0.5, 1.0, 1.0], # Electric [1.0, 0.5, 2.0, 1.0, 0.5, 1.0, 1.0, 0.5, 2.0, 0.5, 1.0, 0.5, 2.0, 1.0, 0.5, 1.0, 0.5], # Grass [1.0, 0.5, 0.5, 1.0, 2.0, 0.5, 1.0, 1.0, 2.0, 2.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 0.5], # Ice [2.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 0.5, 1.0, 0.5, 0.5, 0.5, 2.0, 0.0, 1.0, 2.0, 2.0], # Fighting [1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 0.5, 0.5, 1.0, 1.0, 1.0, 0.5, 0.5, 1.0, 1.0, 0.0], # Poison [1.0, 2.0, 1.0, 2.0, 0.5, 1.0, 1.0, 2.0, 1.0, 0.0, 1.0, 0.5, 2.0, 1.0, 1.0, 1.0, 2.0], # Ground [1.0, 1.0, 1.0, 0.5, 2.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 2.0, 0.5, 1.0, 1.0, 1.0, 0.5], # Flying [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 1.0, 0.5, 1.0, 1.0, 1.0, 1.0, 0.0, 0.5], # Psychic [1.0, 0.5, 1.0, 1.0, 2.0, 1.0, 0.5, 0.5, 1.0, 0.5, 2.0, 1.0, 1.0, 0.5, 1.0, 2.0, 0.5], # Bug [1.0, 2.0, 1.0, 1.0, 1.0, 2.0, 0.5, 1.0, 0.5, 2.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 0.5], # Rock [0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 2.0, 1.0, 0.5, 0.5], # Ghost [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 0.5], # Dragon [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.5, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 2.0, 1.0, 0.5, 0.5], # Dark [1.0, 0.5, 0.5, 0.5, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 0.5], # Steel ] def calculate_attack_values(types): atks = [0.0]*len(type_index) for t in types: t_index = type_index.index(t) for i in range(len(type_index)): value = type_chart[t_index][i] if value > atks[i]: atks[i] = value return atks def calculate_defense_values(types): defs = [2.0]*len(type_index) for t in types: t_index = type_index.index(t) for i in range(len(type_index)): value = type_chart[i][t_index] if value < defs[i]: defs[i] = value return defs def get_types_gt(strengths, value): """ Given a list of strengths, returns a list of all the types that are > value""" ret = [] for i in range(len(strengths)): if strengths[i] > value: ret.append(type_index[i]) return ret def get_types_lt(strengths, value): """ Given a list of strengths, returns a list of all the types that are < value""" ret = [] for i in range(len(strengths)): if strengths[i] < value: ret.append(type_index[i]) return ret def get_types_eq(strengths, value): """ Given a list of strengths, returns a list of all the types that are == value""" ret = [] for i in range(len(strengths)): if strengths[i] == value: ret.append(type_index[i]) return ret def main(): type_list = parse_args().types # These arrays tell us our best values against each type # on attack and on defense atk_strengths = calculate_attack_values(type_list) def_strengths = calculate_defense_values(type_list) atk_list = get_types_gt(atk_strengths, 1.0) print 'These types are super-effective against {} types\n{}\n'.format(len(atk_list), '\n'.join(atk_list)) atk_list = get_types_lt(atk_strengths, 1.0) print 'They cannot be effective against {} types\n{}\n'.format(len(atk_list), '\n'.join(atk_list)) def_list = get_types_eq(def_strengths, 0.0) print 'They are immune to {} types\n{}\n'.format(len(def_list), '\n'.join(def_list)) def_list = list(set(get_types_lt(def_strengths, 1.0)) - set(get_types_eq(def_strengths, 0.0))) print 'They can defend well against {} types\n{}\n'.format(len(def_list), '\n'.join(def_list)) def_list = get_types_gt(def_strengths, 1.0) print 'They have no good defense against {} types\n{}\n'.format(len(def_list), '\n'.join(def_list)) def parse_args(): parser = argparse.ArgumentParser(description='Check your team\'s type strengths and weaknesses', formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('types', nargs=argparse.REMAINDER, help="A list of the types your team is composed of") return parser.parse_args() if __name__ == '__main__': main()