public override void ExecuteStrategy() { foreach (BaseAttacker BA in Participants.Cast <BaseAttacker>().ToList()) { GameSettings.Game.Debug("Formation" + BA.Pirate.Id); } FieldAnalyzer.DefineTargets(Participants.Cast <BaseAttacker>().ToList()); FieldAnalyzer.AssignFormationLocations(Participants.Cast <BaseAttacker>().ToList()); BaseAttacker.FormationComplete = FormUp(); List <Carrier> possibleCarriers = Participants.OfType <Carrier>().ToList(); if (possibleCarriers.Count > 0) { if (Participants.OfType <Carrier>().ToList() != null) { if (Participants.OfType <Carrier>().ToList()[0] != null) { Carrier carrier = Participants.OfType <Carrier>().ToList()[0]; List <Pirate> enemysThreating = FieldAnalyzer.UnderThreat(carrier.Pirate, carrier.Pirate.PushRange * 4, carrier.Destination); if (enemysThreating.Count > 0) { FieldAnalyzer.PopulateEnemyTargets(enemysThreating, Participants.Cast <BaseAttacker>().ToList()); } } } } foreach (BaseAttacker attacker in Participants) { attacker.ExecuteCommand(); } }
public override void ExecuteStrategy() { DeathBallAttacker pusher = null; List <DeathBallDefender> baseDefenders = new List <DeathBallDefender>(); List <ICommand> participants = new List <ICommand>(Participants); foreach (ICommand pirate in participants) { if (pirate is DeathBallAttacker) { pusher = pirate as DeathBallAttacker; } } participants.Remove(pusher); foreach (BaseDefender BD in participants.Cast <BaseDefender>().ToList()) { GameSettings.Game.Debug("DeathBall = " + BD.Pirate.Id); } if (participants != null) { baseDefenders = participants.Cast <DeathBallDefender>().ToList(); } Asteroid dodge = null; foreach (DeathBallDefender defender in baseDefenders) { foreach (Asteroid asteroid in GameSettings.Game.GetLivingAsteroids()) { Mothership closestMothership = FieldAnalyzer.GetClosestEnemyMothership(defender.Pirate); if (closestMothership != null) { if (asteroid.GetLocation().InRange(closestMothership, 500)) { dodge = asteroid; } } } if (pusher.PushedAsteroid && dodge != null) { GameSettings.Game.Debug("Asteroid DeathBall is: " + dodge.Location); defender.WhereToDefend = dodge.GetLocation().Towards(defender.Pirate, dodge.Size + 50); } } foreach (ICommand bot in Participants) { bot.ExecuteCommand(); } }
public void DoTurn(PirateGame game) { GameSettings.Game = game; /*if (GameSettings.Game.GetMyLivingPirates().Length > 0 && GameSettings.LastGameLivingAsteroids.Count > 1) * { * GameSettings.Game.Debug("pirate previous location: "+GameSettings.LastGameMyLivingPirates[0]+" *** current location: "+GameSettings.Game.GetMyLivingPirates()[0].Location); * GameSettings.Game.Debug("asteroid 1 previous location: "+GameSettings.LastGameLivingAsteroids[1]+" *** current location: "+GameSettings.Game.GetLivingAsteroids()[1].Location); * } */ if (GameSettings.Game.Turn == 1) { List <Strategy> tmp = new List <Strategy>(); if (GameSettings.Game.GetMyCapsules().ToList().Count > 0) { tmp.Add(new Formation()); } if (GameSettings.Game.GetEnemyMotherships().ToList().Count > 0) { tmp.Add(new FireWall()); } strategies = tmp; strategyOrganizer = new StrategyOrganizer(strategies); FA = new FieldAnalyzer(); } strategyOrganizer.SendStrategyToCommunicator(); strategyOrganizer.DeliverPirates(); foreach (Strategy strategy in strategies) { strategy.BeforeExecute(); } //update last turn objects locations GameSettings.SetLastGame(); // GameSettings.SetLastGameMyLivingPirates(); // GameSettings.SetLastGameEnemyPirates(); // GameSettings.SetLastGameLivingAsteroids(); // if (GameSettings.Game.GetAllWormholes().Count > 0) // GameSettings.SetLastGameWormholes(); }
public override Pirate Protect() { Mothership mothership = FieldAnalyzer.GetClosestEnemyMothership(Pirate); if (mothership != null) { //List<Pirate> enemiesByDistanceFromEnemyBase = GameSettings.Game.GetEnemyLivingPirates().ToList(); //enemiesByDistanceFromEnemyBase.OrderBy(Pirate => Pirate.Location.Distance(mothership.Location)); List <Pirate> enemyCarriers = new List <Pirate>(); foreach (Pirate enemy in GameSettings.Game.GetEnemyLivingPirates()) { if (enemy.HasCapsule()) { enemyCarriers.Add(enemy); // GameSettings.Game.Debug("Enemy added to enemyCarriers ==> "+enemy); } } enemyCarriers = enemyCarriers.OrderBy(Pirate => mothership.GetLocation().Distance(Pirate)).ToList(); int scale = 500 * 4; if (enemyCarriers.Count > 0 && pirate.Distance(mothership) < scale) { GameSettings.Game.Debug("Pirate to protect from: " + enemyCarriers[0]); return(enemyCarriers[0]); } //foreach (Pirate pirate in enemiesByDistanceFromEnemyBase) //{ // //Checks if the any of the pirates has capsule in the distance // //of the mothership has a capsule // if (pirate.Distance(mothership) < scale && pirate.Capsule != null) // return pirate; //} } return(null); }
public override Pirate Protect() { List <Pirate> enemyCarriers = new List <Pirate>(); foreach (Pirate enemy in GameSettings.Game.GetEnemyLivingPirates()) { if (enemy.HasCapsule()) { enemyCarriers.Add(enemy); } } if (enemyCarriers.Count < 2) { List <Pirate> enemiesByDistanceFromEnemyBase = GameSettings.Game.GetEnemyLivingPirates().ToList(); enemiesByDistanceFromEnemyBase.OrderBy(Pirate => Pirate.Location.Distance(GameSettings.Game.GetEnemyMotherships()[0].Location)); int scale = Pirate.PushDistance * 4; foreach (Pirate pirate in enemiesByDistanceFromEnemyBase) { //Checks if the any of the pirates has capsule in the distance //of the mothership has a capsule if (pirate.Distance(GameSettings.Game.GetEnemyMotherships()[0]) < scale && pirate.Capsule != null) { return(pirate); } } } else if (enemyCarriers.Count > 2) { Mothership closestMothership = FieldAnalyzer.GetClosestEnemyMothership(pirate); enemyCarriers.OrderBy(Pirate => Pirate.GetLocation().Distance(closestMothership)); return(enemyCarriers[1]); } return(null); }
public BaseCommand() { bestWay = new List <MapObject>(); FA = new FieldAnalyzer(); }
/// <summary> /// Makes the defender try to push an enemy pirate. Returns true if it did. /// If can be pushed out of the map, else push againts the motherboard. /// </summary> /// <returns> true if the pirate pushed. </returns> public override bool Push() { foreach (Asteroid asteroid in GameSettings.Game.GetLivingAsteroids()) { if (pirate.CanPush(asteroid)) { GameSettings.Game.Debug("Pirate in Backup = " + pirate); GameSettings.Game.Debug("Location in Backup = " + asteroidHandler.FindBestLocationToPushTo(this.Pirate)); pirate.Push(asteroid, asteroidHandler.FindBestLocationToPushTo(this.Pirate)); return(true); } } if (PirateToPush != null && WhereToPush != null) { if (pirate.CanPush(PirateToPush)) { pirate.Push(PirateToPush, WhereToPush); return(true); } } GameSettings.Game.Debug("Front WhereToPush " + WhereToDefend); foreach (Pirate enemy in GameSettings.Game.GetEnemyLivingPirates()) { // Check if the pirate can push the enemy. if (Pirate.CanPush(enemy) && enemy.HasCapsule()) { //Changed //Push enemy! Location outOfBorder = FieldAnalyzer.GetCloseEnoughToBorder(enemy, Pirate.PushRange); if (outOfBorder != null) { Pirate.Push(enemy, outOfBorder); return(true); } else { Location oppositeSide = enemy.GetLocation().Subtract(GameSettings.Game.GetEnemyMotherships()[0].GetLocation()); //Vector: the distance (x,y) you need to go through to go from the mothership to the enemy oppositeSide = enemy.GetLocation().Towards(enemy.GetLocation().Add(oppositeSide), 600); Pirate.Push(enemy, oppositeSide); //Print a message. GameSettings.Game.Debug("defender " + Pirate + " pushes " + enemy + " towards " + enemy.InitialLocation); //Did push. return(true); } } } foreach (Wormhole wormhole in GameSettings.Game.GetAllWormholes()) { if (wormhole.Distance(pirate) < 750) { if (pirate.CanPush(wormhole)) { int cols = GameSettings.Game.Cols; int rows = GameSettings.Game.Rows; //Push to the center for now if (pirate.CanPush(wormhole)) { pirate.Push(wormhole, new Location(rows / 2, cols / 2)); GameSettings.Game.Debug("Pirate pushed wormhole"); return(true); } } } } return(false); }
//GameSettings.Game public Front(Pirate pirate, FieldAnalyzer fieldAnalyzer) : base(pirate, fieldAnalyzer) { }
public override void ExecuteStrategy() { //foreach(BaseDefender BD in Participants.Cast<BaseDefender>().ToList()) //{ // GameSettings.Game.Debug("FireWall" + BD.Pirate.Id); //} List <BaseDefender> baseDefenders = new List <BaseDefender>(); if (Participants != null) { baseDefenders = Participants.Cast <BaseDefender>().ToList(); //GameSettings.Game.Debug("FireWall Participants.Count: "+Participants.Count); } List <BaseDefender> frontList = new List <BaseDefender>(); foreach (BaseDefender defender in baseDefenders) { if (defender is Front) { frontList.Add(defender); } } foreach (BaseDefender defender in baseDefenders) { //Backup backup = defender as Backup; if (defender is Backup) { List <Pirate> enemyCarriers = FieldAnalyzer.HowManyCarriersNearCityCanBeDoublePushed(baseDefenders); if (enemyCarriers.Count > 0) { enemyCarriers = enemyCarriers.OrderBy(Pirate => Pirate.Location.Distance(defender.Pirate)).ToList(); defender.PirateToPush = enemyCarriers[0]; List <Pirate> pirateToSend = new List <Pirate>() { defender.PirateToPush }; defender.WhereToPush = FieldAnalyzer.DefendersWhereToPush(defender.PirateToPush, FieldAnalyzer.CheckHowManyDefendrsCanPushEnemyCarrier(pirateToSend, baseDefenders).Count *defender.Pirate.PushDistance); } } else { List <Pirate> threatingEnemies = FieldAnalyzer.GetClosestEnemyPiratesToMothership(defender); List <BaseDefender> defenderToSend = frontList; List <Pirate> multipleDefendersCanPushIt = FieldAnalyzer.HowManyCarriersNearCityCanBeDoublePushed(defenderToSend); // GameSettings.Game.Debug("multipleDefendersCanPushIt.Count ==>" + multipleDefendersCanPushIt.Count); if (multipleDefendersCanPushIt.Count >= 1) { defender.PirateToPush = multipleDefendersCanPushIt[0]; defender.WhereToPush = FieldAnalyzer.DefendersWhereToPush(defender.PirateToPush, defender.Pirate.PushDistance); //GameSettings.Game.Debug("Front WhereToPush " + defender.WhereToDefend); } } if (GameSettings.Game.GetEnemyMotherships().Length > 1) { List <ICommand> fakeParticipant = new List <ICommand>(Participants); foreach (Mothership mothership in GameSettings.Game.GetEnemyMotherships()) { for (int i = 0; i < fakeParticipant.Count / GameSettings.Game.GetEnemyMotherships().Length; i++) { Backup backup = fakeParticipant[i] as Backup; Front front = fakeParticipant[i] as Front; if (backup != null) { GameSettings.Game.Debug("Entered backup"); int scale = (int)(500 * 1.5); Capsule capsule = FieldAnalyzer.GetClosestEnemyCapsuleToMothership(mothership); if (capsule != null) { backup.WhereToDefend = mothership.Location.Towards(capsule.GetLocation(), scale - 600); GameSettings.Game.Debug("Backup WhereToDefend = " + backup.WhereToDefend); } } else if (front != null) { int scale = (int)(500 * 1.5); Capsule capsule = FieldAnalyzer.GetClosestEnemyCapsuleToMothership(mothership); if (capsule != null) { GameSettings.Game.Debug("Entered front, capsule = " + capsule.GetLocation()); front.WhereToDefend = mothership.Location.Towards(capsule.GetLocation(), scale); GameSettings.Game.Debug("Front WhereToDefend = " + front.WhereToDefend); } } } } } defender.ExecuteCommand(); } }
public Backup(Pirate pirate, FieldAnalyzer fieldAnalyzer) : base(pirate, fieldAnalyzer) { }
public override Location DefendAt() { Pirate enemyCarrier = null; if (GameSettings.Game.GetMyMotherships().Length == 0 && GameSettings.Game.GetMyCapsules().Length == 0 && GameSettings.Game.GetAllMyPirates().Length == 1 && GameSettings.Game.GetAllEnemyPirates().Length == 2) { Location loc = GameSettings.Game.GetEnemyMotherships()[0].GetLocation(); loc.Row -= 100; return(loc); } // GameSettings.Game.Debug("WhereToDefend " + WhereToDefend); if (WhereToDefend != null) { return(WhereToDefend); } //GameSettings.Game.Debug("Debugging DefendAt()"); Location guardLocation; List <Pirate> enemyCarriers = new List <Pirate>(); foreach (Pirate enemy in GameSettings.Game.GetEnemyLivingPirates()) { if (enemy.HasCapsule()) { enemyCarriers.Add(enemy); } } //Take care of a few citys or Ben will punch me! int scale = (int)(500 * 1.5); if (GameSettings.Game.GetEnemyMotherships().Length > 0) { enemyCarriers.OrderBy(pirate => Pirate.GetLocation().Distance(GameSettings.Game.GetEnemyMotherships()[0])); if (enemyCarriers.Count > 0) { enemyCarrier = enemyCarriers[0]; } if (enemyCarrier != null) { GameSettings.Game.Debug("enemyCarrier to face to: " + enemyCarrier); //guardLocation = GameSettings.Game.GetEnemyMotherships()[0].Location.Towards(enemyCarrier, scale - 450)scale - 650; guardLocation = GameSettings.Game.GetEnemyMotherships()[0].Location.Towards(enemyCarrier, scale - 650); GameSettings.Game.Debug("guardLocation Towards enemyCarrier" + guardLocation); return(guardLocation); } guardLocation = GameSettings.Game.GetEnemyMotherships()[0].Location.Towards(GameSettings.Game.GetEnemyCapsules()[0], scale - 600); //GameSettings.Game.Debug("Location from ProtectFromCarrier" + guardLocation); return(guardLocation); } bool canPushWormhole = true; foreach (Wormhole wormhole in GameSettings.Game.GetAllWormholes()) { if (wormhole.Distance(pirate) < 750) { if (GameSettings.Game.GetEnemyMotherships().Length > 0) { Mothership mothership = FieldAnalyzer.FindClosestMotherShip(pirate); enemyCarrier = FieldAnalyzer.GetMostThreatningEnemyCarrier(mothership); if (enemyCarrier != null) { //Checks if the enemyPirate can come in more then 5 turns if (enemyCarrier.Distance(Pirate) > enemyCarrier.MaxSpeed * 8) { canPushWormhole = false; } if (canPushWormhole) { guardLocation = wormhole.GetLocation().Towards(this.Pirate, wormhole.WormholeRange); // guardLocation.Col += wormhole.WormholeRange; //GameSettings.Game.Debug("wormhole guardLocation = " + guardLocation); return(guardLocation); } } } } } return(WhereToDefend); }
/// <summary> /// Makes the defender try to push an enemy pirate. Returns true if it did. /// If can be pushed out of the map, else push againts the motherboard. /// </summary> /// <returns> true if the pirate pushed.</returns> public override bool Push() { foreach (Asteroid asteroid in GameSettings.Game.GetLivingAsteroids()) { if (pirate.CanPush(asteroid)) { GameSettings.Game.Debug("Pirate in Backup = " + pirate); GameSettings.Game.Debug("Location in Backup = " + asteroidHandler.FindBestLocationToPushTo(this.Pirate)); pirate.Push(asteroid, asteroidHandler.FindBestLocationToPushTo(this.Pirate)); return(true); } } if (PirateToPush != null && WhereToPush != null) { if (pirate.CanPush(PirateToPush)) { pirate.Push(PirateToPush, WhereToPush); return(true); } } Pirate enemyToPush = Protect(); if (enemyToPush != null) { if (pirate.CanPush(enemyToPush)) { //Sorry about those location numbers :\ //#Onemanarmy if (GameSettings.Game.GetMyMotherships().Length == 0 && GameSettings.Game.GetMyCapsules().Length == 0) { pirate.Push(enemyToPush, new Location(3097, 1557)); return(true); } Location pushTowardsOutOfMap = FieldAnalyzer.GetCloseEnoughToBorder(enemyToPush, Pirate.PushDistance); if (pushTowardsOutOfMap != null) { pirate.Push(enemyToPush, pushTowardsOutOfMap); return(true); } else { if (GameSettings.Game.GetEnemyMotherships().Length > 0) { Location oppositeSide = enemyToPush.GetLocation().Subtract(GameSettings.Game.GetEnemyMotherships()[0].GetLocation()); //Vector: the distance (x,y) you need to go through to go from the mothership to the enemy oppositeSide = enemyToPush.GetLocation().Towards(enemyToPush.GetLocation().Add(oppositeSide), 600); Pirate.Push(enemyToPush, oppositeSide); //Print a message. //GameSettings.Game.Debug("defender " + Pirate + " pushes " + enemyToPush + " towards " + enemyToPush.InitialLocation); //Did push. return(true); } else { Location oppositeSide = enemyToPush.GetLocation().Subtract(new Location(0, 0)); //Vector: the distance (x,y) you need to go through to go from the mothership to the enemy oppositeSide = enemyToPush.GetLocation().Towards(enemyToPush.GetLocation().Add(oppositeSide), 600); Pirate.Push(enemyToPush, oppositeSide); } return(true); } } } GameSettings.Game.Debug("Push distance = " + pirate.PushDistance); GameSettings.Game.Debug("Reached Wormhole zone"); bool canPushWormhole = true; foreach (Wormhole wormhole in GameSettings.Game.GetAllWormholes()) { GameSettings.Game.Debug("wormhole foreach"); if (pirate.CanPush(wormhole)) { //GameSettings.Game.Debug("pirate.PushRange ==> " + pirate.PushRange); //GameSettings.Game.Debug("pirate.MaxSpeed ==> " + pirate.MaxSpeed); GameSettings.Game.Debug("wormhole.Distance(pirate)" + wormhole.Distance(pirate)); if (GameSettings.Game.GetEnemyMotherships().Length > 0) { Mothership mothership = FieldAnalyzer.FindClosestMotherShip(pirate); Pirate enemyCarrier = FieldAnalyzer.GetMostThreatningEnemyCarrier(mothership); if (enemyCarrier != null) { //Checks if the enemyPirate can come in more then 5 turns GameSettings.Game.Debug("pirate.CanPush(wormhole) = " + pirate.CanPush(wormhole)); //Checks if the enemyPirate can come in more then 8 turns if (enemyCarrier.Distance(pirate) < enemyCarrier.MaxSpeed * 8) { canPushWormhole = false; } if (canPushWormhole) { int cols = GameSettings.Game.Cols; int rows = GameSettings.Game.Rows; //Push to the center for now pirate.Push(wormhole, new Location(rows / 2, cols / 2)); GameSettings.Game.Debug("Pirate pushed wormhole"); return(true); } } } } } return(false); }
public Strategy() { fieldAnalyzer = new FieldAnalyzer(); participants = new List <ICommand>(); }