/// <summary> Calculates what is the best task to asign </summary>
        /// <returns> Tuple with the pirate and the task-type </returns>
        public Tuple <Pirate, TaskType> BestTaskToAssign()
        {
            var scores = new Dictionary <Tuple <Pirate, TaskType>, double>();

            foreach (Pirate pirate in unemployedPirates)
            {
                foreach (TaskType taskType in todoTasks)
                {
                    Task   task  = TaskTypeToTask(pirate, taskType);
                    double score = task.Bias() + task.GetWeight();

                    scores[new Tuple <Pirate, TaskType>(pirate, taskType)] = score;
                }
            }

            if (scores.Count > 0)
            {
                var best = scores.OrderByDescending(pair => pair.Value).First();

                if (fullDebug)
                {
                    (from pirate in unemployedPirates
                     let tasks = from tup in scores.Keys.Where(p => pirate.Equals(p)) select tup.Item2 + " > " + scores[tup]
                                 let taskString = tasks.Aggregate((t1, t2) => t1 + "  ||  " + t2)
                                                  select taskString).ToList().ForEach(game.Debug);

                    game.Debug("Gave: " + best.Key.Item1.Id + " | " + best.Key.Item2 + " at: " + best.Value);
                }

                return(best.Key);
            }

            return(new Tuple <Pirate, TaskType>(game.GetMyLivingPirates()[0], TaskType.MINER));
        }
Beispiel #2
0
 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);
 }
Beispiel #3
0
 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>();
 }
Beispiel #4
0
        /// <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();
        }
Beispiel #5
0
 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();
     }
 }
 private void HandleDefence()
 {
     if (defense)
     {
         // Go to the enemy mothership and keep trying to push.
         foreach (var pirate in game.GetMyLivingPirates())
         {
             // Get the enemy's closest capsule to the pirate.
             var closestCapsule = game.GetEnemyCapsules().OrderBy(capsule => capsule.Distance(pirate)).FirstOrDefault();
             if (closestCapsule != null)
             {
                 var closestCapsulePirate = game.GetEnemyLivingPirates().Where(enemy => enemy.HasCapsule() && enemy.Capsule.Equals(closestCapsule)).FirstOrDefault();
                 var closestMothership    = game.GetEnemyMotherships().OrderBy(mothership => mothership.Distance(pirate)).FirstOrDefault();
                 if (closestMothership != null)
                 {
                     if (closestCapsulePirate != null)
                     {
                         if (!TryPush(pirate, closestCapsulePirate))
                         {
                             pirate.Sail(closestMothership.Location.Towards(closestCapsulePirate, (int)(game.MothershipUnloadRange * 0.5)));
                         }
                     }
                     else
                     {
                         pirate.Sail(closestMothership.Location.Towards(closestCapsule, (int)(game.MothershipUnloadRange * 0.5)));
                     }
                 }
             }
         }
     }
 }
 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();
 }
Beispiel #8
0
 private void HandleDecoy(PirateGame game)
 {
     if (game.GetMyDecoy() != null)
     {
         if (game.GetMyLivingPirates().Count > 1)
         {
             Mover.MoveAircraft(game.GetMyself().Decoy, game.GetMyLivingPirates().OrderBy(p => p.Distance(game.GetMyself().Decoy)).ToList()[1], game);
         }
         else if (game.GetMyLivingPirates().Count > 0)
         {
             Mover.MoveAircraft(game.GetMyself().Decoy, game.GetMyLivingPirates().OrderBy(p => p.Distance(game.GetMyself().Decoy)).ToList()[0], game);
         }
         else
         {
             Mover.MoveAircraft(game.GetMyself().Decoy, game.GetAllIslands()[0], game);
         }
     }
 }
 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();
 }
Beispiel #10
0
        private int PiratesWithBalls(PirateGame game)
        {
            int c = 0;

            foreach (Pirate p in game.GetMyLivingPirates())
            {
                if (p.HasPaintball)
                {
                    c++;
                }
            }
            return(c);
        }
Beispiel #11
0
 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)));
             }
         }
     }
 }
Beispiel #12
0
 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);
 }
Beispiel #13
0
 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);
     }
 }
Beispiel #14
0
 private void HandlePirates(PirateGame game)
 {
     // Go over all of my pirates
     foreach (Pirate pirate in game.GetMyLivingPirates())
     {
         if (!TryAttack(pirate, game))
         {
             // Get the first island
             Island destination = game.GetAllIslands()[0];
             // Get sail options
             List <Location> sailOptions = game.GetSailOptions(pirate, destination);
             // Set sail!
             game.SetSail(pirate, sailOptions[0]);
             // Print a message
             game.Debug("pirate " + pirate + " sails to " + sailOptions[0]);
         }
     }
 }
Beispiel #15
0
        /// <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);
        }
Beispiel #16
0
        /// <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());
        }
Beispiel #17
0
 public int AllyCloseToOurCapsule(PirateGame game)
 {
     return(game.GetMyLivingPirates().Count(pirate => pirate.InRange(game.GetMyCapsule(), 800)));
 }
Beispiel #18
0
        public List <Pirate> PiratesInRangeOfPush(PirateGame game, Pirate pirate)
        {
            List <Pirate> list = game.GetMyLivingPirates().Where(pir => pir.CanPush(pirate) && pir.PushReloadTurns == 0).ToList();

            return(xClosestToY(pirate, list.Cast <GameObject>().ToList()).Cast <Pirate>().ToList());
        }
        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)));
        }
Beispiel #20
0
 public static List <Pirate> GetMyHolders() => game.GetMyLivingPirates().Where(p => p.HasCapsule() && !HasEnemyBomb(p)).ToList();
 public void Initialize(PirateGame game)
 {
     this.game      = game;
     this.myPirates = game.GetMyLivingPirates().ToList();  // This gets overridden in MovePirates().
 }
        //--------------------------------------------


        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();
            }
        }
Beispiel #23
0
        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);
                        }
                    }
                }
            }
        }
Beispiel #24
0
        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);
                            }
                        }
                    }
                }
            }
        }