def __init__(self, poke, pokedata): super(MoveCoPredictor, self).__init__(poke, pokedata) graph_move = self.pokedata.graph_move self.poke_moves = self.pokedata.poke_moves[correct_mega( correct_name(self.poke))] self.co = graph_move['cooccurences'] self.freq = graph_move['frequencies']
def __init__(self, poke, pokedata): super(RandomMovePredictor, self).__init__(poke, pokedata) poke_moves = self.pokedata.poke_moves[correct_mega( correct_name(self.poke))] random.shuffle(poke_moves) prob = 1.0 / len(poke_moves) self.predictions = [(x, prob) for x in poke_moves]
def get_freqs(self, freq): poke = correct_name(self.poke) poke = correct_mega(poke) probs = {} for move in freq[poke]: prob = freq[poke][move] probs[move] = prob return probs
def get_moves(self, known_moves): poke = correct_name(self.poke) poke = correct_mega(poke) probs = {} if len(known_moves) == 0: probs = self.get_freqs(self.freq) else: for move in self.co[poke]: if move in known_moves: continue prob = 1.0 for othermove in known_moves: if othermove not in self.co[poke][move]: prob *= 0 continue prob *= self.co[poke][move][othermove] if move in MOVE_CORRECTIONS: probs[MOVE_CORRECTIONS[othermove]] = probs[othermove] del probs[move] prob *= self.freq[poke][move] probs[move] = prob #else: #for move in known_moves: #if move not in self.co[poke]: #continue #for othermove in self.co[poke][move]: #if othermove in MOVE_CORRECTIONS: #probs[MOVE_CORRECTIONS[othermove]] = probs[othermove] #del probs[move] #if othermove in known_moves: #continue #prob = self.co[poke][move][othermove] #if othermove not in probs: #probs[othermove] = 1 #probs[othermove] *= prob if probs == {}: probs = self.get_freqs(poke, self.freq) self.predictions = sorted(probs.items(), key=lambda x: -x[1]) return self.predictions
def get_moves(self, known_moves): poke = correct_name(self.poke) poke = correct_mega(poke) probs = {} if len(known_moves) == 0: probs = self.get_freqs(self.freq) else: for move in self.co[poke]: if move in known_moves: continue prob = 1.0 for othermove in known_moves: if othermove not in self.co[poke][move]: prob *= 0 continue prob *= self.co[poke][move][othermove] if move in MOVE_CORRECTIONS: probs[MOVE_CORRECTIONS[othermove]] = probs[othermove] del probs[move] prob *= self.freq[poke][move] probs[move] = prob #else: #for move in known_moves: #if move not in self.co[poke]: #continue #for othermove in self.co[poke][move]: #if othermove in MOVE_CORRECTIONS: #probs[MOVE_CORRECTIONS[othermove]] = probs[othermove] #del probs[move] #if othermove in known_moves: #continue #prob = self.co[poke][move][othermove] #if othermove not in probs: #probs[othermove] = 1 #probs[othermove] *= prob if probs == {}: probs = self.get_freqs(self.freq) self.predictions = sorted(probs.items(), key=lambda x: -x[1]) return self.predictions
def get_moves_assumption_two(self, known_moves): poke = correct_name(self.poke) poke = correct_mega(self.poke) probs = {} if len(known_moves) == 0: probs = self.get_freqs(poke, self.freq) else: for move in known_moves: if move not in self.co[poke]: continue for othermove in self.co[poke][move]: if othermove in MOVE_CORRECTIONS: probs[MOVE_CORRECTIONS[othermove]] = probs[othermove] del probs[move] if othermove in known_moves: continue prob = self.co[poke][move][othermove] if othermove not in probs: probs[othermove] = 1 probs[othermove] *= prob if probs == {}: probs = self.get_freqs(poke, self.freq) self.predictions = sorted(probs.items(), key=lambda x: -x[1]) return self.predictions
def create_initial_gamestate(self): self.logger.info("Creating initial gamestate...") my_pokes = self.my_team.copy() for i, poke in enumerate(my_pokes.poke_list): poke_name = poke.name if poke_name in NAME_CORRECTIONS: poke_name = NAME_CORRECTIONS[poke_name] poke.health = poke.final_stats['hp'] poke.alive = True opp_poke_list = [] log = SimulatorLog.parse(self.selenium.get_log()) for event in log.events: if event.type == "team" and event.details[ 'username'] != self.username: opp_poke_names = event.details['team'] for name in opp_poke_names: if not name: continue poke_name = correct_name(name) "Corrected to:", poke_name if poke_name in self.smogon_data: moveset = [ m for m in self.smogon_data[poke_name].movesets if 'Overused' == m['tag'] or 'Underused' == m['tag'] or 'Rarelyused' == m['tag'] or 'Neverused' == m['tag'] or 'Unreleased' == m['tag'] or 'Ubers' == m['tag'] or 'PU' in m['tag'] ] if len(moveset) > 1: moveset = SmogonMoveset.from_dict(moveset[1]) elif len(moveset) == 1: moveset = SmogonMoveset.from_dict(moveset[0]) else: moveset = [ m for m in self.smogon_bw_data[poke_name].movesets if 'Overused' == m['tag'] or 'Underused' == m['tag'] or 'Rarelyused' == m['tag'] or 'Neverused' == m['tag'] or 'Unreleased' == m['tag'] or 'Ubers' == m['tag'] or 'PU' in m['tag'] ] moveset = SmogonMoveset.from_dict(moveset[0]) elif poke_name not in self.smogon_data and poke_name in self.smogon_bw_data: moveset = [ m for m in self.smogon_bw_data[poke_name].movesets if 'Overused' == m['tag'] or 'Underused' == m['tag'] or 'Rarelyused' == m['tag'] or 'Neverused' == m['tag'] or 'Unreleased' == m['tag'] or 'Ubers' == m['tag'] or 'PU' in m['tag'] ] moveset = SmogonMoveset.from_dict(moveset[0]) else: moveset = SmogonMoveset( None, None, None, { 'hp': 88, 'patk': 84, 'pdef': 84, 'spatk': 84, 'spdef': 84, 'spe': 84 }, { 'hp': 1.0, 'patk': 1.0, 'pdef': 1.0, 'spatk': 1.0, 'spdef': 1.0, 'spe': 1.0 }, None, 'ou') moveset.moves = None if poke_name in self.smogon_data: typing = self.smogon_data[poke_name].typing stats = self.smogon_data[poke_name].stats elif poke_name not in self.smogon_data and poke_name in self.smogon_bw_data: typing = self.smogon_bw_data[poke_name].typing stats = self.smogon_bw_data[poke_name].stats else: typing = ['Normal'] stats = { 'hp': 80, 'patk': 80, 'pdef': 80, 'spatk': 80, 'spdef': 80, 'spe': 80 } predictor = create_predictor(self.predictor_name, name, self.pokedata) poke = Pokemon(name, typing, stats, moveset, predictor, calculate=True) moves = [x[0] for x in poke.predict_moves([])] poke.moveset.moves = moves[:4] poke.health = poke.final_stats['hp'] poke.alive = True opp_poke_list.append(poke) my_primary = None for event in log.events: if event.type == "switch" and event.player == 0: for poke in my_pokes.poke_list: if poke.name == event.poke: my_primary = my_pokes.poke_list.index(poke) elif event.type == "switch" and event.player == 1: for poke in opp_poke_list: if poke.name == event.poke: opp_primary = opp_poke_list.index(poke) assert my_primary != None self.opp_team = Team(opp_poke_list) opp_pokes = self.opp_team.copy() my_pokes.primary_poke = my_primary opp_pokes.primary_poke = opp_primary gamestate = GameState([my_pokes, opp_pokes]) return gamestate
def __init__(self, poke, pokedata): super(MoveCoPredictor, self).__init__(poke, pokedata) graph_move = self.pokedata.graph_move self.poke_moves = self.pokedata.poke_moves[correct_mega(correct_name(self.poke))] self.co = graph_move['cooccurences'] self.freq = graph_move['frequencies']
def __init__(self, poke, pokedata): super(RandomMovePredictor, self).__init__(poke, pokedata) poke_moves = self.pokedata.poke_moves[correct_mega(correct_name(self.poke))] random.shuffle(poke_moves) prob = 1.0 / len(poke_moves) self.predictions = [(x, prob) for x in poke_moves]
def create_initial_gamestate(self): self.logger.info("Creating initial gamestate...") my_pokes = self.my_team.copy() for i, poke in enumerate(my_pokes.poke_list): poke_name = poke.name if poke_name in NAME_CORRECTIONS: poke_name = NAME_CORRECTIONS[poke_name] poke.health = poke.final_stats['hp'] poke.alive = True opp_poke_list = [] log = SimulatorLog.parse(self.selenium.get_log()) for event in log.events: if event.type == "team" and event.details['username'] != self.username: opp_poke_names = event.details['team'] for name in opp_poke_names: if not name: continue poke_name = correct_name(name) "Corrected to:", poke_name if poke_name in self.smogon_data: moveset = [m for m in self.smogon_data[poke_name].movesets if 'Overused' == m['tag'] or 'Underused' == m['tag'] or 'Rarelyused' == m['tag'] or 'Neverused' == m['tag'] or 'Unreleased' == m['tag'] or 'Ubers' == m['tag'] or 'PU' in m['tag']] if len(moveset) > 1: moveset = SmogonMoveset.from_dict(moveset[1]) elif len(moveset) == 1: moveset = SmogonMoveset.from_dict(moveset[0]) else: moveset = [m for m in self.smogon_bw_data[poke_name].movesets if 'Overused' == m['tag'] or 'Underused' == m['tag'] or 'Rarelyused' == m['tag'] or 'Neverused' == m['tag'] or 'Unreleased' == m['tag'] or 'Ubers' == m['tag'] or 'PU' in m['tag']] moveset = SmogonMoveset.from_dict(moveset[0]) elif poke_name not in self.smogon_data and poke_name in self.smogon_bw_data: moveset = [m for m in self.smogon_bw_data[poke_name].movesets if 'Overused' == m['tag'] or 'Underused' == m['tag'] or 'Rarelyused' == m['tag'] or 'Neverused' == m['tag'] or 'Unreleased' == m['tag'] or 'Ubers' == m['tag'] or 'PU' in m['tag']] moveset = SmogonMoveset.from_dict(moveset[0]) else: moveset = SmogonMoveset(None, None, None, {'hp': 88, 'patk': 84, 'pdef': 84, 'spatk': 84, 'spdef': 84, 'spe': 84}, {'hp': 1.0, 'patk': 1.0, 'pdef': 1.0, 'spatk': 1.0, 'spdef': 1.0, 'spe': 1.0}, None, 'ou') moveset.moves = None if poke_name in self.smogon_data: typing = self.smogon_data[poke_name].typing stats = self.smogon_data[poke_name].stats elif poke_name not in self.smogon_data and poke_name in self.smogon_bw_data: typing = self.smogon_bw_data[poke_name].typing stats = self.smogon_bw_data[poke_name].stats else: typing = ['Normal'] stats = {'hp': 80, 'patk': 80, 'pdef': 80, 'spatk': 80, 'spdef': 80, 'spe': 80} predictor = create_predictor(self.predictor_name, name, self.pokedata) poke = Pokemon(name, typing, stats, moveset, predictor, calculate=True) moves = [x[0] for x in poke.predict_moves([])] poke.moveset.moves = moves[:4] poke.health = poke.final_stats['hp'] poke.alive = True opp_poke_list.append(poke) my_primary = None for event in log.events: if event.type == "switch" and event.player == 0: for poke in my_pokes.poke_list: if poke.name == event.poke: my_primary = my_pokes.poke_list.index(poke) elif event.type == "switch" and event.player == 1: for poke in opp_poke_list: if poke.name == event.poke: opp_primary = opp_poke_list.index(poke) assert my_primary != None self.opp_team = Team(opp_poke_list) opp_pokes = self.opp_team.copy() my_pokes.primary_poke = my_primary opp_pokes.primary_poke = opp_primary gamestate = GameState([my_pokes, opp_pokes]) return gamestate