Add genlocke transfer UI with transfer selection modal and backend support
When advancing to the next genlocke leg, users can now select surviving Pokemon to transfer. Transferred Pokemon are bred down to their base evolutionary form and appear as level-1 egg encounters in the next leg. A GenlockeTransfer record links source and target encounters for lineage tracking. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,26 @@ from collections import deque
|
||||
from app.models.evolution import Evolution
|
||||
|
||||
|
||||
def resolve_base_form(pokemon_id: int, evolutions: list[Evolution]) -> int:
|
||||
"""Walk backward through evolution edges to find the base form of a Pokemon."""
|
||||
# Build reverse map: to_pokemon_id -> from_pokemon_id
|
||||
reverse: dict[int, list[int]] = {}
|
||||
for evo in evolutions:
|
||||
reverse.setdefault(evo.to_pokemon_id, []).append(evo.from_pokemon_id)
|
||||
|
||||
visited: set[int] = set()
|
||||
current = pokemon_id
|
||||
while current not in visited:
|
||||
visited.add(current)
|
||||
predecessors = reverse.get(current)
|
||||
if not predecessors:
|
||||
break
|
||||
# Follow the first predecessor (handles Shedinja -> Nincada correctly
|
||||
# since Nincada evolves *to* both Ninjask and Shedinja)
|
||||
current = predecessors[0]
|
||||
return current
|
||||
|
||||
|
||||
def build_families(evolutions: list[Evolution]) -> dict[int, list[int]]:
|
||||
"""Build pokemon_id -> family members mapping using BFS on evolution graph."""
|
||||
adj: dict[int, set[int]] = {}
|
||||
|
||||
Reference in New Issue
Block a user