public void Initialize(PirateGame game) { this.game = game; this.myPirates = game.GetMyLivingPirates().ToList(); // This gets overridden in MovePirates(). this.myCapsules = game.GetMyCapsules().ToList(); this.myMotherships = game.GetMyMotherships().ToList(); }
private void Initialize(PirateGame pirateGame) { game = pirateGame; FinishedTurn = new Dictionary <Pirate, bool>(); myPirates = game.GetMyLivingPirates().ToList(); scale = (((double)(game.Cols.Power(2) + game.Rows.Power(2))).Sqrt()); NumOfAssignedPiratesToWormhole = new Dictionary <Wormhole, int>(); NewWormholeLocation = new Dictionary <Wormhole, Location>(); foreach (Wormhole wormhole in game.GetAllWormholes()) { NewWormholeLocation.Add(wormhole, wormhole.Location); NumOfAssignedPiratesToWormhole.Add(wormhole, 0); } enemyCapsulesPushes = game.GetEnemyCapsules().ToDictionary(key => key, value => 0); pirateDestinations = new Dictionary <Pirate, Location>(); //bunkeringPirates = new List<Pirate>(); asteroids = new Dictionary <Asteroid, bool>(); foreach (Pirate pirate in myPirates) { FinishedTurn.Add(pirate, false); } foreach (var asteroid in game.GetLivingAsteroids()) { asteroids.Add(asteroid, false); } defense = game.GetMyMotherships().Count() == 0 || game.GetMyCapsules().Count() == 0; piratePairs = new Dictionary <Pirate, Pirate>(); }
/// <summary> Tries to interact with a Wormhole. </summary> /// <returns> A tuple with a bool and the action string </returns> protected static Tuple <bool, string> InteractWithWormHole(Pirate pirate, Location goal) { if (!game.GetAllWormholes().Any() || !game.GetMyMotherships().Any() || !Main.mines.Any() || !game.GetEnemyMotherships().Any() || pirate.PushReloadTurns > 0) { return(new Tuple <bool, string>(false, "Did not interact with a wormhole")); } foreach (Wormhole wormhole in game.GetAllWormholes().Where(w => w.InRange(pirate, pirate.PushRange + pirate.MaxSpeed))) { if (Utils.DistanceWithWormhole(pirate.Location, goal, pirate.MaxSpeed) != pirate.Distance(goal)) { return(new Tuple <bool, string>(false, "Sailing into hole is faster")); } var cloestFriendlyMum = game.GetMyMotherships().OrderBy(wormhole.Distance).First(); var cloestFriendlyMine = Main.mines.OrderBy(wormhole.Distance).First(); bool closerToMum = wormhole.Distance(cloestFriendlyMum) < wormhole.Partner.Distance(cloestFriendlyMum); bool closerToMine = wormhole.Distance(cloestFriendlyMine) < wormhole.Partner.Distance(Main.mines.OrderBy(wormhole.Partner.Distance).First()); var pushLocation = cloestFriendlyMum.Location; if (closerToMine) { pushLocation = cloestFriendlyMine; } if (closerToMum || closerToMine) { if (pirate.CanPush(wormhole)) { pirate.Push(wormhole, pushLocation); Main.wormsPushed.Add(wormhole); } else { pirate.Sail(wormhole); } Main.didTurn.Add(pirate.Id); return(new Tuple <bool, string>(true, "Interacted with Wormhole")); } } return(new Tuple <bool, string>(false, "Did not interact with a wormhole")); }
// ------------------------------------------ // Pirate functions // ------------------------------------------ private void MovePirates() { // Check if there is no mothership / capsule of ours to start playing defensive if (game.GetMyMotherships().Count() == 0 || game.GetMyCapsules().Count() == 0) { defense = true; HandleDefence(); } else { // This function will move our pirates. // The closest pirate to the capsule will go towards it. The second pirate will cover the spawn, the rest will attack the enemy pirates. // Addition 1: A number of pirates (NumPushesForCapsuleLoss) will camp the enemy mothership inbetween the capsule and the mothership myPirates = myPirates.OrderBy(pirate => pirate.Distance(myCapsules.OrderBy(capsule => capsule.Distance(pirate)).FirstOrDefault())).ToList(); // if(myPirates.Any(pirate => pirate.HasCapsule())) // { // // There is a pirate with a capsule. Make him go to the mothership // var capsuleHolder = myPirates.First(pirate => pirate.HasCapsule()); // capsuleHolder.Sail(game.GetMyMothership()); // Print("Pirate "+ capsuleHolder + " sails to "+ game.GetMyMothership()); // myPirates.Remove(capsuleHolder); // } myPirates = ManageCapsulePirates(); if (myPirates.Any()) { var currentPirate = myPirates.First(); currentPirate.Sail(GetCapsulePickupLocation()); Print("Pirate " + currentPirate + " sails to capsule at " + GetCapsulePickupLocation()); myPirates.Remove(currentPirate); } myPirates = InterceptCapsule(); // Pirates will remain unused below, only if there are no enemies. So you can simplify things a bit: if (game.GetEnemyLivingPirates().Any()) { foreach (var pirate in myPirates) { // Sort the enemies per their distance then their capsule possession. var enemies = game.GetEnemyLivingPirates() .OrderBy(enemy => enemy.Distance(pirate)) .OrderByDescending(enemy => enemy.HasCapsule()); if (!TryPush(pirate, enemies.First())) { // Sail to the pirate pirate.Sail(enemies.First()); Print("Pirate " + pirate + " sails to " + enemies.First()); } } } else { foreach (var left in myPirates) { Print("All enemy pirates are dead. Unused pirate: " + left); } } } }
private void Initialize(PirateGame game) { this.game = game; this.myPirates = game.GetMyLivingPirates().ToList(); this.myCapsules = game.GetMyCapsules().ToList(); this.myMotherships = game.GetMyMotherships().ToList(); this.enemyMotherships = game.GetEnemyMotherships().ToList(); this.enemyPirates = game.GetEnemyLivingPirates().ToList(); this.enemyCapsules = game.GetEnemyCapsules().ToList(); }
private void MovePirates() { if (!game.GetMyMotherships().Any() || !game.GetMyCapsules().Any()) { // Handle game defensively. Defence(); } else { CaptureGameplay(); } }
private void Initialize(PirateGame game) { game = game; myPirates = game.GetMyLivingPirates().ToList(); myCapsules = game.GetMyCapsules().ToList(); myMotherships = game.GetMyMotherships().ToList(); enemyMotherships = game.GetEnemyMotherships().ToList(); enemyPirates = game.GetEnemyLivingPirates().ToList(); enemyCapsules = game.GetEnemyCapsules().ToList(); asteroids = new Dictionary <Asteroid, bool>(); foreach (var asteroid in game.GetLivingAsteroids()) { asteroids.Add(asteroid, false); } }
public void DoTurn(PirateGame game) { Initialize(game); PushAsteroids(); PlantBombs(); HandleBombCarriers(); PushEnemyCapsulesAggressively(); if (!game.GetMyMotherships().Any() || !game.GetMyCapsules().Any()) { PerformDefensiveBunker(); HandleSwitchPirateStates(); } else { PerformAggressiveBunker(); HandleSwitchPirateStates(); DeliverCapsules(); CaptureCapsules(); } HandlePriorities(); PrintTargetLocations(GetAllTargetLocations()); MovePirates(); }
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"); }