def best_move(self, active, types, target): movesinfo = self.pick_move(active) print movesinfo try: movelist = [x.get('id') for x in movesinfo] except Exception as e: print e movelist = movesinfo print movelist scores = [battleutils.calculate_move_score(active, types, target, x) for x in movelist] best_score = max(scores) best_move = movelist[scores.index(best_score)] if best_score >= 120: print 'Best score is %s - score %s' % (best_move, best_score) return '/move ' + best_move else: b_switch = self.best_switch(active, self.sidedata, target) if b_switch != '/switch 1': b_mon_switch_id = b_switch.split('/switch ')[1] b_mon_switch = self.sidedata.get('pokemon')[int(b_mon_switch_id) - 1] b_mon_species = b_mon_switch.get('details').split(', ')[0] print 'Score not good enough. switching to %s' % b_mon_species return b_switch else: print 'No good other options. using %s' % best_move return '/move ' + best_move
def best_switch(self, active, sidedata, target): print 'call to switch' highest_score = 0 alive_mon_indexes = self.pick_alive_mons(sidedata) side_mon_info = sidedata.get('pokemon') # Loops through all mons, finds which has the highest score, and switches print alive_mon_indexes best_mon_index = alive_mon_indexes[0] for i in alive_mon_indexes: mon = side_mon_info[i - 1] mon_info = mon.get('details').split(', ') mon_species = utils.condense(mon_info[0]) mon_level = mon_info[1][1:] try: mon_types = battleutils.POKEDEX.get(mon_species).get('types') except Exception as e: print e mon_types = ['Normal'] movelist = mon.get('moves') scores = [battleutils.calculate_move_score(active, mon_types, target, x) for x in movelist] print movelist print scores best_score = max(scores) if best_score > highest_score: print 'best score %s is higher than highest score %s!' % (best_score, highest_score) highest_score = best_score best_move = movelist[scores.index(best_score)] print 'best move is %s!' % best_move best_mon = mon_species best_mon_index = i result = '/switch ' + str(best_mon_index) print result return result