// ------------------------------------------ // 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); } } } }
/// <summary> /// Creates a new PirateGameEx, initialized with a game turn state /// Initializes lists of game objects /// </summary> /// <param name="pirateGame">Current game turn state</param> public PirateGameEx(PirateGame pirateGame) { Game = pirateGame; // PirateEx lists MyPirates = CreateExList(Game.GetAllMyPirates()); MyLivingPirates = CreateExList(Game.GetMyLivingPirates()); EnemyPirates = CreateExList(Game.GetAllEnemyPirates()); EnemyLivingPirates = CreateExList(Game.GetEnemyLivingPirates()); // IslandEx lists MyIslands = CreateExList(Game.GetMyIslands()); NeutralIslands = CreateExList(Game.GetNeutralIslands()); EnemyIslands = CreateExList(Game.GetEnemyIslands()); // DroneEx lists MyLivingDrones = CreateExList(Game.GetMyLivingDrones()); EnemyLivingDrones = CreateExList(Game.GetEnemyLivingDrones()); // CityEx lists MyCities = CreateExList(Game.GetMyCities()); EnemyCities = CreateExList(Game.GetEnemyCities()); // AircraftEx lists MyLivingAircrafts = CreateExList(Game.GetMyLivingAircrafts()); EnemyLivingAircrafts = CreateExList(Game.GetEnemyLivingAircrafts()); MyAircrafts = ConvertList <PirateEx, AircraftEx>(MyPirates).Concat(ConvertList <DroneEx, AircraftEx>(MyLivingDrones)).ToList(); EnemyAircrafts = ConvertList <PirateEx, AircraftEx>(EnemyPirates).Concat(ConvertList <DroneEx, AircraftEx>(EnemyLivingDrones)).ToList(); }
private Pirate defendFrom(PirateGame game) { List <Pirate> enemiesByDistanceFromEnemyBase = game.GetEnemyLivingPirates().ToList(); enemiesByDistanceFromEnemyBase.OrderBy(Pirate => Pirate.Location.Distance(game.GetEnemyMothership().Location)); List <Pirate> potentialThreat = new List <Pirate>(); potentialThreat.Add(null); foreach (Pirate pirate in enemiesByDistanceFromEnemyBase) { if (pirate.Distance(game.GetEnemyMothership()) < 2000) { if (potentialThreat[0] == null) { ; } potentialThreat[0] = pirate; } } if (potentialThreat != null) { return(potentialThreat[0]); } else { return(null); } }
public static int FindSafeSpot(List <Location> sailOptions, PirateGame game) { //Week 1: if (game.GetOpponentName() == "11999" || game.GetOpponentName() == "12000" || game.GetOpponentName() == "12001" || game.GetOpponentName() == "12002" || game.GetOpponentName() == "12003" || game.GetOpponentName() == "12004" || game.GetOpponentName() == "12005" || game.GetOpponentName() == "12006") { return(sailOptions.Count - 1); } bool safe = true; int option = 0; if (game.GetOpponentName() == "12109" || game.GetOpponentName() == "12220") { return(sailOptions.Count - 1); } for (int i = 0; i < sailOptions.Count; i++) { // Go over enemy pirates foreach (Pirate enemy in game.GetEnemyLivingPirates()) { // If the sail option is in the pirate's attack range, option isn't safe if (enemy.InRange(sailOptions[i], 8)) { safe = false; } } // If option is safe, stop looking for options. if not, set option to current option if (safe) { option = i; break; } } // Return option return(option); }
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(); }
public static bool TryAttack(Pirate pirate, PirateGame game) { if (game.GetOpponentName() == "12220" || game.GetOpponentName() == "12224" || game.GetOpponentName() == "12109" || game.GetOpponentName() == "12111") { // Go over all enemies foreach (Aircraft enemy in game.GetEnemyLivingAircrafts()) { // Check if the enemy is in attack range and he's not our decoy if (enemy != game.GetMyDecoy() && pirate.InAttackRange(enemy)) { // Fire! game.Attack(pirate, enemy); // Print a message game.Debug("pirate " + pirate + " attacks " + enemy); // Did attack return(true); } } } else { // Go over all enemy drones foreach (Drone enemy in game.GetEnemyLivingDrones()) { // Check if the enemy is in attack range and he's not our decoy if (pirate.InAttackRange(enemy)) { // Fire! game.Attack(pirate, enemy); // Print a message game.Debug("pirate " + pirate + " attacks " + enemy); // Did attack return(true); } } //Go over all enemy pirates foreach (Pirate enemy in game.GetEnemyLivingPirates()) { // Check if the enemy is in attack range and he's not our decoy if (enemy != game.GetMyDecoy() && pirate.InAttackRange(enemy)) { // Fire! game.Attack(pirate, enemy); // Print a message game.Debug("pirate " + pirate + " attacks " + enemy); // Did attack return(true); } } } // Didn't attack return(false); }
private void Defence() { foreach (var pirate in game.GetMyLivingPirates()) { // Get the closest enemy capsule. var closestCapsule = game.GetEnemyCapsules().OrderBy(capsule => capsule.Distance(pirate)).FirstOrDefault(); if (closestCapsule != null) { // Get the person who holds the capsule. var capsuleHolder = game.GetEnemyLivingPirates().Where(enemy => enemy.HasCapsule() && enemy.Capsule.Equals(closestCapsule)).FirstOrDefault(); var closestMothership = game.GetEnemyMotherships().OrderBy(mothership => mothership.Distance(closestCapsule)).FirstOrDefault(); if (capsuleHolder != null) { // There is a capsule holder. Attempt push. if (!DefensivePush(pirate, capsuleHolder)) { // Go towards the capsule's location between the closest mothership to the capsule as well. if (closestMothership != null) { // Go inbetween. pirate.Sail(closestMothership.Location.Towards(capsuleHolder, (int)(game.MothershipUnloadRange * 0.5))); Print("Pirate " + pirate.ToString() + " sails towards " + closestMothership.Location.Towards(capsuleHolder, (int)(game.MothershipUnloadRange * 0.5))); } else { // Leave the capsule holder. They dont have a mothership. Go do something else. } } } else { // No capsule holder. Regardless, go between. pirate.Sail(closestMothership.Location.Towards(closestCapsule, (int)(game.MothershipUnloadRange * 0.5))); Print("Pirate " + pirate.ToString() + " sails towards " + closestMothership.Location.Towards(closestCapsule, (int)(game.MothershipUnloadRange * 0.5))); } } } }
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); } }
private bool PushCarrier(Pirate pirate, PirateGame game) { // Go over all enemies. foreach (Pirate enemy in game.GetEnemyLivingPirates()) { // Check if the pirate can push the enemy. if (pirate.CanPush(enemy) && enemy.HasCapsule()) { // Push enemy! pirate.Push(enemy, enemy.InitialLocation); // Print a message. System.Console.WriteLine("pirate " + pirate + " pushes " + enemy + " towards " + enemy.InitialLocation); // Did push. return(true); } } // Didn't push. return(false); }
public void DoTurn(PirateGame game) { Globals.Game = game; Globals.Drones = new DroneGroups(); // Debug initialization if (Globals.Game.GetTurn() == 1) { Globals.Game.Debug(" - Javier, v3.0.0"); } // Handle challenges Debug.Write("Opponent: " + Globals.Game.GetOpponentName()); if (Challenge.Handle(Globals.Game.GetOpponentName())) { return; } // Handle enemy decoy DecoyDetector.Update(game.GetEnemyLivingPirates()); DecoyDetector.Detect(); // Move drones towards home DroneHandler.Handle(); // Handle friendly decoy int id = -1; DecoyHandler.Handle(ref id); // Handle pirates HandlePirates(id); // Handle decoy movement HandleDecoyMovement(); }
public static Location GetTargetPirate(Pirate pirate, PirateGame game) { try { return(game.GetNotMyIslands().OrderBy(c => c.Distance(pirate)).ToList()[0].Location); } catch { return(game.GetEnemyLivingPirates().OrderBy(p => p.Distance(pirate)).ToList()[0].Location); } }
public static List <Pirate> GetEnemyLivingPiratesWithoutDecoy(this PirateGame game) { return(game.GetEnemyLivingPirates().RemoveDecoyFromList()); }
/// <summary> Sails to goal safely </summary> /// <returns> A tuple with bool and the action string </returns> public static string SafeSail(Pirate pirate, Location to) { if (Main.didTurn.Contains(pirate.Id)) { return("Already did turn"); } if (Utils.HasEnemyBomb(pirate)) { var bomb = game.__stickyBombs.Where(b => b.Owner == game.GetEnemy()).OrderBy(pirate.Distance).First(); if (bomb.Countdown < 2) { foreach (Pirate enemy in game.GetEnemyLivingPirates().Where(pirate.CanPush).SkipWhile(Main.piratesPushed.Contains).OrderBy(pirate.Distance)) { pirate.Push(enemy, pirate); Main.didTurn.Add(pirate.Id); return("Hugged an enemy to death"); } } foreach (Pirate enemy in game.GetEnemyLivingPirates().OrderBy(pirate.Distance)) { double turnsToArrive = pirate.Distance(enemy) / pirate.MaxSpeed; var shouldSail = (game.GetMyLivingPirates().Count(p => p.InRange(pirate, bomb.ExplosionRange)) - game.GetEnemyLivingPirates().Count(e => e.InRange(pirate, bomb.ExplosionRange))) <= 0; if (shouldSail) { pirate.Sail(enemy); Main.didTurn.Add(pirate.Id); return("Sailing to bomb enemy"); } } Main.didTurn.Add(pirate.Id); return("Stop!"); } var dangerPirates = game.GetMyLivingPirates().ToList(); dangerPirates.AddRange(game.GetEnemyLivingPirates().ToList()); dangerPirates = dangerPirates.Where(p => (Utils.HasEnemyBomb(p) || Utils.HasMyBomb(p)) && p.StickyBombs.First().Countdown <= 2 && pirate.CanPush(p)).ToList(); foreach (Pirate prt in dangerPirates) { pirate.Push(prt, Utils.OptimalBomberPushLocation(pirate, prt)); Main.didTurn.Add(pirate.Id); return("Pushed bomber away"); } var interactWithAsteroid = InteractWithAsteroid(pirate, to); if (interactWithAsteroid.Item1) { return(interactWithAsteroid.Item2); } if (!Utils.PiratesWithTask(TaskType.MOLE).Contains(pirate)) { var killEnemy = TryKill(pirate); if (killEnemy.Item1) { return(killEnemy.Item2); } } var enemys = game.GetEnemyLivingPirates().OrderBy(p => p.Distance(pirate)).ToList(); if (enemys.Any() && pirate.InStickBombRange(enemys.First()) && game.GetMyself().TurnsToStickyBomb == 0) { //pirate.StickBomb(enemys.First()); //Main.didTurn.Add(pirate.Id); //return "Stick bombed enemy holder"; } var interactWithWormHole = InteractWithWormHole(pirate, to); if (interactWithWormHole.Item1) { return(interactWithWormHole.Item2); } var objects = new List <MapObject>(); objects.AddRange(Utils.AsteroidsByDistance(pirate.Location).Where(ass => ass.Direction.Add(ass.Location).Distance(pirate) <= 4 * pirate.MaxSpeed + ass.Size)); objects.AddRange(game.GetActiveWormholes().Where(hole => hole.Distance(pirate.GetLocation()) <= 4 * Chunk.size)); objects.AddRange(game.GetAllStickyBombs().Where(bomb => bomb.Distance(pirate) < 1.5 * bomb.ExplosionRange + pirate.MaxSpeed)); objects = objects.OrderBy(obj => obj.Distance(pirate)).ToList(); if (!objects.Any()) { pirate.Sail(to); Main.didTurn.Add(pirate.Id); return("Sailing safely directly to goal i.e. " + Chunk.GetChunk(to)); } var traits = new List <Trait>() { new TraitRateByLazyAsteroid(game.HeavyPushDistance), new TraitRateByMovingAsteroid(game.HeavyPushDistance / 2 + game.PirateMaxSpeed * 3), new TraitWormhole(to, pirate), new TraitRateByStickyBomb() }; Path path = new Path(pirate.Location, to, traits); if (path.GetSailLocations().Count > 1) { pirate.Sail(path.Pop()); Main.didTurn.Add(pirate.Id); return(Chunk.GetChunk(to).ToString()); } pirate.Sail(to); Main.didTurn.Add(pirate.Id); return(Chunk.GetChunk(to).ToString()); }
public void HandlePirates(PirateGame game) { foreach (Pirate pirate in game.GetMyLivingPirates()) { if (!TryPush(pirate, game)) { if (game.GetMyCapsule().Holder == null) //WE HAVE NO CAPSULE { if (pirate == xClosestToY(game.GetMyCapsule(), game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate) { pirate.Sail(game.GetMyCapsule().InitialLocation); } else if (game.GetEnemyCapsule().Holder == null) //WE DONT HAVE, ENEMY DONT HAVE CAPSULE { System.Console.WriteLine($"STATE: WE DONT HAVE, ENEMY DONT HAVE"); if (pirate == xClosestToY(game.GetMyCapsule(), game.GetMyLivingPirates().Cast <GameObject>().ToList())[1] as Pirate) { Pirate first = xClosestToY(game.GetMyCapsule(), game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate; pirate.Sail(first); } // SENDS CLOSEST PIRATE 1&2 TO- CLOSEST ENEMY TO CLOSEST ENEMY CAPSULE else if (xClosestToY(xClosestToY(game.GetEnemyCapsule().InitialLocation, game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate == pirate || xClosestToY(xClosestToY(game.GetEnemyCapsule().InitialLocation, game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate, game.GetMyLivingPirates().Cast <GameObject>().ToList())[1] as Pirate == pirate) { pirate.Sail(xClosestToY(game.GetEnemyCapsule().InitialLocation, game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate); } else { pirate.Sail(xClosestToY(xClosestToY(game.GetMyCapsule(), game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate, game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate); } } else //WE NO HAVE, ENEMY HAVE CAPSULE { System.Console.WriteLine($"STATE: WE DONT HAVE, ENEMY HAVE"); if (pirate == xClosestToY(game.GetMyCapsule(), game.GetMyLivingPirates().Cast <GameObject>().ToList())[1] as Pirate) { Pirate first = xClosestToY(game.GetMyCapsule(), game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate; pirate.Sail(first); } else { pirate.Sail(game.GetEnemyCapsule().Holder); } } } // SEMI DONE else //WE HAVE CAPSULE { if (pirate.HasCapsule()) { pirate.Sail(game.GetMyMothership()); } else if (game.GetEnemyCapsule().Holder == null) //WE HAVE, ENEMY DONT HAVE CAPSULE { System.Console.WriteLine($"STATE: WE HAVE, ENEMY DONT HAVE"); // IF SHAMEN CHECKS IF A PIRATE IS THE CLOSEST TO INITIAL OF CAPSULE AND PERFECT ROTATION POSSIBLE and CHECKS FOR CLOSEST PIRATE if (game.GetMyCapsule().Holder.Distance(game.GetMyMothership()) + game.GetMyMothership().Distance(game.GetMyCapsule().InitialLocation) > game.GetMyCapsule().InitialLocation.Distance(xClosestToY(game.GetMyCapsule().InitialLocation, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate) && pirate == xClosestToY(game.GetMyMothership(), game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate) { pirate.Sail(game.GetMyCapsule().InitialLocation); } else if (xClosestToY(game.GetMyCapsule().Holder, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate == pirate) { pirate.Sail(game.GetMyCapsule().Holder); } // SENDS CLOSEST PIRATE 1&2 TO- CLOSEST ENEMY TO CLOSEST ENEMY CAPSULE else if (xClosestToY(xClosestToY(game.GetEnemyCapsule().InitialLocation, game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate == pirate || xClosestToY(xClosestToY(game.GetEnemyCapsule().InitialLocation, game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate, game.GetMyLivingPirates().Cast <GameObject>().ToList())[1] as Pirate == pirate) { pirate.Sail(xClosestToY(game.GetEnemyCapsule().InitialLocation, game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate); } else // ALL OTHER PIRATES (NOT DONE BITCHLAL) { pirate.Sail(xClosestToY(xClosestToY(game.GetMyCapsule(), game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate, game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate); } } else //WE HAVE, ENEMY HAVE CAPSULE { System.Console.WriteLine($"STATE: WE HAVE, ENEMY HAVE"); // IF SHAMEN CHECKS IF A PIRATE IS THE CLOSEST TO INITIAL OF CAPSULE AND PERFECT ROTATION POSSIBLE and CHECKS FOR CLOSEST PIRATE if (game.GetMyCapsule().Holder.Distance(game.GetMyMothership()) + game.GetMyMothership().Distance(game.GetMyCapsule().InitialLocation) > game.GetMyCapsule().InitialLocation.Distance(xClosestToY(game.GetMyCapsule().InitialLocation, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate) && pirate == xClosestToY(game.GetMyMothership(), game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate) { pirate.Sail(game.GetMyCapsule().InitialLocation); } else if (xClosestToY(game.GetMyCapsule().Holder, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate == pirate) { pirate.Sail(game.GetMyCapsule().Holder); } // CHECKS IF THE PIRATE IS CLOSE TO HOLDER IF HE DOES AND WE HAVE LESS PIRATES THAN THEM PIRATE GOES TO DEFEND OR SOMETHING else if (EnemyCloseToOurCapsule(game) > 1 && pirate.Distance(game.GetMyCapsule().Holder) < 900 && pirate != game.GetMyCapsule().Holder&& AllyCloseToOurCapsule(game) + 1 < EnemyCloseToOurCapsule(game)) { pirate.Sail(game.GetMyCapsule().Holder); } // SENDS THE 1st & 2nd CLOSEST PIRATES TO ENEMY CAPSULE else if (xClosestToY(game.GetEnemyCapsule().Holder, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate == pirate || xClosestToY(game.GetEnemyCapsule().Holder, game.GetMyLivingPirates().Cast <GameObject>().ToList())[1] as Pirate == pirate) { pirate.Sail(game.GetEnemyCapsule().Holder); } // GOES TO ENEMY MOTHERSHIP IN ORDER TO DEFEND else if (game.GetEnemyCapsule().Holder.InRange(game.GetEnemyMothership(), 1500) && pirate.InRange(game.GetEnemyMothership(), 1200)) { pirate.Sail(game.GetEnemyCapsule().Holder); } // CHECKS IF ENEMY PIRATE IS IN RANGE OF OUR MS, IF SO, CLOSEST PIRATE TO THIS ENEMY WILL GO TO HIM else if ((xClosestToY(game.GetMyMothership(), game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate).InRange(game.GetMyMothership(), 800) && xClosestToY((xClosestToY(game.GetMyMothership(), game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate), game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate == pirate) { pirate.Sail((xClosestToY(game.GetMyMothership(), game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate)); } // LETS SAIL TO CLOSEST ENEMY PIRATE AND F**K HIN IN THE ASS HOLEEEEE !Q!!:) else { pirate.Sail(xClosestToY(pirate, game.GetEnemyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate); } } } } } }
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()))); }
public int EnemyCloseToOurCapsule(PirateGame game) { return(game.GetEnemyLivingPirates().Count(enemy => enemy.InRange(game.GetMyCapsule(), 800))); }
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))); }
public static List <Pirate> EnemyHoldersByDistance(Location l) => game.GetEnemyLivingPirates().Where(e => e.HasCapsule()).OrderBy(l.Distance).ToList();
public int EnemyPirateNearEnemyCapsule(PirateGame game) { return(game.GetEnemyLivingPirates().Count(pirate => pirate.InRange(game.GetEnemyCapsule(), 500))); }
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"); }
//-------------------------------------------- public void DoTurn(PirateGame game) { Main.game = game; ///* game.Debug("Kol od baleivav penimah"); game.Debug("Nefesh Yehudi homiyah,"); game.Debug("Ul(e)faatei mizrach kadimah,"); game.Debug("Ayin leTziyon tzofiyah;"); game.Debug(""); game.Debug("Od lo avdah tikvateinu,"); game.Debug("Hatikvah bat sh(e)not alpayim,"); game.Debug("Lihyot am chofshi b(e)artzeinu,"); game.Debug("Eretz-Tziyon virushalayim."); game.Debug(""); //*/ if (goStick.Any() && !game.GetMyPirateById(goStick.First().Id).IsAlive()) { goStick.Clear(); } // Clearing objects didTurn.Clear(); sailToworm.Clear(); capsulesTargetted.Clear(); asteroidsPushed.Clear(); piratesPushed.Clear(); wormsPushed.Clear(); // Gettings the mines if (game.GetMyCapsules().Any() && game.Turn == 1) { game.GetMyCapsules().Where(cap => cap.Holder == null && !mines.Contains(cap.Location)).ToList().ForEach(cap => mines.Add(cap.Location)); } if (game.GetEnemyCapsules().Any() && game.Turn == 1) { game.GetEnemyCapsules().Where(cap => cap.Holder == null && !enemyMines.Contains(cap.Location)).ToList().ForEach(cap => enemyMines.Add(cap.Location)); } unemployedPirates = game.GetMyLivingPirates().ToList(); HandTasks(); foreach (Pirate pirate in game.GetMyLivingPirates().Where(p => p.StateName != game.STATE_NAME_HEAVY).OrderByDescending(p => tasks[p.Id].Item2.HeavyWeight())) { if (tasks[pirate.Id].Item2.HeavyWeight() <= 0) { break; } var switchWith = game.GetMyLivingPirates().Where(p => p.Id != pirate.Id && tasks[p.Id].Item2.HeavyWeight() < tasks[pirate.Id].Item2.HeavyWeight() && p.StateName == game.STATE_NAME_HEAVY) .OrderBy(p => tasks[p.Id].Item2.HeavyWeight()); bool shouldNotSwitch = game.__livingAsteroids.Any(a => pirate.Distance(a) < pirate.MaxSpeed * 5) || game.GetEnemyLivingPirates().Any(e => pirate.Distance(e) < pirate.MaxSpeed * 3.5); if (shouldNotSwitch) { break; } if (switchWith.Any() && pirate.StateName != game.STATE_NAME_HEAVY) { switchWith.First().SwapStates(pirate); didTurn.Add(switchWith.First().Id); break; } } foreach (KeyValuePair <int, Tuple <TaskType, Task> > pair in tasks.OrderByDescending(pair => pair.Value.Item2.Priority())) { try { var preform = pair.Value.Item2.Preform(); if (debug) { game.Debug(preform); } } catch (System.Exception e) { game.Debug(e.Message); } } if (stopStick == true) { Main.goStick.Clear(); } }
private void HandlePirates(PirateGame game) { bool second_guard = false; bool decoyed = false; // Go over all of my pirates foreach (Pirate pirate in game.GetMyLivingPirates()) { #region First Week if (game.GetOpponentName() == "11999" || game.GetOpponentName() == "12000" || game.GetOpponentName() == "12001" || game.GetOpponentName() == "12002" || game.GetOpponentName() == "12003" || game.GetOpponentName() == "12004" || game.GetOpponentName() == "12005" || game.GetOpponentName() == "12006") { if (!Attacker.TryAttack(pirate, game)) { //bot 1: if (game.GetMyCities().Count == 0) { Mover.MoveAircraft(pirate, Week1.GetGuardDestination(pirate, game), game); } else { // if there's 5 islands OR my city and first island are on the same row and there is more than one island and not one city if (game.GetAllIslands().Count == 3 || game.GetMyCities()[0].Location.Row != game.GetAllIslands()[0].Location.Row && (game.GetMyCities().Count != 1 && game.GetAllIslands().Count != 1)) { // if there's 3 islands AND my city and enemy city is in the same row if (game.GetAllIslands().Count == 3 && game.GetMyCities()[0].Location.Row == game.GetEnemyCities()[0].Location.Row) { if (pirate.Id == 0) { Mover.MoveAircraft(pirate, Week1.GetGuardDestination(pirate, game), game); } else if (pirate.Id < 3) { int distance = 1000000; int id = 0; int counter = 0; foreach (Aircraft a in game.GetEnemyLivingAircrafts()) { if (a.Distance(pirate) < distance) { id = counter; distance = a.Distance(pirate); } counter++; } // sail to closest enemy aircraft Mover.MoveAircraft(pirate, game.GetEnemyLivingAircrafts()[id], game); } else if (pirate.Id == 3) { Mover.MoveAircraft(pirate, game.GetAllIslands()[0], game); } else { Mover.MoveAircraft(pirate, game.GetAllIslands()[1], game); } } else //Dolphin OR Nahshol { Mover.MoveAircraft(pirate, game.GetAllIslands()[2], game); } } else if (!Week1.GoAsUnit(game) && !done) { // Gal before move Mover.MoveAircraft(pirate, game.GetAllIslands()[0], game); } else if (game.GetMyCities().Count == 1 && game.GetAllIslands().Count == 1 && game.GetMyCities()[0].Location.Col == game.GetAllIslands()[0].Location.Col) { // Gal after move done = true; Mover.MoveAircraft(pirate, game.GetMyLivingDrones()[0], game); } else if (game.GetMyCities()[0].Location.Row == game.GetAllIslands()[0].Location.Row) { // Bee done = true; Mover.MoveAircraft(pirate, game.GetEnemyLivingPirates()[0], game); } } } } #endregion #region Second Week else if (game.GetOpponentName() == "12109") // First Bot { if (pirate.Id == 0) // If You're The First Pirate { if (game.GetNotMyIslands().Count > 0) { if (game.GetNeutralCities().Count > 0 && game.GetAllIslands().OrderBy(c => c.Distance(game.GetNeutralCities()[0])).ToList()[0].Owner != game.GetMyself()) // If There's a trading city and the island closest to it isn't ours { Mover.MoveAircraft(pirate, game.GetNotMyIslands().OrderBy(c => c.Distance(game.GetNeutralCities()[0])).ToList()[0], game); // Go To Closest Island To The Trading City } else { Mover.MoveAircraft(pirate, game.GetNotMyIslands().OrderBy(c => c.Distance(pirate)).ToList()[0], game); // Go To Closest Island That isn't Yours } } else { Mover.MoveAircraft(pirate, game.GetMyIslands().OrderByDescending(c => c.Distance(pirate)).ToList()[0], game); // Go To Farthest Island That's Yours } } // If pirate didn't attack else if (!Attacker.TryAttack(pirate, game)) { foreach (City C in game.GetEnemyCities()) { if (pirate.Id == game.GetMyLivingPirates().OrderBy(c => c.Distance(C)).ToList()[0].Id) // If current pirate is the pirate that is closest to the current enemy city { Mover.MoveAircraft(pirate, Targets.GetTarget <Drone>(pirate, game, C, 10), game); // Guard In Range Of 10 } else if (game.GetNotMyIslands().Count > 0) // if there are islands that aren't ours { Mover.MoveAircraft(pirate, game.GetNotMyIslands().OrderBy(c => c.Distance(pirate)).ToList()[0], game); // Go To Closest Island That Isn't Yours } else { Mover.MoveAircraft(pirate, game.GetMyIslands().OrderByDescending(c => c.Distance(pirate)).ToList()[0], game); // Go To Farthest Island That's Yours } } } } else if (game.GetOpponentName() == "12116") // Last Bot { if (!Attacker.TryAttack(pirate, game)) // if pirate didn't attack { Mover.MoveAircraft(pirate, game.GetAllIslands().OrderBy(isle => isle.Distance(game.GetNeutralCities()[0])).ToList()[0], game); // go to the closest islnad to the trade city } } else if (game.GetOpponentName() == "12115") // Seventh Bot { if (!Attacker.TryAttack(pirate, game)) { //if pirate is the closest to the trade city(optimal guard), guard the trade city if (pirate == game.GetMyLivingPirates().OrderBy(c => c.Distance(game.GetNeutralCities()[0])).ToList()[0]) { Mover.MoveAircraft(pirate, Targets.GetTarget <Drone>(pirate, game, game.GetNeutralCities().OrderBy(c => c.Distance(pirate)).ToList()[0], 15), game); // Guard In Range Of 15 } //find if one of the other enemy cities has drones in its range, go there too //if we don't own the closest island to trade city, go get 'em else if (game.GetAllIslands().OrderBy(c => c.Distance(game.GetNeutralCities()[0])).ToList()[0].Owner != game.GetMyself()) { Mover.MoveAircraft(pirate, game.GetAllIslands().OrderBy(c => c.Distance(game.GetNeutralCities()[0])).ToList()[0].Location, game); } //if trade city is under attack, go help. else if (game.GetEnemyLivingPirates().Exists(e => e.InRange(game.GetMyLivingPirates().OrderBy(c => c.Distance(game.GetNeutralCities()[0])).ToList()[0], 7))) { try { if (pirate.Id < game.GetEnemyLivingPirates().Count(e => e.InRange(game.GetMyLivingPirates().OrderBy(c => c.Distance(game.GetNeutralCities()[0])).ToList()[0], 7))) { Mover.MoveAircraft(pirate, Targets.GetTarget <Pirate>(pirate, game, game.GetNeutralCities().OrderBy(c => c.Distance(pirate)).ToList()[0], 10), game); } else { Mover.MoveAircraft(pirate, Targets.GetTarget <Pirate>(pirate, game, game.GetNotMyIslands().OrderBy(c => c.Distance(pirate)).ToList()[0], 15), game); } } catch { } } else if (!second_guard && game.GetEnemyLivingDrones().Exists(d => d.InRange(game.GetEnemyCities().OrderBy(c => c.Distance(pirate)).ToList()[0], 10))) { Mover.MoveAircraft(pirate, Targets.GetTarget <Drone>(pirate, game, game.GetEnemyCities().OrderBy(c => c.Distance(pirate)).ToList()[0], 10), game); second_guard = true; } //finally focus on capturing islands else { try { Mover.MoveAircraft(pirate, game.GetNotMyIslands().OrderBy(c => c.Distance(game.GetNeutralCities()[0])).ToList()[0].Location, game); } catch { } } } } else if (game.GetOpponentName() == "12110") // Second Bot { if (!Attacker.TryAttack(pirate, game)) // if pirate didn't attack { Mover.MoveAircraft(pirate, game.GetEnemyLivingPirates().OrderBy(p => p.Distance(pirate)).ToList()[0], game); // go to closest enemy pirate } } else if (game.GetOpponentName() == "12111") // Third Bot { if (!Attacker.TryAttack(pirate, game)) // if pirate didn't attack { if (game.GetEnemyLivingDrones().Count > 0) // if there's any enemy drones { Mover.MoveAircraft(pirate, game.GetEnemyLivingDrones().OrderBy(p => p.Distance(game.GetEnemyLivingDrones()[0])).ToList()[0], game); // go to closest enemy drone } else { Mover.MoveAircraft(pirate, game.GetNeutralCities()[0], game); // go to trade city } } } else if (game.GetOpponentName() == "12113") // Fifth Bot { if (!Attacker.TryAttack(pirate, game)) // if pirate didn't attack { if (game.GetEnemyLivingDrones().Count > 0 && pirate.Id < 4) // if there are any enemy drones and the pirate id is less than 4 { Mover.MoveAircraft(pirate, game.GetEnemyLivingDrones().OrderBy(d => d.Distance(game.GetNeutralCities()[0])).ToList()[0], game); // go to closest enemy drone to trade city } else if (game.GetNotMyIslands().Count > 0) // if there are any islands that aren't ours { Mover.MoveAircraft(pirate, game.GetNotMyIslands().OrderBy(p => p.Distance(pirate)).ToList()[0], game); // go to closest island that isn't yours } else { Mover.MoveAircraft(pirate, game.GetEnemyLivingPirates().OrderBy(p => p.Distance(pirate)).ToList()[0], game); // go to closest pirate } } } else if (game.GetOpponentName() == "12112") // Fourth Bot { if (!Attacker.TryAttack(pirate, game)) // if pirate didn't attack { if (game.GetMyScore() > game.GetEnemyScore() + 5) // if our score is 6 more than the enemy's score { Mover.MoveAircraft(pirate, game.GetEnemyLivingPirates().OrderBy(c => c.Distance(pirate)).ToList()[0], game); // go to dclosest enemy pirate } else if (pirate.Id == 0) // if pirate id is 0 { if (game.GetEnemyLivingDrones().Count > 0) // if there are enemy drones { Mover.MoveAircraft(pirate, game.GetEnemyLivingDrones().OrderBy(c => c.Distance(new Location(game.GetRowCount() / 2, game.GetColCount() / 2))).ToList()[0], game); // go to the closest enemy drone to the middle of the map } else { Mover.MoveAircraft(pirate, new Location(game.GetRowCount() / 2, game.GetColCount() / 2), game); // go to the middle of the map } } else if (game.GetNotMyIslands().Count > 1) // if there's 2 or more islands that aren't ours { Mover.MoveAircraft(pirate, game.GetNotMyIslands()[pirate.Id % 2], game); // go to island 0 or 1 according to pirate id } else { Mover.MoveAircraft(pirate, game.GetEnemyLivingPirates()[0], game); // go to first enemy pirate } } } else if (game.GetOpponentName() == "12114") // 100 years of loneliness { if (!Attacker.TryAttack(pirate, game)) { if (pirate.Id == 0 && game.GetEnemyLivingDrones().Count > 0) { Mover.MoveAircraft(pirate, game.GetEnemyLivingDrones()[0], game); } else { Mover.MoveAircraft(pirate, game.GetAllIslands()[0], game); // go to first island } } } #endregion #region Third Week else if (game.GetOpponentName() == "12217") //First Bot { // If pirate didn't attack move to the spot between the islands if (!Attacker.TryAttack(pirate, game, game.GetEnemyLivingPirates().OrderBy(p => p.Distance(pirate)).ToList()[0])) { Mover.MoveAircraft(pirate, new Location(14, 25), game); } } else if (game.GetOpponentName() == "12218") // Second Bot { // If pirate didn't attack go to the first island if (!Attacker.TryAttack(pirate, game)) { Mover.MoveAircraft(pirate, game.GetAllIslands()[0], game); } } else if (game.GetOpponentName() == "12219") // Third Bot { //If pirate id is either 0 or 7 if (pirate.Id == 0 || pirate.Id == 7) { // If pirate doesn't have a paintball get closest paintball if (!pirate.HasPaintball) { Mover.MoveAircraft(pirate, game.GetAllPaintballs().OrderBy(p => p.Distance(pirate)).ToList()[0], game); } // Else if there's any enemy drones else if (game.GetEnemyLivingDrones().Count > 0) { // If pirate has an enemy drone in range attack it. If not, go to closest drone if (!pirate.InAttackRange(game.GetEnemyLivingDrones().OrderBy(d => d.Distance(pirate)).ToList()[0])) { Mover.MoveAircraft(pirate, game.GetEnemyLivingDrones().OrderBy(d => d.Distance(pirate)).ToList()[0], game); } else { game.Attack(pirate, game.GetEnemyLivingDrones().OrderBy(d => d.Distance(pirate)).ToList()[0]); } } // Else go to closest island that isn't ours else { Mover.MoveAircraft(pirate, game.GetNotMyIslands().OrderBy(p => p.Distance(pirate)).ToList()[0], game); } } // Else if pirate didn't attack else if (!Attacker.TryAttack(pirate, game)) { // If pirate isn't one of the last 3 pirates move to Second island if (pirate.Id < game.GetAllMyPirates().Count - 2) { Mover.MoveAircraft(pirate, game.GetAllIslands()[2], game); } // Else if second island is ours target closest pirate to current pirate in a range of 30 else if (game.GetAllIslands()[2].Owner == game.GetMyself()) { Mover.MoveAircraft(pirate, Targets.GetTarget <Pirate>(pirate, game, 24), game); } // Else go to second island else { Mover.MoveAircraft(pirate, game.GetAllIslands()[2], game); } } } else if (game.GetOpponentName() == "12220") // Fourth Bot { // If pirate didn't attack if (!Attacker.TryAttack(pirate, game)) { // If pirate id is 0, go to (4,3). If not go staright untill you reach column 3 if (pirate.Id == 0) { Mover.MoveAircraft(pirate, new Location(4, 3), game); } else { Mover.MoveAircraft(pirate, new Location(pirate.Location.Row, 3), game); } } } else if (game.GetOpponentName() == "12221") { // If pirate id is 0 if (pirate.Id == 0) { // If pirate doesn't have a paintball get closest paintball if (!pirate.HasPaintball) { Mover.MoveAircraft(pirate, game.GetAllPaintballs().OrderBy(p => p.Distance(pirate)).ToList()[0], game); } // Else if there's any enemy drones else if (game.GetEnemyLivingDrones().Count > 0) { // If pirate has an enemy drone in range attack it. If not, go to closest drone if (!pirate.InAttackRange(game.GetEnemyLivingDrones().OrderBy(d => d.Distance(pirate)).ToList()[0])) { Mover.MoveAircraft(pirate, game.GetEnemyLivingDrones().OrderBy(d => d.Distance(pirate)).ToList()[0], game); } else { game.Attack(pirate, game.GetEnemyLivingDrones().OrderBy(d => d.Distance(pirate)).ToList()[0]); } } // Else go to closest island that isn't ours else { Mover.MoveAircraft(pirate, game.GetNotMyIslands().OrderBy(p => p.Distance(pirate)).ToList()[0], game); } } // Else if pirate didn't attack go to the first island else if (!Attacker.TryAttack(pirate, game)) { Mover.MoveAircraft(pirate, game.GetAllIslands()[0], game); } } else if (game.GetOpponentName() == "12222") { // If pirate didn't attack if (!Attacker.TryAttack(pirate, game)) { if (game.GetNotMyIslands().Count > 0) { Mover.MoveAircraft(pirate, game.GetNotMyIslands().OrderBy(i => i.Distance(pirate)).ToList()[0], game); } else { Mover.MoveAircraft(pirate, game.GetEnemyLivingPirates().OrderBy(p => p.Distance(pirate)).ToList()[0], game); } } } else if (game.GetOpponentName() == "12223") { if (game.GetNotMyIslands().Count > 0) { Mover.MoveAircraft(pirate, game.GetNotMyIslands().OrderBy(i => i.Distance(pirate)).ToList()[0], game); } else if (pirate.Id < game.GetAllMyPirates().Count / 2) { // If pirate doesn't have a paintball get closest paintball if (!pirate.HasPaintball) { Mover.MoveAircraft(pirate, game.GetAllPaintballs().OrderBy(p => p.Distance(pirate)).ToList()[0], game); } // Else if there's any enemy drones else if (game.GetEnemyLivingDrones().Count > 0) { // If pirate has an enemy drone in range attack it. If not, go to closest drone if (!pirate.InAttackRange(game.GetEnemyLivingDrones().OrderBy(d => d.Distance(pirate)).ToList()[0])) { Mover.MoveAircraft(pirate, game.GetEnemyLivingDrones().OrderBy(d => d.Distance(pirate)).ToList()[0], game); } else { game.Attack(pirate, game.GetEnemyLivingDrones().OrderBy(d => d.Distance(pirate)).ToList()[0]); } } // Else go to closest island that isn't ours else if (!Attacker.TryAttack(pirate, game)) { Mover.MoveAircraft(pirate, game.GetEnemyLivingPirates().OrderBy(p => p.Distance(pirate)).ToList()[0], game); } } else if (!Attacker.TryAttack(pirate, game)) { Mover.MoveAircraft(pirate, game.GetEnemyLivingPirates().OrderBy(p => p.Distance(pirate)).ToList()[0], game); } } else if (false && game.GetOpponentName() == "12224") { if (!Attacker.TryAttack(pirate, game)) { if (pirate.Id < 4) { Mover.MoveAircraft(pirate, game.GetAllIslands()[3], game); } else { if (game.GetAllIslands()[1].Owner != game.GetMyself()) { Mover.MoveAircraft(pirate, game.GetAllIslands()[1], game); } else if (game.GetAllIslands()[0].Owner != game.GetMyself()) { Mover.MoveAircraft(pirate, game.GetAllIslands()[0], game); } else if (game.GetAllIslands()[2].Owner != game.GetMyself()) { Mover.MoveAircraft(pirate, game.GetAllIslands()[2], game); } else { Mover.MoveAircraft(pirate, game.GetMyCities()[0], game); } } } } #endregion else // Tournament Bot { if (!decoyed && game.GetMyself().TurnsToDecoyReload == 0) { game.Decoy(pirate); decoyed = true; } else if (!Attacker.TryAttack(pirate, game)) { int count = 0; if (game.GetEnemyLivingPirates().OrderBy(p => p.Distance(game.GetAllIslands()[3])).ToList()[0].InRange(pirate, 5)) { Mover.MoveAircraft(pirate, game.GetEnemyLivingPirates().OrderBy(p => p.Distance(game.GetAllIslands()[3])).ToList()[0], game); } else { Mover.MoveAircraft(pirate, game.GetAllIslands()[3], game); } } } } }
/// <summary> /// Makes the pirate try to push an enemy pirate. Returns true if it did. /// </summary> /// <param name="pirate">The pushing pirate.</param> /// <param name="game">The current game state.</param> /// <returns>true if the pirate pushed.</returns> private bool TryPush(Pirate pirate, PirateGame game) { foreach (Pirate ally in game.GetMyLivingPirates()) { // IF WE HAVE CAP AND PIRATE IS THE CAPSULE HOLDER RETURN FALSE if (game.GetMyCapsule().Holder != null && game.GetMyCapsule().Holder == pirate) { return(false); } // IF WE HAVE CAP AND PIRATE CAN PUSH CAP HOLDER AND HE IS THE CLOSEST TO HIM WE RETURN TRUE if (game.GetMyCapsule().Holder != null && ally.CanPush(game.GetMyCapsule().Holder) && PiratesInRangeOfPush(game, game.GetMyCapsule().Holder)[0] == pirate) { ally.Push(game.GetMyCapsule().Holder, game.GetMyMothership()); System.Console.WriteLine($"pirate:{ally} did push capholder: {game.GetMyCapsule().Holder} to MOTHERSHIP"); return(true); } // IF WE DONT HAVE CAPSULE AND WE CAN PUSH THE CLOSEST PIRATE TO CAP LOCATION THAN DO IT! if (game.GetMyCapsule().Holder == null && ally.CanPush(xClosestToY(game.GetMyCapsule().InitialLocation, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate)) { if ((xClosestToY(game.GetMyCapsule().InitialLocation, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate).Distance(game.GetMyCapsule().InitialLocation) >= game.PirateMaxSpeed * 3 && ally.CanPush(xClosestToY(game.GetMyCapsule().InitialLocation, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate) && xClosestToY(game.GetMyCapsule().InitialLocation, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate == ally) { ally.Push(xClosestToY(game.GetMyCapsule().InitialLocation, game.GetMyLivingPirates().Cast <GameObject>().ToList())[0] as Pirate, game.GetMyCapsule().InitialLocation); System.Console.WriteLine($"pirate:{ally} did push closest to cap: {game.GetMyCapsule().Holder} to CAP"); return(true); } } } //WE PREFFER TO PUSH OURSELVES FIRST! foreach (Pirate enemy in game.GetEnemyLivingPirates()) { //TODO : IF TIGBORET PUSH HIM TO BUY SOME TIME // IF ENEMY HAS CAP AND WE HAVE MORE THAN 2 TO DROP HIS CAP if (game.GetEnemyCapsule().Holder != null && enemy == game.GetEnemyCapsule().Holder&& PiratesInRangeOfPush(game, enemy).Count > 1 && pirate.CanPush(enemy)) { pirate.Push(enemy, EnemyCanExplode(game, enemy)); return(true); } // IF ENEMY CAN GO OUT OF MAP KICK HIM! if (!EnemyCanExplode(game, enemy).Equals(enemy.InitialLocation.Add(enemy.InitialLocation))) { if (isOneFromThisList(game, PiratesInRangeOfPush(game, enemy), pirate)) { pirate.Push(enemy, EnemyCanExplode(game, enemy)); return(true); } } // Check if the pirate can push the enemy. /*if (pirate.CanPush(enemy)) * { * // Push enemy! * //***POSSIBLE BUG*** * pirate.Push(enemy, EnemyCanExplode(game, enemy)); * * // Print a message. * System.Console.WriteLine("pirate " + pirate + " pushes " + enemy + " towards " + EnemyCanExplode(game, enemy)); * * // Did push. * return true; * }*/ } // Didn't push. return(false); }