def get_move(move): if isinstance(move, dict): return move if isinstance(move, str): return deepcopy(all_move_json.get(move, None)) else: return None
def find_best_attack(self): #build tree attackRoot = Tree() # find worst case move used on each possible switched in Pokemon battle_copy = deepcopy(self) battle_copy.opponent.lock_moves() if self.user.active.hp == 0: return attackRoot for move in self.user.active.moves: if move.name.startswith("hiddenpower"): continue if move.current_pp == 0: continue selfCopy = deepcopy(self) state = selfCopy.create_state() attacking_move = deepcopy(all_move_json.get(move.name, None)) attacking_type = attacking_move.get(constants.CATEGORY) if attacking_type == constants.STATUS: score = 25 else: score = _calculate_damage(state.self.active,state.opponent.active,move.name)[0] switchNode = Tree() switchNode.data = move.name switchNode.maximinScore = score attackRoot.children.append(switchNode) return treeTraversalDFS(attackRoot)
def _get_move(self, move): if isinstance(move, dict): return move if isinstance(move, str): move = clean_string(move) return all_move_json.get(move, None) else: return None
def get_move(move): if isinstance(move, dict): return move if isinstance(move, str): move = normalize_name(move) return all_move_json.get(move, None) else: return None
def attack_or_switch(self): if self.user.last_used_move[1].startswith("switch"): return "ATTACK" if self.user.active.hp == 0: return "SWITCH" waitingPkm = False; for pkm in self.user.reserve: if not pkm.fainted: waitingPkm = True break if not waitingPkm: return "ATTACK" battle_copy = deepcopy(self) battle_copy.opponent.lock_moves() try: pokemon_sets = get_pokemon_sets(battle_copy.opponent.active.name) except KeyError: logger.warning("No set for {}".format(battle_copy.opponent.active.name)) return opponent_possible_moves = sorted(pokemon_sets[MOVES_STRING], key=lambda x: x[1], reverse=True) worstCaseDmgTaken = 0 for move in opponent_possible_moves: if move[0].startswith("hiddenpower"): continue selfCopy = deepcopy(self) state = selfCopy.create_state() damageEstimate = _calculate_damage(state.opponent.active,state.self.active,move[0]) if damageEstimate != None: if damageEstimate[0] > worstCaseDmgTaken: worstCaseDmgTaken = damageEstimate[0] bestCaseDmgGiven = 0 for move in self.user.active.moves: if move.name.startswith("hiddenpower"): continue selfCopy = deepcopy(self) state = selfCopy.create_state() attacking_move = deepcopy(all_move_json.get(move.name, None)) attacking_type = attacking_move.get(constants.CATEGORY) if attacking_type == constants.STATUS: score = 40 else: score = _calculate_damage(state.self.active,state.opponent.active,move.name)[0] if score != None: if score > bestCaseDmgGiven: bestCaseDmgGiven = score if bestCaseDmgGiven >= worstCaseDmgTaken: return "ATTACK" else: return "SWITCH"