Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Link
- {
- //...
- //gets an ordered list of all factories sorted by distance from `sourceFactory`
- public static IOrderedEnumerable<KeyValuePair<Factory, int>> GetFactoriesByDistance(Factory sourceFactory)
- {
- Dictionary<Factory, int> sortedFactories = new Dictionary<Factory, int>();
- foreach(Link link in Links)
- {
- if (link.source != sourceFactory.id) continue; //only looking at links from that originate sourceFactory
- Factory targetFactory = Factory.Factories[link.target];
- sortedFactories.Add(targetFactory, link.distance);
- }
- return sortedFactories.OrderBy(key => key.Value); //return the sorted 'list'
- }
- public static Factory GetTargetFactory(Factory sourceFactory)
- {
- foreach (KeyValuePair<Factory, int> factoryPair in Link.GetFactoriesByDistance(Factory.FriendlyFactories.Values.First())) //get the sorted 'list'
- {
- Factory targetFactory = factoryPair.Key; //simple placeholder variable
- //apply logic to get the best enemy factory to target
- if (targetFactory.owner == 1) continue; //cant be targeting our own factory
- if (Troop.GetCountOfFriendlyTroopsTargetingFactory(targetFactory) > targetFactory.finalNumberOfCyborgs + 1) continue; //check if there is already enough friendly troops targeting this factory
- if (sourceFactory.numberOfCyborgs < targetFactory.finalNumberOfCyborgs - 3) continue; //if we dont have enough troops to capture the planet, we move on
- if (factoryPair.Value < Bomb.TurnsUntilBombHitsFactory(targetFactory)) return null; //THIS HAS TO BE THE LAST CHECK - if we are going to get to this target factory faster than a bomb would (meaning we would suffer from it's effects after we capture the factory) then we return null instead of continuing because we still want to target this factory, just later
- return targetFactory;
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment