override public string Preform() { if (game.GetEnemyCapsules().Count() == 0 || game.GetEnemyMotherships().Count() == 0) { return(Utils.GetPirateStatus(pirate, "No enemy capsules or ships")); } var nearestCapsule = Utils.OrderByDistance(game.GetEnemyCapsules().ToList(), pirate.Location).First(); var nearestShip = Utils.OrderByDistance(game.GetEnemyMotherships().ToList(), nearestCapsule.Location).First(); if (Main.didTurn.Contains(pirate.Id)) { return(Utils.GetPirateStatus(pirate, "Already did turn")); } if (Utils.HasEnemyBomb(pirate)) { return(Utils.GetPirateStatus(pirate, Sailing.SafeSail(pirate, new Location(0, 0)))); } var sortedEnemyHolders = Utils.EnemyHoldersByDistance(pirate.GetLocation()).Where(enemy => !Main.piratesPushed.Contains(enemy) && pirate.CanPush(enemy)); bool shouldGo = !sortedEnemyHolders.Any() || pirate.MaxSpeed * 4 + pirate.Distance(nearestShip) < sortedEnemyHolders.First().Distance(nearestShip); if (shouldGo) { foreach (Wormhole hole in game.GetAllWormholes().Where(h => h.Distance(nearestShip) < pirate.MaxSpeed * 10 && !Main.wormsPushed.Contains(h))) { var molesByDistance = Utils.PiratesWithTask(TaskType.MOLE).OrderBy(hole.Distance); bool closest = molesByDistance.First().Id == pirate.Id || (molesByDistance.Count() > 1 && molesByDistance.Take(2).Contains(pirate)); var eholdersbydistance = Utils.EnemyHoldersByDistance(nearestShip.GetLocation()); if (!pirate.CanPush(hole) && pirate.PushRange < pirate.Distance(hole) && closest) { var wormLoc = pirate.Location.Towards(hole, pirate.Distance(hole) - hole.WormholeRange); var assDanger = game.__livingAsteroids.Any(a => a.Location.Add(a.Direction).Distance(pirate) <= a.Size + pirate.MaxSpeed * 2); var bombDanger = game.__stickyBombs.Any(b => b.Distance(pirate) < b.ExplosionRange + pirate.MaxSpeed * 2); var wormPushLocation = pirate.Location.Towards(hole, pirate.Distance(hole) - pirate.PushRange); var caseI = pirate.Distance(wormPushLocation) / pirate.MaxSpeed >= pirate.PushReloadTurns; var caseII = true; if (eholdersbydistance.Any()) { caseII = hole.Distance(nearestShip) + pirate.MaxSpeed * 4 < eholdersbydistance.First().Distance(nearestShip); } if (!assDanger && !bombDanger && caseI && caseII) { pirate.Sail(wormLoc); Main.didTurn.Add(pirate.Id); return(Utils.GetPirateStatus(pirate, "Sailing out to worm hole ")); } if (caseI && caseII) { return(Utils.GetPirateStatus(pirate, "Safely sailing out to worm hole " + Sailing.SafeSail(pirate, wormLoc))); } } var enemyHolders = Utils.EnemyHoldersByDistance(pirate.GetLocation()).SkipWhile(Main.piratesPushed.Contains).OrderBy(hole.Distance); if (pirate.CanPush(hole) && hole.IsActive && enemyHolders.Any() && hole.Distance(nearestShip) < hole.Partner.Distance(nearestShip)) { foreach (Pirate enemyHolder in enemyHolders) { int cost = enemyHolder.Distance(hole) + enemyHolder.MaxSpeed / 2; if (cost < pirate.PushDistance) { pirate.Push(hole, pirate.Location.Towards(enemyHolder.Location, cost)); Main.didTurn.Add(pirate.Id); Main.piratesPushed.Add(enemyHolder); Main.wormsPushed.Add(hole); return(Utils.GetPirateStatus(pirate, "Pushed hole on enemy")); } } } if (pirate.CanPush(hole) && Main.mines.Any()) { pirate.Push(hole, Main.mines.OrderBy(nearestShip.Distance).First()); Main.didTurn.Add(pirate.Id); Main.wormsPushed.Add(hole); return(Utils.GetPirateStatus(pirate, "Pushed hole away")); } } } foreach (Pirate enemyHolder in sortedEnemyHolders) { game.Debug("pirate can push holder: " + pirate.CanPush(enemyHolder)); var killLocation = Utils.NearestKillLocation(enemyHolder.Location); double maxDistance = ((double)killLocation.Item1 + enemyHolder.MaxSpeed / 2); var canKillAlone = maxDistance / pirate.PushDistance <= 1; if (canKillAlone) { pirate.Push(enemyHolder, killLocation.Item2); Main.didTurn.Add(pirate.Id); Main.piratesPushed.Add(enemyHolder); return(Utils.GetPirateStatus(pirate, "Killed enemy holder")); } // Initialize variables var pushHelpers = game.GetMyLivingPirates().Where(h => h.CanPush(enemyHolder) && !Main.didTurn.Contains(h.Id)).OrderBy(h => h.PushDistance); var killHelpers = pushHelpers.Where(h => h.Id != pirate.Id && ((double)killLocation.Item1 + enemyHolder.MaxSpeed / 2) / ((double)h.PushDistance + pirate.PushDistance) <= 1); // If they can kill him if (killHelpers.Any()) { var partner = killHelpers.OrderByDescending(h => maxDistance / ((double)h.PushDistance + pirate.PushDistance) <= 1).First(); pirate.Push(enemyHolder, killLocation.Item2); partner.Push(enemyHolder, killLocation.Item2); Main.didTurn.AddRange(new List <int> { pirate.Id, partner.Id }); Main.piratesPushed.Add(enemyHolder); return(Utils.GetPirateStatus(pirate, "Couple killed enemy holder")); } // If they can make him drop his capsule but not kill him if (pushHelpers.Count() >= enemyHolder.NumPushesForCapsuleLoss) { var pushers = pushHelpers.Take(enemyHolder.NumPushesForCapsuleLoss).ToList(); var pushLocation = Utils.NearestKillLocation(enemyHolder.GetLocation()).Item2; if (Utils.NearestKillLocation(enemyHolder.GetLocation()).Item2.Distance(nearestCapsule) < nearestShip.Distance(nearestCapsule)) { pushLocation = nearestShip.GetLocation(); } pushers.ForEach(m => m.Push(enemyHolder, pushLocation)); Main.didTurn.AddRange(from p in pushers select p.Id); Main.piratesPushed.Add(enemyHolder); return(Utils.GetPirateStatus(pirate, enemyHolder.NumPushesForCapsuleLoss + " pirates droped the enemy capsule")); } // Boost enemy to closest dropers couple var myMoles = Utils.PiratesWithTask(TaskType.MOLE).ToList().Where(p => p.Id != pirate.Id && p.PushReloadTurns <= 1).OrderBy(p => p.Distance(nearestShip)).ToList(); var regularEnemyPirates = game.GetEnemyLivingPirates().Where(prt => !prt.HasCapsule()).ToList(); bool shouldUseBuddies = myMoles.Any() && pirate.PushRange + pirate.MaxSpeed / 2 < myMoles.OrderBy(pirate.Distance).First().Distance(pirate); bool enemyIsTerr = Utils.HasMyBomb(enemyHolder); if (regularEnemyPirates.Any() && myMoles.Count() >= 2 && shouldUseBuddies && !enemyIsTerr) { foreach (Pirate A in myMoles) { foreach (Pirate B in myMoles.Where(m => m.Id != A.Id)) { if (A.Distance(pirate) < A.PushRange * 1.5) { continue; } var centerLoc = Utils.Center(A.Location, B.Location); var pushLocation = pirate.GetLocation().Towards(centerLoc, pirate.PushDistance - enemyHolder.MaxSpeed / 2); bool checkI = pushLocation.Distance(A) <= A.PushRange && pushLocation.Distance(B) <= B.PushRange; bool checkII = enemyHolder.StateName == "normal"; // TODO add check if there is a booster close to the enemy pirate if (checkI && checkII) { pirate.Push(enemyHolder, centerLoc); Main.didTurn.Add(pirate.Id); Main.piratesPushed.Add(enemyHolder); return(Utils.GetPirateStatus(pirate, "Pushed pirates towards buddies!")); } } } } } int radius = (game.PushRange + game.HeavyPushDistance) / 3; int coupleIndex = Utils.PiratesWithTask(TaskType.MOLE).OrderBy(nearestShip.Distance).ToList().IndexOf(pirate) / 2; if (coupleIndex > 0) { radius += game.HeavyPushDistance; } var loc = nearestShip.GetLocation().Towards(nearestCapsule, radius); foreach (Pirate enemyHolder in sortedEnemyHolders) { var CheckI = enemyHolder.Distance(nearestShip) < 2 * pirate.PushRange + pirate.Distance(nearestShip); var CheckII = pirate.PushReloadTurns <= (enemyHolder.Distance(nearestShip) - pirate.Distance(nearestShip)) / (2 * enemyHolder.MaxSpeed); var CheckIII = pirate.Distance(loc) < 2 * pirate.MaxSpeed; var CheckIV = game.GetMyLivingPirates().Count(p => p.Id != pirate.Id && p.GetLocation().Col == pirate.Location.Col && p.GetLocation().Row == pirate.Location.Row) >= 1; //var CheckV = Utils.PiratesWithTask(TaskType.MOLE).OrderBy(enemyHolder.Distance).First().Id == pirate.Id; //game.Debug(CheckI + " || " + CheckII + " || " + CheckIII + " || " + CheckIV + " || "/*+ CheckV + " || "*/); if (CheckI && CheckII && CheckIII && CheckIV /* && CheckV*/) { return(Utils.GetPirateStatus(pirate, "Sailing out to enemy holder " + Sailing.SafeSail(pirate, enemyHolder.GetLocation()))); } } return(Utils.GetPirateStatus(pirate, "Is sailing to position, " + Sailing.SafeSail(pirate, loc))); }
override public string Preform() { if (Main.didTurn.Contains(pirate.Id) || !game.GetMyMotherships().Any()) { return(Utils.GetPirateStatus(pirate, "Already did turn")); } if (!pirate.HasCapsule()) { turnCounter = 0; if (Main.capsulesTargetted.ContainsKey(pirate)) { var sailLocation = Main.capsulesTargetted[pirate].Location; return(Utils.GetPirateStatus(pirate, "Sailing to capsule " + Sailing.SafeSail(pirate, sailLocation))); } return(Utils.GetPirateStatus(pirate, "Is idle... ")); } var nearestShip = Utils.OrderByDistance(game.GetMyMotherships().ToList(), pirate.Location).First(); var threats = game.GetEnemyLivingPirates().ToList().Where(e => e.PushReloadTurns < 3 && e.Distance(nearestShip) < pirate.Distance(nearestShip)).OrderBy(nearestShip.Distance).ToList(); if (Utils.HasEnemyBomb(pirate)) { var suicideObj = Utils.NearestKillLocation(pirate.GetLocation()).Item2; var bomb = game.__stickyBombs.OrderBy(pirate.Distance).First(); bool canReachMum = pirate.Distance(nearestShip) / pirate.MaxSpeed + pirate.MaxSpeed < bomb.Countdown; if (!canReachMum) { return(Utils.GetPirateStatus(pirate, Sailing.SafeSail(pirate, new Location(0, 0)))); } } turnCounter++; if (turnCounter == 0) { maxTurnsToArrive = ((double)pirate.Distance(nearestShip) / pirate.MaxSpeed) * 2.5; } if (Utils.GetMyHolders().Count() > 1) { var secondHolder = Utils.GetMyHolders().Where(h => h.Id != pirate.Id).First(); var nearestShipToSecondHolder = Utils.OrderByDistance(game.GetMyMotherships().ToList(), secondHolder.Location).First(); var secondThreats = game.GetEnemyLivingPirates().ToList().Where(e => e.CanPush(secondHolder) && e.Distance(nearestShip) < secondHolder.Distance(nearestShip)); secondThreats = secondThreats.OrderBy(treath => treath.Distance(secondHolder)).ToList(); bool caseVI = secondHolder.Distance(nearestShip) < pirate.Distance(nearestShip); bool caseVII = secondHolder.Distance(nearestShip) < pirate.PushDistance + secondHolder.MaxSpeed + game.MothershipUnloadRange; if (pirate.CanPush(secondHolder) && caseVI && caseVII && !Main.piratesPushed.Contains(secondHolder)) { pirate.Push(secondHolder, nearestShipToSecondHolder); Main.didTurn.Add(pirate.Id); Main.piratesPushed.Add(secondHolder); return(Utils.GetPirateStatus(pirate, "Boosted second holder")); } } var traits = new List <Trait>() { new TraitRateByLazyAsteroid(game.PushDistance + game.AsteroidSize), new TraitRateByMovingAsteroid(game.HeavyPushDistance / 2 + game.PirateMaxSpeed * 3), new TraitRateByEdges(750, 4), new TraitRateByStickyBomb(), new TraitRateByEnemy(150, 3, -1), new TraitAttractedToGoal(500, nearestShip.Location), new TraitWormhole(nearestShip.Location, pirate) }; if (threats.Any() && maxTurnsToArrive < turnCounter && Utils.GetNumOfEnemyPiratesOnPoint(threats.First().Location) >= 4) { pirate.Sail(nearestShip); Main.didTurn.Add(pirate.Id); return(Utils.GetPirateStatus(pirate, "Kamikazad on ship")); } int abstainRadius = 8 * pirate.MaxSpeed; if (Utils.GetMyHolders().Count() > 1) { var secondHolder = Utils.GetMyHolders().First(h => h.Id != pirate.Id); abstainRadius = 3 * (pirate.MaxSpeed + secondHolder.MaxSpeed); if (abstainRadius / 2 < pirate.Distance(nearestShip)) { traits.Add(new TraitRateByEnemy(abstainRadius, 100, secondHolder.UniqueId)); } } var path = new Path(pirate.GetLocation(), nearestShip.Location, traits); bool nearWormHole = game.__wormholes.Any() && game.__wormholes.Any(w => w.TurnsToReactivate <= 2 && pirate.Distance(w) < w.WormholeRange + pirate.MaxSpeed); bool safe = (threats.Any() && game.PushDistance + game.AsteroidSize <= threats.OrderBy(pirate.Distance).First().Distance(pirate)) && !game.GetLivingAsteroids().Any(a => a.Distance(pirate) <= a.Size + pirate.MaxSpeed * 2); if (!nearWormHole && safe && (!threats.Any() && pirate.Distance(nearestShip) < abstainRadius || pirate.Distance(nearestShip) <= Chunk.size || path.GetSailLocations().Count <= 1)) { pirate.Sail(nearestShip); Main.didTurn.Add(pirate.Id); return(Utils.GetPirateStatus(pirate, "Sailing directly to ship")); } Location pathPopLocation = path.Pop(); Location nextSailLocation = pathPopLocation; if (Utils.GetMyHolders().Count() > 1 && safe && threats.Count() >= pirate.NumPushesForCapsuleLoss) { var otherMiner = Utils.GetMyHolders().First(h => h.Id != pirate.Id); bool sameTargetShip = Utils.OrderByDistance(game.GetMyMotherships().ToList(), otherMiner.Location).First() == nearestShip; bool checkI = pirate.Distance(nearestShip) < otherMiner.Distance(nearestShip); bool checkII = Chunk.size * 4 < otherMiner.Distance(nearestShip) - pirate.Distance(nearestShip); if (sameTargetShip && checkI && checkII) { nextSailLocation = pirate.Location.Towards(pathPopLocation, pirate.MaxSpeed / 2); } } if (Utils.PiratesWithTask(TaskType.BOOSTER).Any() && safe) { var closestBooster = Utils.OrderByDistance(Utils.PiratesWithTask(TaskType.BOOSTER), pirate.Location).First(); bool cloestToBooster = Utils.OrderByDistance(Utils.GetMyHolders(), closestBooster.Location).First().Id == pirate.Id; bool checkI = threats.Any() && threats.First().MaxSpeed * 2 <= threats.First().Distance(pirate); if (cloestToBooster && game.PushRange < pirate.Distance(closestBooster) && checkI) { nextSailLocation = pirate.Location.Towards(pathPopLocation, closestBooster.MaxSpeed / 2); } } return(Utils.GetPirateStatus(pirate, "Sailing to goal, " + Sailing.SafeSail(pirate, nextSailLocation.GetLocation()))); }
override public string Preform() { if (!Utils.GetMyHolders().Any() || !game.GetMyCapsules().Any() || !game.GetAllMotherships().Any()) { if (Main.mines.Count > 0 && game.GetMyMotherships().Any()) { var sailLocation = Utils.GetMyHolders().OrderBy(h => h.Distance(pirate)).First().Location; return(Utils.GetPirateStatus(pirate, "Sailing to rendezvous point, " + Sailing.SafeSail(pirate, sailLocation))); } return(Utils.GetPirateStatus(pirate, "Is idle.")); } var holders = Utils.GetMyHolders().OrderBy(h => h.Distance(pirate)); var cloestHolder = holders.First(); foreach (Pirate holder in Utils.GetMyHolders().OrderBy(h => h.Distance(pirate))) { var nearestShip = Utils.OrderByDistance(game.GetMyMotherships().ToList(), holder.Location).First(); if (!pirate.CanPush(holder)) { var sailLocation = Utils.GetMyHolders().OrderBy(h => h.Distance(pirate)).First().Location; return(Utils.GetPirateStatus(pirate, "Sailing towards holder, " + Sailing.SafeSail(pirate, sailLocation))); } var threats = game.GetEnemyLivingPirates().Where(t => t.PushReloadTurns > 2 && t.Distance(nearestShip) < pirate.Distance(nearestShip) * 1.5).OrderBy(nearestShip.Distance); // Checks if the holder can be pushed directly onto the ship bool caseI = holder.Distance(nearestShip) - game.MothershipUnloadRange <= pirate.PushDistance + holder.MaxSpeed; bool caseII = false; if (threats.Any() && threats.First().Distance(nearestShip) > holder.Distance(nearestShip)) { caseII = holder.Distance(nearestShip) - threats.First().Distance(nearestShip) < pirate.PushRange; } var holderLocAfterPush = holder.GetLocation().Towards(nearestShip, pirate.PushDistance + holder.MaxSpeed / 2); bool caseIII_PI = threats.Any() && threats.First().Distance(nearestShip) < holder.Distance(nearestShip); bool caseIII_PII = threats.Any() && threats.First().PushRange < holderLocAfterPush.Distance(threats.First()); bool ImminentDeath = game.GetEnemyLivingPirates().Count(t => holder.InRange(t, holder.MaxSpeed + t.PushRange) && t.PushReloadTurns <= 1) >= holder.NumPushesForCapsuleLoss; if (ImminentDeath && !caseI && holder.MaxSpeed * 10 < holder.Distance(nearestShip)) { var safest = Sailing.SafestCloestLocation(holder.Location, nearestShip.Location, 2, true, pirate); pirate.Push(holder, safest); Main.piratesPushed.Add(holder); Main.didTurn.Add(pirate.Id); if (!Main.didTurn.Contains(holder.Id)) { holder.Push(pirate, safest); Main.piratesPushed.Add(pirate); Main.didTurn.Add(holder.Id); } return(Utils.GetPirateStatus(pirate, "Moved away from danger zone")); } bool caseIII = threats.Any() && caseIII_PI && caseIII_PII && ImminentDeath; game.Debug(caseI + " || " + caseII + " || " + caseIII + " +| IMD: " + ImminentDeath); if (caseI || caseIII) { if (Utils.GetMyHolders().Count() > 1) { var secondHolder = Utils.GetMyHolders().First(h => h.Id != holder.Id); if (!Main.didTurn.Contains(holder.Id) && holder.CanPush(secondHolder) && !Main.piratesPushed.Contains(secondHolder) && secondHolder.Distance(nearestShip) - nearestShip.UnloadRange < pirate.PushDistance + secondHolder.MaxSpeed) { holder.Push(secondHolder, nearestShip); Main.piratesPushed.Add(secondHolder); pirate.Push(holder, nearestShip); Main.piratesPushed.Add(holder); if (!Main.didTurn.Contains(secondHolder.Id) && holder.NumPushesForCapsuleLoss > 2 && secondHolder.CanPush(holder)) { secondHolder.Push(holder, nearestShip); Main.piratesPushed.Add(holder); } Main.didTurn.Add(holder.Id); Main.didTurn.Add(pirate.Id); return(Utils.GetPirateStatus(pirate, "Pushed holder to the motherShip while the holder boosted another holder")); } } if (!Main.didTurn.Contains(holder.Id)) { holder.Sail(nearestShip); Main.didTurn.Add(holder.Id); } pirate.Push(holder, nearestShip); Main.didTurn.Add(pirate.Id); Main.piratesPushed.Add(holder); return(Utils.GetPirateStatus(pirate, "Pushed holder directly to ship")); } Main.holdersPaired.Add(holder); return(Utils.GetPirateStatus(pirate, "Sailing towards paired holder, " + Sailing.SafeSail(pirate, holder.Location))); } return("Did nothing"); }