def simulate(self, gamestate, actions, who, log=False): assert not gamestate.is_over() my_team = gamestate.get_team(who) opp_team = gamestate.get_team(1 - who) my_poke = my_team.primary() opp_poke = opp_team.primary() gamestate = gamestate.deep_copy() my_action = actions[who] opp_action = actions[1 - who] if my_action.is_switch(): gamestate.switch_pokemon(my_action.switch_index, who, log=log) my_move = MOVES["Noop"] my_poke = my_team.primary() if opp_action.is_switch(): gamestate.switch_pokemon(opp_action.switch_index, 1 - who, log=log) opp_move = MOVES["Noop"] opp_poke = opp_team.primary() if my_action.is_move(): my_move = get_move(my_poke.moveset.moves[my_action.move_index]) if opp_action.is_move(): opp_move = get_move(opp_poke.moveset.moves[opp_action.move_index]) moves = [None, None] moves[who] = my_move moves[1 - who] = opp_move first = self.get_first(gamestate, moves, who) self.make_move(gamestate, moves, actions, first, who, log=log) 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 simulate(self, gamestate, actions, who, log=False, add_action=False, deep_copy=True): assert not gamestate.is_over() my_team = gamestate.get_team(who) opp_team = gamestate.get_team(1 - who) my_poke = my_team.primary() opp_poke = opp_team.primary() if deep_copy: gamestate = gamestate.deep_copy() my_action = actions[who] opp_action = actions[1 - who] if my_action.is_switch(): gamestate.switch_pokemon(my_action.switch_index, who, log=log) my_move = MOVES["Noop"] my_poke = my_team.primary() if opp_action.is_switch(): gamestate.switch_pokemon(opp_action.switch_index, 1 - who, log=log) opp_move = MOVES["Noop"] opp_poke = opp_team.primary() if my_action.is_move(): if not my_action.move_name is None: move_name = my_action.move_name elif my_action.move_index != -1: move_name = my_poke.moveset.known_moves[my_action.move_index] else: move_name = my_poke.moveset.known_moves[0] if add_action and not move_name in my_poke.moveset.known_moves: my_poke.moveset.known_moves.append(move_name) my_move = get_move(move_name) if opp_action.is_move(): if not opp_action.move_name is None: move_name = opp_action.move_name elif opp_action.move_index != -1: move_name = opp_poke.moveset.known_moves[opp_action.move_index] else: move_name = opp_poke.moveset.known_moves[0] if add_action and not move_name in opp_poke.moveset.known_moves: opp_poke.moveset.known_moves.append(move_name) opp_move = get_move(move_name) moves = [None, None] moves[who] = my_move moves[1 - who] = opp_move first = self.get_first(gamestate, moves, who) self.make_move(gamestate, moves, actions, first, who, log=log) 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