Ejemplo n.º 1
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());
        }