public static List <string> GetSystemsXJumpsFrom(List <string> sysList, string start, int X) { if (MapNodes == null || !MapNodes.ContainsKey(start)) { return(sysList); } if (X != 0) { if (!sysList.Contains(start)) { sysList.Add(start); } MapNode mn = MapNodes[start]; foreach (string mm in mn.Connections) { if (!sysList.Contains(mm)) { sysList.Add(mm); } List <string> connected = GetSystemsXJumpsFrom(sysList, mm, X - 1); foreach (string s in connected) { if (!sysList.Contains(s)) { sysList.Add(s); } } } } return(sysList); }
public void AddNodePair(string a, string b) { if (!MapNodes.ContainsKey(a)) { // need to set things up var nodes = new List <string>(); MapNodes.Add(a, nodes); } MapNodes[a].Add(b); }
public static Dictionary <string, int> GetJumpsOfEachSystemInRange(int targetJumps, int currentJump, string location) { var jumpsOfEachSystem = new Dictionary <string, int>(); if (!MapNodes.ContainsKey(location) || currentJump > targetJumps) { return(jumpsOfEachSystem); } var targetSystemNode = MapNodes[location]; jumpsOfEachSystem.Add(location, currentJump); foreach (var connectedNode in targetSystemNode.Connections) { var connectedSystems = GetJumpsOfEachSystemInRange(targetJumps, currentJump + 1, connectedNode); foreach (var connectedSystem in connectedSystems) { if (jumpsOfEachSystem.ContainsKey(connectedSystem.Key)) { var jumpsInCache = jumpsOfEachSystem[connectedSystem.Key]; if (jumpsInCache > connectedSystem.Value) { jumpsOfEachSystem[connectedSystem.Key] = connectedSystem.Value; } } else { jumpsOfEachSystem.Add(connectedSystem.Key, connectedSystem.Value); } } } return(jumpsOfEachSystem); }