public Type GetNextSpawn(PodsData pods) { var totalPods = pods.OwnPods.Count; var iRoleAssemblies = Reflection.RoleAssemblies; // todo float maxRatio = 0f; Type maxType = null; foreach (var iRole in iRoleAssemblies) { var roleType = iRole.AsType(); var currentRatio = pods.GetPodCollectionWithRole(roleType).Count / (float)totalPods; var goalRatio = _rolesRatios[roleType]; var prioritizeSpawn = goalRatio / currentRatio; //Debug.Print("["+roleType.Name+"] Current Ratio : " + currentRatio + " | Goal : " + goalRatio + " | Prioritized : "+ prioritizeSpawn); if (prioritizeSpawn > maxRatio) { maxRatio = prioritizeSpawn; maxType = roleType; } } //Debug.Print("_"); return(maxType); }
public void AttributeRoles() { var toRemove = new List <Pod>(); foreach (var pod in podsData.GetPodCollectionWithRole(null)) { var nextRole = ratios.GetNextSpawn(podsData); pod.Role = (IRole)nextRole.Construct(); podsData.SpecializedPods.AddPod(pod); } podsData.SpecializedPods.ClearColectionWithRole(null); }
public void AttributeTargets(PodsData podsData, PrioritizedTargets targets, Map map) { var target = targets.Collection.ElementAt(0).Key; var offset = 0; var attackers = podsData.GetPodCollectionWithRole(typeof(Attacker)).ToList(); var nbTotalAttackers = attackers.Count; Debug.Print("total attackers : " + attackers.Count); targets.ForEachZone(zone => { var nbPodsToAssign = (int)Math.Round(targets.GetPercent(zone) * nbTotalAttackers); if (offset + nbPodsToAssign < nbTotalAttackers) { attackers.GetRange(offset, nbPodsToAssign).ForEach(pod => { pod.AssignTarget(target); }); offset += nbPodsToAssign; if (nbPodsToAssign == 0) { attackers.GetRange(offset, 1).ForEach(pod => { pod.AssignTarget(target); }); offset += 1; } Debug.Print("[" + zone.Id + "] " + nbPodsToAssign + " new offset : " + offset); } }); /* * foreach (var pod in podsData.GetPodCollectionWithRole(typeof(Attacker))) * { * if (pod.IsWaiting) * { * pod.Target = new Target(pod.Position, target); * Debug.Print("Attribute attacker pod : "+pod.Position.Id+" target : " + targets.Collection.ElementAt(0).Key.Id); * } * * } */ }
public void AttributeTargets(PodsData podsData, PrioritizedTargets targets, Map map) { if (targets == null) { return; } var pods = podsData.GetPodCollectionWithRole(typeof(Explorer)); var waiters = pods.Where(p => p.IsWaiting).ToList(); pods.ForEach(pod => { /* * if (pod.IsWaiting) * { * if (targets.Collection.Count == 0) * { * pod.Draft(); * } * else * { * //here proxy * var bestPlatZone = MaxPlatInNeighbors(pod.Position.Neighbors); * if (bestPlatZone != null) * { * Debug.Print("Proxy : " + pod.Position.Id + " -> " + bestPlatZone.Id); * pod.AssignTarget(bestPlatZone); * targets.Remove(pod.Target.Dest); * } * else * { * var pathFound = GetPathToClosestNeutralZone(pod.Position, map); * if (pathFound != null) * { * pod.AssignTarget(pathFound); * targets.Remove(pod.Target.Dest); * } * else * { * Debug.Print("[Error] GetPathToClosestNeutralZone returned null for " + pod.Position.Id); * } * } * } * } */ if (targets.Collection.Count == 0 && pod.IsWaiting) { pod.Draft(); } else { var bestPlatZone = MaxPlatInNeighbors(pod.Position.Neighbors); if (bestPlatZone != null) { if (!pod.IsWaiting) { pod.RemoveTarget(); } pod.AssignTarget(bestPlatZone); } else { if (!pod.IsWaiting) { var destAssignedMission = pod.Target.Dest.AssignedMissions; if (destAssignedMission.Count > 1) { FindAndAssignNextNeutralZone(targets, pod, map); } } else { FindAndAssignNextNeutralZone(targets, pod, map); } } } }); }