|
|
|
@ -52,7 +52,8 @@ class EfficiencyOriginDexPlanner: |
|
|
|
|
|
|
|
for group in generation_groups: |
|
|
|
group_plan = self.plan_for_group(group, pokemon_by_gen, game_by_gen, encounter_data, evolution_map, caught_pokemon) |
|
|
|
plan.extend(group_plan) |
|
|
|
if group_plan: |
|
|
|
plan.extend(group_plan) |
|
|
|
|
|
|
|
return plan |
|
|
|
|
|
|
|
@ -145,24 +146,39 @@ class EfficiencyOriginDexPlanner: |
|
|
|
for game in selected_games: |
|
|
|
game_plan = self.plan_for_game(game, needed_pokemon, encounter_data, evolution_map, caught_pokemon, set(generations), new_evolutions) |
|
|
|
if game_plan: |
|
|
|
group_plan.extend(game_plan) |
|
|
|
|
|
|
|
# Update game_pokemon to remove exclusive encounters that weren't used |
|
|
|
exclusive_groups = self.get_exclusive_groups(game['id']) |
|
|
|
used_exclusive_groups = set() |
|
|
|
for step in game_plan: |
|
|
|
if step.startswith(" Catch:"): |
|
|
|
pfic = step.split(":")[1].strip().split(" ")[0] |
|
|
|
# Update caught_pokemon and game_pokemon based on the new JSON structure |
|
|
|
for plan_entry in game_plan: |
|
|
|
for pokemon in plan_entry["pokemon"]: |
|
|
|
pfic = pokemon["pfic"] |
|
|
|
caught_pokemon.add(pfic) |
|
|
|
|
|
|
|
# Handle evolutions |
|
|
|
for evolution in pokemon["evolve_to"]: |
|
|
|
caught_pokemon.add(evolution["pfic"]) |
|
|
|
|
|
|
|
# Handle breeding |
|
|
|
for breeding in pokemon["breed_for"]: |
|
|
|
caught_pokemon.add(breeding["pfic"]) |
|
|
|
|
|
|
|
# Update game_pokemon to remove exclusive encounters that weren't used |
|
|
|
exclusive_groups = self.get_exclusive_groups(game['id']) |
|
|
|
used_exclusive_groups = set() |
|
|
|
|
|
|
|
# Track used exclusive groups based on the new structure |
|
|
|
for pokemon in plan_entry["pokemon"]: |
|
|
|
pfic = pokemon["pfic"] |
|
|
|
for group_id, group_encounters in exclusive_groups.items(): |
|
|
|
if any(ge['pfic'] == pfic for ge in group_encounters): |
|
|
|
used_exclusive_groups.add(group_id) |
|
|
|
break |
|
|
|
|
|
|
|
for group_id, group_encounters in exclusive_groups.items(): |
|
|
|
if group_id not in used_exclusive_groups: |
|
|
|
for ge in group_encounters: |
|
|
|
if ge['pfic'] in game_pokemon[game['id']]: |
|
|
|
game_pokemon[game['id']].remove(ge['pfic']) |
|
|
|
# Remove unused exclusive encounters |
|
|
|
for group_id, group_encounters in exclusive_groups.items(): |
|
|
|
if group_id not in used_exclusive_groups: |
|
|
|
for ge in group_encounters: |
|
|
|
if ge['pfic'] in game_pokemon[game['id']]: |
|
|
|
game_pokemon[game['id']].remove(ge['pfic']) |
|
|
|
|
|
|
|
group_plan.extend(game_plan) |
|
|
|
|
|
|
|
if not group_plan: |
|
|
|
print("Warning: No games were selected or no Pokémon were planned to be caught.") |
|
|
|
@ -170,7 +186,10 @@ class EfficiencyOriginDexPlanner: |
|
|
|
return group_plan |
|
|
|
|
|
|
|
def plan_for_game(self, game, needed_pokemon, encounter_data, evolution_map, caught_pokemon, target_generations, new_evolutions): |
|
|
|
game_plan = [] |
|
|
|
game_plan = { |
|
|
|
"game_name": game['name'], |
|
|
|
"pokemon": [] |
|
|
|
} |
|
|
|
to_catch = defaultdict(int) |
|
|
|
to_evolve = defaultdict(list) |
|
|
|
to_breed = defaultdict(list) |
|
|
|
@ -266,23 +285,55 @@ class EfficiencyOriginDexPlanner: |
|
|
|
del to_breed[group_encounter['pfic']] |
|
|
|
|
|
|
|
if to_catch or to_evolve or to_breed: |
|
|
|
game_plan.append(f"Play {game['name']}:") |
|
|
|
if to_catch: |
|
|
|
game_plan.append(" Catch:") |
|
|
|
for pfic, count in to_catch.items(): |
|
|
|
game_plan.append(f" - {self.get_pokemon_name(pfic)}: {count} time(s)") |
|
|
|
if to_evolve: |
|
|
|
game_plan.append(" Evolve:") |
|
|
|
for from_pfic, to_pfics in to_evolve.items(): |
|
|
|
for to_pfic in to_pfics: |
|
|
|
game_plan.append(f" - {self.get_pokemon_name(from_pfic)} into {self.get_pokemon_name(to_pfic)}") |
|
|
|
if to_breed: |
|
|
|
game_plan.append(" Breed:") |
|
|
|
for parent_pfic, baby_pfics in to_breed.items(): |
|
|
|
for baby_pfic in baby_pfics: |
|
|
|
game_plan.append(f" - {self.get_pokemon_name(parent_pfic)} to get {self.get_pokemon_name(baby_pfic)}") |
|
|
|
|
|
|
|
return game_plan |
|
|
|
for pfic, count in to_catch.items(): |
|
|
|
pokemon_entry = { |
|
|
|
"pfic": pfic, |
|
|
|
"name": self.get_pokemon_name(pfic).split(" (")[0], |
|
|
|
"form_name": self.get_form_name(pfic), |
|
|
|
"catch_count": count, |
|
|
|
"evolve_to": [], |
|
|
|
"breed_for": [] |
|
|
|
} |
|
|
|
|
|
|
|
# Add evolution information as flat structure |
|
|
|
if pfic in to_evolve: |
|
|
|
processed_evolutions = set() |
|
|
|
evolution_queue = [(pfic, to_pfic, 1) for to_pfic in to_evolve[pfic]] |
|
|
|
|
|
|
|
while evolution_queue: |
|
|
|
from_pfic, to_pfic, count = evolution_queue.pop(0) |
|
|
|
if (from_pfic, to_pfic) not in processed_evolutions: |
|
|
|
processed_evolutions.add((from_pfic, to_pfic)) |
|
|
|
|
|
|
|
evolution = { |
|
|
|
"pfic": to_pfic, |
|
|
|
"name": self.get_pokemon_name(to_pfic).split(" (")[0], |
|
|
|
"form_name": self.get_form_name(to_pfic), |
|
|
|
"count": count |
|
|
|
} |
|
|
|
|
|
|
|
pokemon_entry["evolve_to"].append(evolution) |
|
|
|
|
|
|
|
# Add next evolution stage to queue if it exists |
|
|
|
if to_pfic in evolution_map: |
|
|
|
for next_pfic in evolution_map[to_pfic]: |
|
|
|
if next_pfic in to_evolve[to_pfic]: |
|
|
|
evolution_queue.append((to_pfic, next_pfic, count)) |
|
|
|
|
|
|
|
# Add breeding information |
|
|
|
if pfic in to_breed: |
|
|
|
for baby_pfic in to_breed[pfic]: |
|
|
|
breeding = { |
|
|
|
"pfic": baby_pfic, |
|
|
|
"name": self.get_pokemon_name(baby_pfic).split(" (")[0], |
|
|
|
"form_name": self.get_form_name(baby_pfic), |
|
|
|
"count": 1 |
|
|
|
} |
|
|
|
pokemon_entry["breed_for"].append(breeding) |
|
|
|
|
|
|
|
game_plan["pokemon"].append(pokemon_entry) |
|
|
|
|
|
|
|
return [game_plan] if game_plan["pokemon"] else [] |
|
|
|
|
|
|
|
def plan_evolutions(self, evolution_chains, evolution_map, caught_pokemon): |
|
|
|
chains, visit_counts = self.get_evolution_chains(evolution_chains[0][0], evolution_map) |
|
|
|
@ -343,17 +394,19 @@ class EfficiencyOriginDexPlanner: |
|
|
|
return f"{result['name']} ({result['form_name']})" |
|
|
|
return result['name'] |
|
|
|
|
|
|
|
def display_plan(self, generation_groups, output_file='efficiency_plan.txt'): |
|
|
|
def get_form_name(self, pfic): |
|
|
|
cursor = self.conn.cursor() |
|
|
|
cursor.execute("SELECT form_name FROM pokemon_forms WHERE PFIC = ?", (pfic,)) |
|
|
|
result = cursor.fetchone() |
|
|
|
return result['form_name'] if result and result['form_name'] else "" |
|
|
|
|
|
|
|
def display_plan(self, generation_groups, output_file='efficiency_plan.json'): |
|
|
|
plan = self.generate_efficient_plan(generation_groups) |
|
|
|
|
|
|
|
# Print to console |
|
|
|
#for step in plan: |
|
|
|
# print(step) |
|
|
|
|
|
|
|
# Write to file |
|
|
|
# Write to JSON file |
|
|
|
import json |
|
|
|
with open(output_file, 'w', encoding='utf-8') as f: |
|
|
|
for step in plan: |
|
|
|
f.write(f"{step}\n") |
|
|
|
json.dump(plan, f, indent=4, ensure_ascii=False) |
|
|
|
|
|
|
|
print(f"\nPlan has been written to {os.path.abspath(output_file)}") |
|
|
|
|
|
|
|
|