Implement Retire HoF (Gauntlet) rule enforcement for genlockes
When retireHoF is enabled, surviving HoF Pokemon and their evolutionary families are retired at leg advancement and treated as duplicates in all subsequent legs — both in the encounter modal and bulk randomize. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
31
backend/src/app/services/families.py
Normal file
31
backend/src/app/services/families.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from collections import deque
|
||||
|
||||
from app.models.evolution import Evolution
|
||||
|
||||
|
||||
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]] = {}
|
||||
for evo in evolutions:
|
||||
adj.setdefault(evo.from_pokemon_id, set()).add(evo.to_pokemon_id)
|
||||
adj.setdefault(evo.to_pokemon_id, set()).add(evo.from_pokemon_id)
|
||||
|
||||
visited: set[int] = set()
|
||||
pokemon_to_family: dict[int, list[int]] = {}
|
||||
for node in adj:
|
||||
if node in visited:
|
||||
continue
|
||||
component: list[int] = []
|
||||
queue = deque([node])
|
||||
while queue:
|
||||
current = queue.popleft()
|
||||
if current in visited:
|
||||
continue
|
||||
visited.add(current)
|
||||
component.append(current)
|
||||
for neighbor in adj.get(current, set()):
|
||||
if neighbor not in visited:
|
||||
queue.append(neighbor)
|
||||
for member in component:
|
||||
pokemon_to_family[member] = component
|
||||
return pokemon_to_family
|
||||
Reference in New Issue
Block a user