public void GoogleSampleThreeTribes() { Attacks attacks = new Attacks(); Assert.AreEqual(6, attacks.Count(new Tribe[] { new Tribe(1, 2, 0, 5, 10, 2, 8, 0), new Tribe(0, 3, 0, 1, 7, 1, 2, 2), new Tribe(3, 3, 0, 5, 1, 1, 4, 0) })); }
public static void Main(string[] args) { string inputname = args[0]; string outputname = args[1]; string[] lines = File.ReadAllLines(inputname); int ncases = int.Parse(lines[0]); int nline = 0; IList<string> results = new List<string>(); Attacks attacks = new Attacks(); for (int k = 0; k < ncases; k++) { Console.WriteLine(string.Format("Solving Case #{0}", k + 1)); nline++; int ntribes = int.Parse(lines[nline]); IList<Tribe> tribes = new List<Tribe>(); for (int j = 0; j < ntribes; j++) { nline++; string[] words = lines[nline].Split(' '); int day = int.Parse(words[0]); int nattacks = int.Parse(words[1]); int west = int.Parse(words[2]); int east = int.Parse(words[3]); int strength = int.Parse(words[4]); int ddays = int.Parse(words[5]); int ddistance = int.Parse(words[6]); int dstrength = int.Parse(words[7]); Tribe tribe = new Tribe(day, nattacks, west, east, strength, ddays, ddistance, dstrength); tribes.Add(tribe); } int count = attacks.Count(tribes); results.Add(string.Format("Case #{0}: {1}", k + 1, count)); } File.WriteAllLines(outputname, results.ToArray()); }
public override string ToString() { return(string.Format("Target={0}, ArrivalTime={1}, Attacks={2}", Target.LocationString, ArrivalTime.ToString("dd/MM hh:mm:ss"), Attacks.Count())); }
public void OneTribe() { Attacks attacks = new Attacks(); Assert.AreEqual(10, attacks.Count(new Tribe[] { new Tribe(10, 10, 0, 2, 6, 4, 3, 1) })); }
public void NoTribes() { Attacks attacks = new Attacks(); Assert.AreEqual(0, attacks.Count(new Tribe[] { })); }
public void GoogleSampleTwoTribes() { Attacks attacks = new Attacks(); Assert.AreEqual(5, attacks.Count(new Tribe[] { new Tribe(0, 3, 0, 2, 10, 2, 3, -2), new Tribe(10, 3, 2, 3, 8, 7, 2, 0) })); }
private void UpdateAttacks(CocApi cocApi, IWar?downloadedWar) { ICurrentWarApiModel?currentWar = downloadedWar as ICurrentWarApiModel; if (currentWar == null || currentWar.WarId != WarId) { return; } List <AttackApiModel> newAttacks = currentWar.Attacks.Where(a => a.Order > Attacks.Count()).ToList(); //foreach (AttackApiModel attack in downloadedWar.Attacks) //{ // if (!Attacks.Any(a => a.Order == attack.Order)) // { // Attacks.Add(attack); // } //} //foreach (WarClanApiModel clan in Clans) //{ // foreach (WarVillageApiModel warVillage in clan.Villages.EmptyIfNull()) // { // foreach (AttackApiModel downloadedAttack in downloadedWar.Attacks.Where(a => a.AttackerTag == warVillage.VillageTag)) // { // if (!warVillage.Attacks.Any(a => a.Order == downloadedAttack.Order)) // { // if (warVillage.Attacks == null) // { // warVillage.Attacks = new List<AttackApiModel>(); // } // warVillage.Attacks.Add(downloadedAttack); // } // } // } //} //foreach (var clan in Clans) //{ // clan.AttackCount = downloadedWar.Clans.First(c => c.ClanTag == clan.ClanTag).AttackCount; // clan.DefenseCount = downloadedWar.Clans.First(c => c.ClanTag == clan.ClanTag).DefenseCount; // clan.DestructionPercentage = downloadedWar.Clans.First(c => c.ClanTag == clan.ClanTag).DestructionPercentage; // clan.Stars = downloadedWar.Clans.First(c => c.ClanTag == clan.ClanTag).Stars; //} cocApi.NewAttacksEvent(currentWar, newAttacks); }
public void Initialize() { Clans = Clans.OrderBy(x => x.ClanTag).ToList(); WarId = $"{PreparationStartTimeUtc};{Clans[0].ClanTag}"; //ClanTag1 = Clans.First().ClanTag; Flags.WarId = WarId; TimeSpan timeSpan = StartTimeUtc - PreparationStartTimeUtc; if (timeSpan.TotalHours == 24 || timeSpan.TotalHours == 20 || timeSpan.TotalHours == 16 || timeSpan.TotalHours == 12 || timeSpan.TotalHours == 8 || timeSpan.TotalHours == 6 || timeSpan.TotalHours == 4 || timeSpan.TotalHours == 2 || timeSpan.TotalHours == 1 || timeSpan.TotalMinutes == 30 || timeSpan.TotalMinutes == 15) { WarType = WarType.Friendly; } if (WarIsOverOrAllAttacksUsed()) { if (Clans[0].Stars == Clans[1].Stars) { if (Clans[0].DestructionPercentage == Clans[1].DestructionPercentage) { Clans[0].Result = Result.Draw; Clans[1].Result = Result.Draw; } else if (Clans[0].DestructionPercentage > Clans[1].DestructionPercentage) { Clans[0].Result = Result.Win; Clans[1].Result = Result.Lose; } else { Clans[0].Result = Result.Lose; Clans[1].Result = Result.Win; } } else if (Clans[0].Stars > Clans[1].Stars) { Clans[0].Result = Result.Win; Clans[1].Result = Result.Lose; } else { Clans[0].Result = Result.Lose; Clans[1].Result = Result.Win; } } foreach (WarClanApiModel clan in Clans) { foreach (WarVillageApiModel warVillage in clan.Villages.EmptyIfNull()) { foreach (AttackApiModel attack in warVillage.Attacks.EmptyIfNull()) { if (!Attacks.Any(a => a.Order == attack.Order)) { Attacks.Add(attack); } } } } Attacks = Attacks.OrderBy(a => a.Order).ToList(); var attacksByDefenderTag = Attacks.GroupBy(a => a.DefenderTag); foreach (var defendingVillage in attacksByDefenderTag) { defendingVillage.OrderBy(d => d.Order).First().Fresh = true; } foreach (var attack in Attacks) { foreach (var clan in Clans) { WarVillageApiModel?attacker = clan.Villages.FirstOrDefault(m => m.VillageTag == attack.AttackerTag); if (attacker != null) { attack.AttackerClanTag = clan.ClanTag; } WarVillageApiModel?defender = clan.Villages.FirstOrDefault(m => m.VillageTag == attack.DefenderTag); if (defender != null) { attack.DefenderClanTag = clan.ClanTag; } } } foreach (WarClanApiModel clan in Clans) { clan.DefenseCount = Attacks.Count(a => a.DefenderClanTag == clan.ClanTag); } }