def extract_atk(self, game_state): ''' Returns booleans for all attack type effectiveness features ''' p2 = game_state.getp2_in_play() p1 = game_state.getp1_in_play() p2_index = game_state.getp2_pokemon_names().index(p2) p1_index = game_state.getp1_pokemon_names().index(p1) p1_type = game_state.getp1_pokemon_types()[p1_index] p2_type = game_state.getp2_pokemon_types()[p2_index] STAB1 = 1 STAB2 = 1 type_atk1 = 0 power_atk1 = 0 type_atk2 = 0 power_atk2 = 0 if game_state.getp1_action() != "switch" and game_state.getp1_action() != "None": move1 = Pokedex.getMove(game_state.getp1_action()) if move1['type'] in p1_type: STAB1 = 1.5 elif game_state.getp1_action() == "None": if p1 in game_state.getp1_pokemon_moves().keys(): moves = game_state.getp1_pokemon_moves()[p1] move1 = moves[numpy.random.choice(range(len(moves)))] move1 = Pokedex.getMove(move1) else: moves = Pokedex.getLegalMoves(p1) move1 = moves[numpy.random.choice(range(len(moves)))]['name'] move1 = Pokedex.getMove(move1) else: move1 = None if game_state.getp2_action() != "switch" and game_state.getp2_action() != "None": move2 = Pokedex.getMove(game_state.getp2_action()) if move2['type'] in p2_type: STAB2 = 1.5 elif game_state.getp2_action() == "None": if p2 in game_state.getp2_pokemon_moves().keys(): moves = game_state.getp2_pokemon_moves()[p2] move2 = moves[numpy.random.choice(range(len(moves)))] move2 = Pokedex.getMove(move2) else: moves = Pokedex.getLegalMoves(p2) move2 = moves[numpy.random.choice(range(len(moves)))]['name'] move2 = Pokedex.getMove(move2) else: move2 = None #TODO: REMOVE TYPE EFFECTIVENESS ON STATUS MOVES if move1 != None: type_atk1 = Pokedex.getTypeEffectiveness(move1['type'],p2_type) power_atk1 = move1['power'] if power_atk1 == None: power_atk1 = 0 if move2 != None: type_atk2 = Pokedex.getTypeEffectiveness(move2['type'],p1_type) power_atk2 = move2['power'] if power_atk2 == None: power_atk2 = 0 return [type_atk1*power_atk1*STAB1, type_atk2*power_atk2*STAB2]
def calculateDamage(self, move_name, user_pokemon, reciever_pokemon, reciever_hp): #accuracy removed move = Pokedex.getMove(move_name) user_type = Pokedex.get(user_pokemon)['type'] reciever_type = Pokedex.get(reciever_pokemon)['type'] STAB = 1 if move['type'] in user_type: STAB = 1.5 type_multiplier = Pokedex.getTypeEffectiveness(move['type'], reciever_type) power = 0 if move['power'] is None else move['power'] damage = STAB * type_multiplier * power return damage
def calculateDamage(self, move_name, user_pokemon, reciever_pokemon, reciever_hp): move = Pokedex.getMove[move_name] user_type = Pokedex.get(user_pokemon)['type'] reciever_type = Pokedex.get(reciever_pokemon)['type'] STAB = 1 if move['type'] in user_type: STAB = 1.5 type_multiplier = Pokedex.getTypeEffectiveness(move['type'], reciever_type) if move['accuracy'] != 'None' and move['accuracy'] != None: accuracy = move['accuracy'] else: accuracy = 1 damage = STAB * type_multiplier * move['power'] * accuracy return damage
def get_poke_info(): """ リクエストのポケモン名をベースに検索結果を返す(部分一致) :return: HTMLデータ """ pokedex = Pokedex() poke_name = pokedex.get_poke_name_list() name = request.args.get('name') if name is not None: tgt_name = name else: tgt_name = poke_name[0] title = "{}の種族値".format(tgt_name) poke_status = pokedex.get_poke_info(tgt_name) return render_template('poke_info.html', title=title, info=poke_status, name_list=poke_name)
def damage(power, moveType, defType, atkType, attack, defense): stab = 1.5 if moveType in atkType else 1.0 effectiveness = Pokedex.getTypeEffectiveness(moveType, defType) if effectiveness > 1: print "It's super effective!" ratio = float(attack) / float(defense) return math.floor(((42 * power * ratio) / 50.0 + 2) * stab * effectiveness)
def update_player_2(self,pokemon_name,pokemon_hp): """ To be used to backpropogate information """ #Use this because p1_pokemon_names updates automatically if len(self.p2_pokemon_names) > len(self.p2_pokemon_hp): self.p2_pokemon_hp.append(pokemon_hp) self.p2_pokemon_status.append("None") self.p2_pokemon_types.append(Pokedex.get(pokemon_name)["type"])
def __init__(self, p2_pokemon_names, p2_pokemon_hp, p2_pokemon_status, p2_action, p2_in_play, p2_max_hps, p1_pokemon_names, p1_pokemon_hp, p1_pokemon_status, p1_action, p1_in_play, p1_moves, p2_moves, p1_max_hps, p2_heal, p1_heal): """ Constructor for one gamestate --> state/action pair """ #the weird way I'm instantiating list variables is because they keep changing when the inputs change #want names and moves to be same throughout all states self.p2_pokemon_names = p2_pokemon_names self.p2_pokemon_hp = [] for i in p2_pokemon_hp: self.p2_pokemon_hp.append(i) self.p2_pokemon_status = [] for i in p2_pokemon_status: self.p2_pokemon_status.append(i) self.p2_action = p2_action self.p2_in_play = p2_in_play self.p2_pokemon_moves = p2_moves self.p2_pokemon_types = [] for pokemon in p2_pokemon_names: self.p2_pokemon_types.append(Pokedex.get(pokemon)["type"]) self.p2_hp_change = 0 self.p2_max_hps = p2_max_hps self.p2_heal = p2_heal self.p1_pokemon_names = p1_pokemon_names self.p1_pokemon_hp = [] for i in p1_pokemon_hp: self.p1_pokemon_hp.append(i) self.p1_pokemon_status = [] for i in p1_pokemon_status: self.p1_pokemon_status.append(i) self.p1_action = p1_action self.p1_in_play = p1_in_play self.p1_pokemon_moves = p1_moves self.p1_pokemon_types = [] self.p1_max_hps = p1_max_hps self.p1_heal = p1_heal self.p1_hp_change = 0 for pokemon in p1_pokemon_names: self.p1_pokemon_types.append(Pokedex.get(pokemon)["type"])
def getFirstPlayer(self, my_team, active_index, opponent_pokemon, move_name): #SHould return "[1,2]" if p1 expected to go first, "[2,1]" otherwise #For now, assume p1 goes first my_speed = my_team[active_index]['speed'] opponent_speed = Pokedex.getAverageSpeed(opponent_pokemon['name']) if my_team[active_index]['status'] == 'PAR': my_speed /= 4 if opponent_pokemon['status'] == 'PAR': opponent_speed /= 4 if my_speed > opponent_speed: return [1, 2] elif my_speed < opponent_speed: return [2, 1] else: return random.shuffle([1, 2])
def find_pokemon_name(nom_scramble): pokedex = Pokedex() nom_scramble = nom_scramble.lower() for poke in pokedex.pokemons: pokeNom = list(poke.name.lower()) for lettre1 in nom_scramble: if lettre1 in pokeNom: pokeNom.remove(lettre1) else: break if not pokeNom: return poke.name return "no pokemon found"
def startJourney(filename): pkmn = np.genfromtxt(filename, skip_header=1, dtype=list(PKMN.values()), delimiter=',') #input(pkmn) pokedex = Pokedex(pkmn) pokedex.catchem(ALL) # train and score on specific categories categories = [ PKMN[Attack], PKMN[SpAtk], PKMN[SpDef], PKMN[Defense], PKMN[Speed], PKMN[HeightM], PKMN[WeightKG] ] results = PKMN[Type1] # 1 dimensional pokedex.train(categories, results) score = pokedex.score(categories, results) print(f'Pokedex Score : {score}') return pkimg = PokemonImage(ImgCsv) pkplot = PokePlot(rows=1, cols=1) x = data[Number] y = data[TotalStat] hp = normalize(data[HP]) zeros = np.zeros(hp.size * 2)[:, None].reshape((hp.size, 2)) ones = np.ones(hp.size)[:, None] col = hp[:, None] print(ones) trail = np.append(zeros, ones, axis=1) colors = np.append(col, trail, axis=1) #colors = colors.reshape((hp.size, 3)) input(colors) pkplot.scatter(x, y, colors=colors) pkplot.show()
"""Test Cases for Pokedex.""" from pokedex import Pokedex my_pokemon = Pokedex() pokemon_to_add = [ "bulbasaur", "ivysaur", "venusaur", "charmander", "charmeleon", "charizard", "squirtle", "wartortle", "blastoise", "caterpie", "pikachu", "raichu", "poliwhirl", "vulpix", "ninetales", "zubat", "diglett", "psyduck", "growlithe", "arcanine" ] for pokemon in pokemon_to_add: my_pokemon.add_pokemon(pokemon) my_pokemon.dump_pokedex() my_pokemon.print_names() print(my_pokemon.search("raichu")) print(my_pokemon.search("butterfree"))
# This Python file uses the following encoding: utf-8 # The file used to control the game via the command line. from pokedex import Pokedex import QLearner import random import numpy import math import sys my_team = Pokedex.randomTeam() opponent_team = Pokedex.randomTeam() second_player_can_move = True interactive = False active_index = -1 opponent_active_index = -1 separator = ', ' Q_agent = None def main(): global interactive global Q_agent global my_team global opponent_team print "Importing log data and weights..." print "This might take a moment. Thanks for your patience." Q_learning_agent = QLearner.QLearningAgent() Q_learning_agent.runTrainingData() weights = Q_learning_agent.returnWeights()
if current_features['par2'] < 1: next_state_features['par2']= move['effect_prob'] elif effect == "opponent_status:brn": if current_features['brn2'] < 1: next_state_features['brn2']= move['effect_prob'] #Now look at p2's turn #if opponent will die after or not if current_game_state.getp2_hp() < damage2: prob_p2fnt = move['effect_prob'] else: prob_p2fnt = 0 damage1 = 0 for i in current_game_state.getp2_pokemon_moves().keys(): damage1 += self.calculateDamage(i,p1,p2,current_game_state.getp1_hp())/4 for num in 4-current_game_state.getp2_pokemon_moves().keys(): poss_moves2 = Pokedex.getLegalMoves(p2) move_added = False while not move_added: i = numpy.random(range(len(poss_moves2))) if i not in current_game_state.getp2_pokemon_moves().keys(): damage1 += self.calculateDamage(i,p1,p2,current_game_state.getp1_hp())/4 move_added = True next_state_features('atk2') = damage1 if damage1 > p1_hp: next_state_features['remaining1']=current_features['remaining1']-1 #Not dealing with effects on p1, too difficult to account for next_state_features('par1') = current_features('par1') next_state_features('tox1') = current_features('tox1') next_state_features('brn1') = current_features('brn1') print(next_state_features) return next_state_features
def calculateExpectedNextState(self, move_name, current_game_state): #true_effect = anticipated reward, anticipated #TODO: FINISH IMPLIMENTATION --> expected damage from attack, expected change in status features, expected effect on own hp. #TODO: FIGURE OUT ORDER OF TURNS current_features = self.getCurrentFeatures(current_game_state) next_state_features = {} move = Pokedex.getMove[move_name] effect_id = move['effect_id'] effect_prob = Pokedex.effects['effect_prob'] effect = Pokedex.effects[effect_id] p1 = current_game_state.getp1_in_play() p2 = current_game_state.getp2_in_play() p1_index = current_game_state.getp1_pokemon_names.index(p1) p2_index = current_game_state.getp2_pokemon_names.index(p2) p1_hp = current_game_state.getp1_hp() p2_hp = current_game_state.getp2_hp() p1_type = Pokedex.get(p1)['type'] p2_type = Pokedex.get(p2)['type'] #NOTE: IGNORING POSSIBILITY OF OPPONENT SWITCHING damage2 = self.calculateDamage(move_name, p1, p2, p2_hp) if 'par' in current_game_state.get_p1_stats()[p1_index]: expected_damage2 = expected_damage2 *.75 ''' if 'frz' in current_game_state.get_p1_stats()[p1_index]: #appears as though freeze is permanent, cant move expected_damage2 = 0 if 'slp' in current_game_state.get_p1_stats()[p1_index]: #cannot move on turn you wake up expected_damage2 = 0 ''' next_state_features['atk1'] = damage2 if damage2 > hp2: next_state_features['remaining2']=current_features['remaining1']-1 if effect == "heal": max_hp = current_game_state.get_p1_max_hps()[p1_index] if move == "rest": if .5*max_hp+current_game_state.getp1_hp()[p1_index] < max_hp: heal1 = .5*max_hp+current_game_state.getp1_hp()[p1_index] * effect_prob else: heal1 = max_hp*effect_prob - current_game_state.getp1_hp()[p1_index] elif move == "rest": heal1 = max_hp*effect_prob - current_game_state.getp1_hp()[p1_index] else: heal1 = .5*damage next_state_features['heal1']=heal1 if effect == "opponent_status:psn": if current_features['tox2'] < 1: next_state_features['tox2']= move['effect_prob'] elif effect == "opponent_status:par": #IMPLIMENT HERE TO SHOW THAT THEY GET POISONED #how to deal with dif ppl getting poisoned if current_features['par2'] < 1: next_state_features['par2']= move['effect_prob'] elif effect == "opponent_status:brn": if current_features['brn2'] < 1: next_state_features['brn2']= move['effect_prob'] #Now look at p2's turn #if opponent will die after or not damage1 = 0 for i in current_game_state.getp2_pokemon_moves().keys(): damage1 += self.calculateDamage(i,p1,p2,current_game_state.getp1_hp())/4 for num in 4-current_game_state.getp2_pokemon_moves().keys(): poss_moves2 = Pokedex.getLegalMoves(p2) move_added = False while not move_added: i = numpy.random(range(len(poss_moves2))) if i not in current_game_state.getp2_pokemon_moves().keys(): damage1 += self.calculateDamage(i,p1,p2,current_game_state.getp1_hp())/4 move_added = True next_state_features('atk2') = damage1 if damage1 > p1_hp: next_state_features['remaining1']=current_features['remaining1']-1 #Not dealing with effects on p1, too difficult to account for next_state_features('par1') = current_features('par1') next_state_features('tox1') = current_features('tox1') next_state_features('brn1') = current_features('brn1') print(next_state_features) return next_state_features
#constants NUM = 0 NAME = 1 TYPE = 2 TOTAL = 3 HP = 4 ATTACK = 5 DEFENSE = 6 SPATCK = 7 SPDEF = 8 SPEED = 9 client = discord.Client() TOKEN = "" #must put in your own token! pokedex = Pokedex() #run the discored bot def run(): client.run(TOKEN) #display a message when ready @client.event async def on_ready(): print("Bot ready!") await client.change_presence(activity=discord.Game(name="Pokemon Red")) #send a message
def calculateExpectedNextFeatures(self,active_index, current_features, move_name, my_team, opponent_pokemon): #true_effect = anticipated reward, anticipated #TODO: FINISH IMPLIMENTATION --> expected damage from attack, expected change in status features, expected effect on own hp. #TODO: FIGURE OUT ORDER OF TURNS next_state_features = current_features if move_name == 'None' or move_name == None: move_name = 'Growl' move = Pokedex.getMove(move_name) effect_id = move['effect_id'] effect_prob = move['effect_prob'] if effect_id in Pokedex.effects.keys(): effect = Pokedex.effects[effect_id] else: effect = 'None' p1 = my_team[active_index] p2 = opponent_pokemon p1_faint = 0 p2_faint = 0 order = self.getFirstPlayer(my_team,active_index,opponent_pokemon,move_name) atk1 = self.calculateDamage(move_name, p1['name'], p2['name'], p1['current_hp'])*move['accuracy'] if 'par' in p1['status']: atk1 = atk1 *.75 next_state_features['atk1'] = atk1 if self.calculateDamage(move_name, p1['name'], p2['name'], p2['current_hp']) > p2['current_hp']: #doesn't include possibility of opponent switch next_state_features['remaining2']=current_features['remaining1']-move['accuracy'] p2_faint = move['accuracy'] if effect == "heal": max_hp = p1['hp'] if move == "rest": if .5*max_hp+p1['current_hp'] < max_hp: heal1 = .5*max_hp+p1['current_hp']* effect_prob else: heal1 = max_hp*effect_prob - p1['current_hp'] elif move == "rest": heal1 = max_hp*effect_prob - p1['current_hp'] else: heal1 = .5*atk1 next_state_features['heal1']=heal1 if effect == "opponent_status:psn": if current_features['tox2'] < 1: next_state_features['tox2']= move['effect_prob'] elif effect == "opponent_status:par": if current_features['par2'] < 1: next_state_features['par2']= move['effect_prob'] elif effect == "opponent_status:brn": if current_features['brn2'] < 1: next_state_features['brn2']= move['effect_prob'] atk2 = 0 avg_accuracy = 0 for i in opponent_pokemon['known_moves']: atk2 += Pokedex.getMove(i)*self.calculateDamage(i,my_team[active_index]['name'],opponent_pokemon['name'],opponent_pokemon['current_hp'])/4 avg_accuracy += Pokedex.getMove(i)['accuracy']/4 for num in range(4-len(opponent_pokemon['known_moves'])): poss_moves2 = Pokedex.getLegalMoves(opponent_pokemon['name']) move_added = False while not move_added: i = random.choice(range(len(poss_moves2))) if i not in opponent_pokemon['known_moves']: atk2 += poss_moves2[i]['accuracy'] * self.calculateDamage(poss_moves2[i]['name'], my_team[active_index]['name'], opponent_pokemon['name'], opponent_pokemon['current_hp']) / 4 avg_accuracy += poss_moves2[i]['accuracy']/4 move_added = True next_state_features['atk2'] = atk2*avg_accuracy if order[0] == 1: next_state_features['atk2'] = atk2*(1-move['accuracy']) if atk2 > p1['current_hp']: next_state_features['remaining1']=current_features['remaining1']-avg_accuracy p1_faint = avg_accuracy if order[0] == 2: next_state_features['atk1'] = next_state_features['atk1']*(1-avg_accuracy) #Not dealing with effects on p1, too difficult to account for next_state_features['par1'] = current_features['par1'] next_state_features['tox1'] = current_features['tox1'] next_state_features['brn1'] = current_features['brn1'] return next_state_features
def setUp(self): self.pokedex = Pokedex()
from pokedex import Pokedex from ui import PokedexInterface pokedex = Pokedex() pokedex.get_entries() poke_interface = PokedexInterface()