def update_latest_turn(self, gamestate): self.logger.info("Updating with latest information...") text_log = self.selenium.get_log() text_list = text_log.split("\n") buffer = [] turns = [] for line in text_list: line = line.strip() if re.match(r"Turn [0-9]+", line): turns.append(buffer) buffer = [] else: buffer.append(line) my_poke_name = self.selenium.get_my_primary() if my_poke_name == None: my_poke_name = gamestate.get_team(0).primary().name opp_poke_name = self.selenium.get_opp_primary() if opp_poke_name == None: opp_poke_name = gamestate.get_team(1).primary().name old_gamestate = gamestate gamestate = gamestate.deep_copy() self.simulator.append_log(gamestate, turns[-1], my_poke=my_poke_name, opp_poke=opp_poke_name) move_events = [] for event in self.simulator.latest_turn: if event.type == "move": move_events.append(event) if len(move_events) == 2 and move_events[0].player == 1: my_move = move_events[1].details['move'] opp_move = move_events[0].details['move'] if my_move == "Hidden Power": my_move = get_hidden_power(move_events[1].poke, self.smogon_data) if opp_move == "Hidden Power": opp_move = get_hidden_power(move_events[0].poke, self.smogon_data) if my_move in MOVE_CORRECTIONS: my_move = MOVE_CORRECTIONS[my_move] if opp_move in MOVE_CORRECTIONS: opp_move = MOVE_CORRECTIONS[opp_move] my_move = get_move(my_move) opp_move = get_move(opp_move) if move_events[0].player != self.simulator.get_first( old_gamestate, [my_move, opp_move], 0): opp_poke = old_gamestate.get_team(1).primary() for poke in gamestate.get_team(1).poke_list: if poke.name == opp_poke.name: poke.item = "Choice Scarf" return gamestate
def update_latest_turn(self, gamestate): self.logger.info("Updating with latest information...") text_log = self.selenium.get_log() text_list = text_log.split("\n") buffer = [] turns = [] for line in text_list: line = line.strip() if re.match(r"Turn [0-9]+", line): turns.append(buffer) buffer = [] else: buffer.append(line) my_poke_name = self.selenium.get_my_primary() if my_poke_name == None: my_poke_name = gamestate.get_team(0).primary().name opp_poke_name = self.selenium.get_opp_primary() if opp_poke_name == None: opp_poke_name = gamestate.get_team(1).primary().name old_gamestate = gamestate gamestate = gamestate.deep_copy() self.simulator.append_log(gamestate, turns[-1], my_poke=my_poke_name, opp_poke=opp_poke_name) move_events = [] for event in self.simulator.latest_turn: if event.type == "move": move_events.append(event) if len(move_events) == 2 and move_events[0].player == 1: my_move = move_events[1].details['move'] opp_move = move_events[0].details['move'] if my_move == "Hidden Power": my_move = get_hidden_power(move_events[1].poke, self.smogon_data) if opp_move == "Hidden Power": opp_move = get_hidden_power(move_events[0].poke, self.smogon_data) if my_move in MOVE_CORRECTIONS: my_move = MOVE_CORRECTIONS[my_move] if opp_move in MOVE_CORRECTIONS: opp_move = MOVE_CORRECTIONS[opp_move] my_move = get_move(my_move) opp_move = get_move(opp_move) if move_events[0].player != self.simulator.get_first(old_gamestate, [my_move, opp_move], 0): opp_poke = old_gamestate.get_team(1).primary() for poke in gamestate.get_team(1).poke_list: if poke.name == opp_poke.name: poke.item = "Choice Scarf" return gamestate
def handle_event(self, gamestate, event): def get_pokemon(team, name): for poke in team: if poke.name == name: return poke def get_mega_item(name): for item, (premega, mega) in MEGA_ITEMS.items(): if mega == name: return item player = event.player type = event.type team = gamestate.get_team(player) poke = get_pokemon(team, event.poke) if poke == None: print(event.poke) opp_poke = gamestate.get_team(1 - player).primary() if type == "faint": poke.health = 0 poke.alive = False print("%s fainted." % (poke)) elif type == "mega_evolve": poke.item = get_mega_item(event.details['mega']) team = gamestate.get_team(player) team.poke_list[team.primary_poke] = poke.mega_evolve(self.pokedata) print("%s mega evolved!" % (poke)) elif type == "damage": hp = poke.final_stats['hp'] poke.damage(event.details['damage'] / 100 * hp) print("%s got damaged: %f" % (poke, event.details['damage'])) elif type == "move": print("%s used %s." % (poke, event.details['move'])) if event.details['move'] == "Relic Song": my_poke = gamestate.get_team(player).primary() my_poke.meloetta_evolve() if player == 1: move = event.details['move'] poke_name = correct_mega(poke.name) if move in MOVE_CORRECTIONS: move = MOVE_CORRECTIONS[move] if move == "Hidden Power": hidden_power = get_hidden_power(poke_name, self.smogon_data) if hidden_power: move = hidden_power else: return known_moves = poke.moveset.known_moves if move not in known_moves: self.total += 1 old_guess_moves = [ x[0] for x in poke.predict_moves(known_moves) ][:4 - len(known_moves)] if move in old_guess_moves: self.score += 1 known_moves.append(move) guess_moves = [ x[0] for x in poke.predict_moves(known_moves) if x[0] not in known_moves ][:4 - len(known_moves)] poke.moveset.moves = poke.moveset.known_moves + guess_moves if player == 0: my_poke = gamestate.get_team(player).primary() my_poke.last_move = event.details['move'] if poke.item in ["Choice Scarf", "Choice Specs", "Choice Band"]: moves = poke.moveset.moves try: moves.index(event.details['move']) poke.choiced = True poke.move_choice = event.details['move'] print("%s is choiced to %s" % (poke, event.details['move'])) except: pass elif type == "stat_change": stages = event.details['stages'] if stages > 0: poke.increase_stage(event.details['stat'], abs(stages)) print("%s increased its %s by %d stages" % (poke, event.details['stat'], stages)) else: poke.decrease_stage(event.details['stat'], abs(stages)) print("%s decreased its %s by %d stages" % (poke, event.details['stat'], stages)) elif type == "switch": if poke == "Meloetta": poke.meloetta_reset() team.set_primary(team.poke_list.index(poke)) print("Player %d switched in %s" % (player, poke)) elif type == "regain_health": poke.heal(0.5) print("%s regained health" % poke) elif type == "leftovers": poke.item = "Leftovers" poke.heal(1.0 / 16) print("%s regained health due to leftovers" % poke) elif type == "life_orb": poke.item = "Life Orb" poke.damage_percent(1.0 / 10) elif type == "leech_seed": damage = poke.damage_percent(1.0 / 8) opp_poke.heal(damage) print("%s was sapped and %s gained health due to leech seed." % (poke, opp_poke)) elif type == "rocks": gamestate.set_rocks(player, True) print("Player %u got rocked!" % player) elif type == "spikes": gamestate.spikes[player] += 1 print("Player %u now has %d spikes!" % (player, gamestate.spikes[player])) elif type == "rocks_gone": gamestate.set_rocks(player, False) print("Player %u's rocks disappeared!" % player) elif type == "burn": poke.set_status("burn") elif type == "paralyze": poke.set_status("paralyze") print("%s got burned!" % poke) elif type == "hurt_burn": poke.damage_percent(1.0 / 8) print("%s got hurt due to its burn!" % poke) elif type == "float_balloon": poke.item = "Air Balloon" print("%s has an air balloon!" % poke) elif type == "pop_balloon": poke.item = None print("%s's air balloon was popped!" % poke) elif type == "new_item": poke.item = event.details['item'] print("%s got a %s" % (poke, event.details['item'])) elif type == "lost_item": poke.item = None poke.choiced = False print("%s lost its item!" % poke) elif type == "belly_drum": poke.increase_stage('patk', 9999) elif type == "mold_breaker": poke.ability = "Mold Breaker" print("%s has mold breaker!" % poke) elif type == "disabled": move = event.details['move'] poke.disabled = move print("%s has mold breaker!" % poke) elif type == "taunt": poke.set_taunt(True) print("%s just got taunted!" % poke) elif type == "encore": poke.set_encore(True) print("%s just got encored!" % poke)
def handle_event(self, gamestate, event): def get_pokemon(team, name): for poke in team: if poke.name == name: return poke def get_mega_item(name): for item, (premega, mega) in MEGA_ITEMS.items(): if mega == name: return item player = event.player type = event.type team = gamestate.get_team(player) poke = get_pokemon(team, event.poke) opp_poke = gamestate.get_team(1 - player).primary() if type == "faint": poke.health = 0 poke.alive = False # print "%s fainted." % (poke) elif type == "mega_item": poke.item = event.details['item'] team = gamestate.get_team(player) team.poke_list[team.primary_poke] = poke.mega_evolve(self.pokedata) elif type == "damage": hp = poke.final_stats['hp'] poke.damage(event.details['damage'] / 100 * hp) # print "%s got damaged: %f" % (poke, event.details['damage']) elif type == "move": # print "%s used %s." % (poke, event.details['move']) poke.last_move = event.details['move'] if event.details['move'] == "Relic Song": my_poke = gamestate.get_team(player).primary() my_poke.meloetta_evolve() move = event.details['move'] poke_name = correct_mega(poke.name) if move in MOVE_CORRECTIONS: # print move move = MOVE_CORRECTIONS[move] # print move if move == "Hidden Power": hidden_power = get_hidden_power(poke_name, self.smogon_data) if hidden_power: move = hidden_power else: return if move != None and move not in poke.moveset.known_moves: #self.total += 1 #old_guess_moves = [x[0] for x in poke.predict_moves(poke.moveset.known_moves)][:4 - len(poke.moveset.known_moves)] #if move in old_guess_moves: # self.score += 1 poke.moveset.known_moves.append(move) #guess_moves = [x[0] for x in poke.predict_moves(poke.moveset.known_moves) if x[0] not in poke.moveset.known_moves][:4 - len(poke.moveset.known_moves)] # poke.moveset.moves = poke.moveset.known_moves + guess_moves if poke.item in ["Choice Scarf", "Choice Specs", "Choice Band"]: moves = poke.moveset.known_moves try: moves.index(event.details['move']) poke.choiced = True poke.move_choice = event.details['move'] # print "%s is choiced to %s" % (poke, event.details['move']) except: pass elif type == "stat_change": stages = event.details['stages'] if stages > 0: poke.increase_stage(event.details['stat'], abs(stages)) # print "%s increased its %s by %d stages" % (poke, event.details['stat'], stages) else: poke.decrease_stage(event.details['stat'], abs(stages)) # print "%s decreased its %s by %d stages" % (poke, event.details['stat'], stages) elif type == "switch": #if poke == "Meloetta": # poke.meloetta_reset() #team.set_primary(team.poke_list.index(poke)) gamestate.switch_pokemon(team.poke_list.index(poke), player, log=True) # print "Player %d switched in %s" % (player, poke) elif type == "regain_health": poke.heal(0.5) # print "%s regained health" % poke elif type == "leftovers": poke.item = "Leftovers" poke.heal(1.0 / 16) # print "%s regained health due to leftovers" % poke elif type == "life_orb": poke.item = "Life Orb" poke.damage_percent(1.0/10) elif type == "leech_seed": damage = poke.damage_percent(1.0 / 8) opp_poke.heal(damage) # print "%s was sapped and %s gained health due to leech seed." % (poke, opp_poke) elif type == "rocks": gamestate.set_rocks(player, True) # print "Player %u got rocked!" % player elif type == "spikes": gamestate.spikes[player] += 1 # print "Player %u now has %d spikes!" % (player, gamestate.spikes[player]) elif type == "rocks_gone": gamestate.set_rocks(player, False) # print "Player %u's rocks disappeared!" % player elif type == "burn": poke.set_status("burn") elif type == "paralyze": poke.set_status("paralyze") # print "%s got burned!" % poke elif type == "hurt_burn": poke.damage_percent(1.0 / 8) # print "%s got hurt due to its burn!" % poke elif type == "float_balloon": poke.item = "Air Balloon" # print "%s has an air balloon!" % poke elif type == "pop_balloon": poke.item = None # print "%s's air balloon was popped!" % poke elif type == "new_item": poke.item = event.details['item'] # print "%s got a %s" % (poke, event.details['item']) elif type == "lost_item": poke.item = None poke.choiced = False # print "%s lost its item!" % poke elif type == "belly_drum": poke.increase_stage('patk', 9999) elif type == "mold_breaker": poke.ability = "Mold Breaker" # print "%s has mold breaker!" % poke elif type == "disabled": move = event.details['move'] poke.disabled = move # print "%s has mold breaker!" % poke elif type == "taunt": poke.set_taunt(True) # print "%s just got taunted!" % poke elif type == "encore": poke.set_encore(True)