private void weightedDistribution(Node root) { float weightOfNode = root.Weight; if (weightOfNode > 1) { Node[] destinations; if (weightOfNode >= 5) { destinations = root.priorityNodes(4); } else if (weightOfNode > 3) { destinations = root.priorityNodes(3); } else { destinations = root.priorityNodes(2); } distributeGuards(destinations); addNodesToMap(destinations); } else { miniMap.clearPaths(); miniMap.clearNodeImages(); GuardDetection closestGuard = null; float closest = float.MaxValue; foreach (GuardDetection guard in guards) { float distance = (guard.transform.position - root.transform.position).magnitude; if (distance < closest) { closestGuard = guard; closest = distance; } } miniMap.addNodeToMap(root); closestGuard.GetComponent <OptimalTraversal>().changeGoal(root); } }
private void distributeGuards(Node[] destinations) { miniMap.clearPaths(); miniMap.clearNodeImages(); List <GuardDetection> guardsChecked = new List <GuardDetection>(); for (int i = 0; i < destinations.Length; ++i) { Node destination = destinations[i].GetComponent <Node>(); GuardDetection closestGuard = null; float closestDistance = float.MaxValue; foreach (GuardDetection guard in guards) { float distance = (guard.transform.position - destination.transform.position).magnitude; if (distance < closestDistance && !guardsChecked.Contains(guard)) { closestGuard = guard; closestDistance = distance; } } closestGuard.GetComponent <OptimalTraversal>().changeGoal(destination); guardsChecked.Add(closestGuard); } }