public void Remove(int id, GeneticEssence essence) { GeneticEssence.NodeInf inf = essence.Nodes.FirstOrDefault(c => c.SourceNode == false && c.ID == id); List <GeneticEssence.NodeInf> toCheck = new List <GeneticEssence.NodeInf>(); toCheck.Add(inf); while (toCheck.Count > 0) { List <GeneticEssence.NodeInf> newCheck = new List <GeneticEssence.NodeInf>(); foreach (var checking in toCheck) { foreach (var outId in checking.OutConnections) { newCheck.Add(essence.Nodes.FirstOrDefault(c => c.SourceNode == false && c.ID == outId)); } foreach (var c in essence.Nodes) { if (c.OutConnections.Contains(checking.ID)) { c.OutConnections.Remove(checking.ID); } } essence.Nodes.Remove(checking); } toCheck = newCheck; } }
public void ApplyTo(GeneticEssence essence) { var generatedNodes = essence.Nodes.Where(c => c.SourceNode == false).ToList(); if (generatedNodes.Count < 1) { return; } GeneticEssence.NodeInf target = generatedNodes[Random.Range(0, generatedNodes.Count)]; float offset = 5f; float rx = Random.Range(-offset, offset); float ry = Random.Range(-offset, offset); target.Position += new Vector2(rx, ry); List <int> toRemove = new List <int>(); foreach (var id in target.OutConnections) { var node = generatedNodes.FirstOrDefault(c => c.ID == id); if (node == default(GeneticEssence.NodeInf)) { toRemove.Add(id); continue; } if (Vector2.Distance(node.Position, target.Position) < 1) { toRemove.Add(node.ID); } } foreach (var id in toRemove) { MutatorRemover.Instance.Remove(id, essence); } }