static void TestTravelTime() { var calculator = new TravelCalculator(1.0f, 1.0f); var start = new Village { X = 200, Y = 200 }; var end = new Village { X = 210, Y = 220 }; var troopsWithTimes = Enum.GetValues(typeof(TroopType)).Cast <TroopType>().Where(t => t != TroopType.Militia).ToDictionary(t => t, t => calculator.CalculateTravelTime(t, start, end)); var offsets = new[] { TimeSpan.FromSeconds(5), TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(30), TimeSpan.FromMinutes(60) }; foreach (var o in offsets) { Console.WriteLine("With offset of {0} minutes", o.TotalMinutes); foreach (var kvp in troopsWithTimes) { var type = kvp.Key; var time = kvp.Value; var modifiedTime = time - o; var estimate = calculator.EstimateTroopType(modifiedTime, start, end); Console.WriteLine("- For {0} (speed={1}) estimated as {2} (speed={3})", type, ArmyStats.TravelSpeed[type], estimate, ArmyStats.TravelSpeed[estimate]); } } }
public bool MeetsRequirement(decimal worldSpeed, decimal travelSpeed, Coordinate source, Coordinate target, Army army) { var calculator = new TravelCalculator(worldSpeed, travelSpeed); var fieldSpeed = calculator.ArmyFieldSpeed(army); return(fieldSpeed * source.DistanceTo(target) <= MaximumTime); }
public List <CommandInstruction> GenerateOptions(Dictionary <Scaffold.Village, Scaffold.CurrentVillage> availableVillages, Scaffold.Village target) { var result = new List <CommandInstruction>(); var travelCalculator = new TravelCalculator(worldSpeed, unitSpeed); if (availableVillages == null) { throw new ArgumentNullException(nameof(availableVillages)); } foreach ((var source, var currentVillage) in availableVillages.Tupled()) { if (source == null) { throw new ArgumentNullException("source"); } if (currentVillage == null) { throw new ArgumentNullException("currentVillage"); } var villageArmy = ArmyConvert.ArmyToJson(currentVillage.ArmyAtHome); if (villageArmy == null || villageArmy.IsEmpty()) { continue; } foreach (var permutation in ArmyPermutations(villageArmy)) { if (Requirements.Any(r => !r.MeetsRequirement(worldSpeed, unitSpeed, source.Coordinates(), target.Coordinates(), permutation))) { continue; } var travelTroopType = travelCalculator.TravelTroopType(permutation); result.Add(new CommandInstruction { SendFrom = source.VillageId, SendTo = target.VillageId, TroopType = travelTroopType, TravelTime = travelCalculator.CalculateTravelTime(travelTroopType, source, target) }); } } return(result); }