using System.Collections.Generic; using UnityEngine; public static class PuzzleGraphUtility { // Builds a dependency graph: for each step, lists the steps it depends on public static Dictionary> BuildDependencyGraph(IEnumerable steps) { var graph = new Dictionary>(); foreach (var step in steps) { graph[step] = new List(); } foreach (var step in steps) { foreach (var unlocked in step.unlocks) { if (!graph.ContainsKey(unlocked)) graph[unlocked] = new List(); graph[unlocked].Add(step); } } return graph; } // Finds initial steps (no dependencies) public static List FindInitialSteps(Dictionary> graph) { var initial = new List(); foreach (var kvp in graph) { if (kvp.Value.Count == 0) initial.Add(kvp.Key); } return initial; } // Finds all steps unlocked by a given step public static List FindUnlocks(PuzzleStepSO step, IEnumerable allSteps) { var unlocks = new List(); foreach (var s in allSteps) { if (s.unlocks.Contains(step)) unlocks.Add(s); } return unlocks; } }