/* Execute a series of steps */ public void GoTo(PirateGame game, LinkedList <Location> locationList) { if (_traveling) { /* SPirate is currently traveling */ if (_pirate.GetLocation() == _currentMapTarget.Value) { //Pirate reached destination if (_currentMapTarget.Next == null) { _traveling = false; } else { _currentMapTarget = _currentMapTarget.Next; } } else { //Traveling but still hasn't reached destination if (_pirate.IsAlive()) { game.SetSail(_pirate, game.GetSailOptions(_pirate, _currentMapTarget.Value)[0]); } } } else { //Not traveling, insert new list _mapTargetBuffer = locationList; } }
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>(); }
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 void MoveAircraft(Drone drone, MapObject destination, PirateGame game) { if (game.GetOpponentName() == "12220") { destination = game.GetMyCities()[1]; } // Get sail options for the pirate to get to the destination List <Location> sailOptions = game.GetSailOptions(drone, destination); if (game.GetOpponentName() == "12110") // 2nd Week 3rd Bot { if (drone.Location.Row != game.GetMyCities()[0].Location.Row) { game.SetSail(drone, sailOptions[FindSafeSpot(sailOptions, game)]); } else if (game.GetMyLivingDrones().Count > 10 && game.GetMyLivingDrones()[10].Location.Row == game.GetMyCities()[0].Location.Row) { game.SetSail(drone, sailOptions[FindSafeSpot(sailOptions, game)]); } } else { // Set sail towards the destination game.SetSail(drone, sailOptions[FindSafeSpot(sailOptions, game)]); // Debug game.Debug("Drone " + drone + " sails to " + sailOptions[FindSafeSpot(sailOptions, game)] + game.GetOpponentName().ToString()); } }
//FINDS THE LOCATION POSSIBLE TO PUSH ENEMY OUT OF MAP BOUNDS OTHERWISE INIT LOCATION public Location EnemyCanExplode(PirateGame game, Pirate enemy) { int count = PiratesInRangeOfPush(game, enemy).Count; int col = enemy.Location.Col; int row = enemy.Location.Row; //ROWS if (row + (count * game.PushDistance) > game.Rows) { return(new Location(row + (count * game.PushDistance), col)); } if (row - (count * game.PushDistance) < 0) { return(new Location(row - (count * game.PushDistance), col)); } //COLS if (col + (count * game.PushDistance) > game.Cols) { return(new Location(row, col + (count * game.PushDistance))); } if (col - (count * game.PushDistance) < 0) { return(new Location(row, col - (count * game.PushDistance))); } //CANT PUSH OUT OF MAP, SEND TO INITIAL LOCATION return(enemy.InitialLocation.Add(enemy.InitialLocation)); }
/// <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(); }
public static Location GetGuardDestination(Pirate pirate, PirateGame game) { Drone drone = GetClosestDrone(game); if (drone != null) { if (drone.Location.Col > game.GetEnemyCities()[0].Location.Col + 3 && drone.Location.Row <= game.GetEnemyCities()[0].Location.Row + 3 && drone.Location.Row >= game.GetEnemyCities()[0].Location.Row - 3) { return(new Location(game.GetEnemyCities()[0].Location.Row, game.GetEnemyCities()[0].Location.Col + 1)); } else if (drone.Location.Col < game.GetEnemyCities()[0].Location.Col - 3 && drone.Location.Row <= game.GetEnemyCities()[0].Location.Row + 3 && drone.Location.Row >= game.GetEnemyCities()[0].Location.Row - 3) { return(new Location(game.GetEnemyCities()[0].Location.Row, game.GetEnemyCities()[0].Location.Col - 1)); } else if (drone.Location.Row > game.GetEnemyCities()[0].Location.Row + 1) { return(new Location(game.GetEnemyCities()[0].Location.Row + 1, game.GetEnemyCities()[0].Location.Col)); } else if (drone.Location.Row < game.GetEnemyCities()[0].Location.Row - 1) { return(new Location(game.GetEnemyCities()[0].Location.Row - 1, game.GetEnemyCities()[0].Location.Col)); } } return(game.GetEnemyCities()[0].Location); }
public void DoTurn(PirateGame game) { Initialize(game); if (defense) { BuildBunkerForDefense(); MovePiratesToDestinations(); } else { PushEachOther(); PairMyPirates(); PushAsteroidsNearby(); // HandleSwitchPirates(); MoveToIntersection(); BuildDefensiveBunker(); foreach (var pirate in game.GetMyLivingPirates().Where(p => p.HasCapsule())) { TryPushMyCapsule(pirate); } SendCapsuleCaptures(); PushWormholes(); PushAsteroids(); // AttackEnemies(); MovePiratesToDestinations(); } }
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(); }
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); }
public void DoTurn(PirateGame game) { MyBot.game = game; // Give orders to my pirates HandlePirates(game); // Give orders to my drones HandleDrones(game); }
public Popup(ContentManager manager, String background, String font, List<string> messages, PirateGame.Interfaces.IDrawableCustom owner) { this.IsVisible = false; this.Texture = manager.Load<Texture2D>(background); this.Font = manager.Load<SpriteFont>(font); this.Messages = messages; this.owner = owner; this.backgroundRect = new Rectangle(); }
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 bool isOneFromThisList(PirateGame game, List <Pirate> list, Pirate pirate) { foreach (Pirate item in list) { if (item.Equals(pirate)) { return(true); } } return(false); }
private bool IsGroup(PirateGame game) { for (int i = 0; i < game.GetMyLivingPirates().Count - 1; i++) { if (i + 1 < game.GetMyLivingPirates().Count - 1 && !game.GetMyLivingPirates()[i].Location.Equals(game.GetMyLivingPirates()[i + 1].Location)) { return(false); } } return(true); }
public static void MoveAircraft(Aircraft aircraft, MapObject destination, PirateGame game) { // Get sail options for the pirate to get to the destination List <Location> sailOptions = game.GetSailOptions(aircraft, destination); // Set sail towards the destination game.SetSail(aircraft, sailOptions[0]); // Debug game.Debug("aircraft " + aircraft + " sails to " + sailOptions[0]); }
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); }
void Formation(PirateGame game) { if (collector.IsAlive()) { if (collector.Capsule == null) { if (!TryPush(collector, game)) { collector.Sail(game.GetMyCapsule()); } } else { if (!TryPush(collector, game)) { collector.Sail(game.GetMyMothership().Location); } } } else { Pirate temp = collector; for (int i = 0; i < 2; i++) { if (bodyGuards[i].IsAlive() && !collector.IsAlive()) { collector = bodyGuards[i]; bodyGuards[i] = temp; break; } } } if (bodyGuards[0].IsAlive()) { if (!TryPush(bodyGuards[0], game)) { bodyGuards[0].Sail(new Location(collector.Location.Row + offsetY, collector.Location.Col - offsetX)); } } if (bodyGuards[1].IsAlive()) { if (!TryPush(bodyGuards[1], game)) { bodyGuards[1].Sail(new Location(collector.Location.Row + offsetY, collector.Location.Col + offsetX)); } } if (tailGuard.IsAlive()) { if (!TryPush(tailGuard, game)) { tailGuard.Sail(new Location(collector.Location.Row + offsetY, collector.Location.Col)); } } }
public AttackerList(PirateGame game) { PirateList all = new PirateList(game.GetAllMyPirates().OrderBy(Pirate => Pirate.Location.Distance(game.GetMyCapsule().Location))); for (int i = 0; i < GameSettings.FORMATION_COUNT / 4; i++) { this.Add(new Attacker(all[0])); this.Add(new Attacker(all[1])); this.Add(new Attacker(all[2])); this.Add(new Attacker(all[3])); } }
public int HowMuchCapsules(PirateGame game, List <Pirate> pirates) { int count = 0; foreach (Pirate pirate in pirates) { if (pirate.HasCapsule()) { count++; } } return(count); }
bool done = false; //Got island 0 public void DoTurn(PirateGame game) { game.Debug(game.GetOpponentName()); // Give orders to my pirates HandlePirates(game); // Give orders to my drones if my city exists if (game.GetMyCities().Count > 0 || game.GetNeutralCities().Count > 0) { HandleDrones(game); } HandleDecoy(game); }
private void HandleDrones(PirateGame game) { // Go over all of my drones foreach (Drone drone in game.GetMyLivingDrones()) { // Get my first city City destination = game.GetMyCities()[0]; // Get sail options List <Location> sailOptions = game.GetSailOptions(drone, destination); // Set sail! game.SetSail(drone, sailOptions[0]); } }
private int PiratesWithBalls(PirateGame game) { int c = 0; foreach (Pirate p in game.GetMyLivingPirates()) { if (p.HasPaintball) { c++; } } return(c); }
public DefenderList(PirateGame game) { PirateList def = new PirateList(game.GetAllMyPirates().OrderBy(Pirate => Pirate.Location.Distance(game.GetMyCapsule().Location))); def.RemoveRange(0, 4); for (int i = 0; i < (def.Count / 2); i++) { this.Add(new Defender(def[i], Roles.front)); } for (int i = 0; i < def.Count - (def.Count / 2); i++) { this.Add(new Defender(def[i], Roles.backup)); } }
public static bool GoAsUnit(PirateGame game) { bool startgo = false; List <Drone> livingdrones = game.GetMyLivingDrones(); if (livingdrones != null) { if (livingdrones.Count >= game.GetMaxDronesCount()) { startgo = true; } } return(startgo); }
private void Initialize(PirateGame pirateGame) { game = pirateGame; availableAsteroids = game.GetLivingAsteroids().ToList(); availablePirates = pirateGame.GetMyLivingPirates().ToList(); pirateDestinations = new Dictionary <Pirate, Location>(); enemyCapsulePushes = new Dictionary <Capsule, int>(); foreach (var capsule in game.GetEnemyCapsules()) { enemyCapsulePushes[capsule] = 0; } bunkeringPirates = new List <Pirate>(); myPiratesWithCapsulePushes = game.GetMyLivingPirates().Where(p => p.HasCapsule()).ToDictionary(pirate => pirate, pirate => 0); }
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(); }
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 static bool TryAttack(Pirate pirate, PirateGame game, Pirate enemy) { // 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); } // Didn't attack return(false); }
public static Location GetTarget <T>(Pirate pirate, PirateGame game, MapObject Obj, int range) { if (game.GetEnemyLivingDrones().Count > 0) { if (TryGetTargetList(Obj, game, range)) { List <Aircraft> targets = GetTargetList(Obj, game, range); if (targets.Where(c => c.GetType().Equals(typeof(T))).ToList().Count > 0) { return(targets.Where(c => c.GetType().Equals(typeof(T))).ToList()[0].Location); } } } return(game.GetNotMyCities().OrderBy(c => c.Distance(Obj)).ToList()[0].Location); }
override public int Cost(Chunk chunk) { PirateGame game = Main.game; int cost = 0; foreach (Asteroid asteroid in Main.game.__livingAsteroids.Where(a => Utils.AsteroidIsMoving(a))) { foreach (Location next in GetNextLocations(asteroid).Where(loc => chunk.Distance(loc) < range)) { cost += (range - chunk.Distance(asteroid)) * 10; } } return(cost); }
public void Run() { PirateGame pirateGame = null; string str = ""; while (true) { try { string str1 = Console.ReadLine().TrimEnd(new char[] { '\r', '\n' }); if (str1.ToLower() == "ready") { pirateGame = new PirateGame(str); pirateGame.FinishTurn(); str = ""; } else if (str1.ToLower() != "go") { str = string.Concat(str, str1, "\n"); } else { pirateGame.Update(str); if (!pirateGame.ShouldRecoverErrors()) { this.bot.DoTurn(pirateGame); } else { try { this.bot.DoTurn(pirateGame); } catch (Exception exception1) { Exception exception = exception1; pirateGame.Debug("Exception occured during doTurn: \n{0}", new object[] { exception.ToString() }); } } pirateGame.CancelCollisions(); pirateGame.FinishTurn(); str = ""; } } catch (IOException oException) { break; } catch (Exception exception2) { Console.Error.WriteLine(exception2.ToString()); Console.Error.Flush(); } finally { this.client.WriteByte(0); this.client.Flush(); } } }
public bool IsCollidedWith(PirateGame.Interfaces.IDrawableCustom obj) { int top = Math.Max(this.rectangle.Top, obj.Rectangle.Top); int bottom = Math.Min(this.rectangle.Bottom, obj.Rectangle.Bottom); int left = Math.Max(this.rectangle.Left, obj.Rectangle.Left); int right = Math.Min(this.rectangle.Right, obj.Rectangle.Right); if (this.rectangle.Intersects(obj.Rectangle)) { Color[] shipTextureData = new Color[this.Texture.Width * this.Texture.Height]; this.Texture.GetData(shipTextureData); Color[] objTextureData = new Color[obj.Texture.Width * obj.Texture.Height]; obj.Texture.GetData(objTextureData); for (int y = top; y < bottom; y++) { for (int x = left; x < right; x++) { Color colorA = shipTextureData[(x - this.rectangle.Left) + (y - this.rectangle.Top) * this.rectangle.Width]; Color colorB = objTextureData[(x - obj.Rectangle.Left) + (y - obj.Rectangle.Top) * obj.Rectangle.Width]; if (colorA.A != 0 && colorB.A != 0) { return true; } } } } return false; }