コード例 #1
0
        /// <summary>
        /// Makes the defender try to push an enemy pirate. Returns true if it did.
        /// If can be pushed out of the map, else push againts the motherboard.
        /// </summary>
        /// <returns> true if the pirate pushed. </returns>
        public override bool Push()
        {
            foreach (Asteroid asteroid in GameSettings.Game.GetLivingAsteroids())
            {
                if (pirate.CanPush(asteroid))
                {
                    GameSettings.Game.Debug("Pirate in Backup = " + pirate);
                    GameSettings.Game.Debug("Location in Backup = " + asteroidHandler.FindBestLocationToPushTo(this.Pirate));
                    pirate.Push(asteroid, asteroidHandler.FindBestLocationToPushTo(this.Pirate));
                    return(true);
                }
            }

            if (PirateToPush != null && WhereToPush != null)
            {
                if (pirate.CanPush(PirateToPush))
                {
                    pirate.Push(PirateToPush, WhereToPush);
                    return(true);
                }
            }

            GameSettings.Game.Debug("Front WhereToPush " + WhereToDefend);
            foreach (Pirate enemy in GameSettings.Game.GetEnemyLivingPirates())
            {
                // Check if the pirate can push the enemy.
                if (Pirate.CanPush(enemy) && enemy.HasCapsule())
                {
                    //Changed
                    //Push enemy!
                    Location outOfBorder = FieldAnalyzer.GetCloseEnoughToBorder(enemy, Pirate.PushRange);
                    if (outOfBorder != null)
                    {
                        Pirate.Push(enemy, outOfBorder);
                        return(true);
                    }
                    else
                    {
                        Location oppositeSide = enemy.GetLocation().Subtract(GameSettings.Game.GetEnemyMotherships()[0].GetLocation());
                        //Vector: the distance (x,y) you need to go through to go from the mothership to the enemy
                        oppositeSide = enemy.GetLocation().Towards(enemy.GetLocation().Add(oppositeSide), 600);
                        Pirate.Push(enemy, oppositeSide);
                        //Print a message.
                        GameSettings.Game.Debug("defender " + Pirate + " pushes " + enemy + " towards " + enemy.InitialLocation);
                        //Did push.
                        return(true);
                    }
                }
            }


            foreach (Wormhole wormhole in GameSettings.Game.GetAllWormholes())
            {
                if (wormhole.Distance(pirate) < 750)
                {
                    if (pirate.CanPush(wormhole))
                    {
                        int cols = GameSettings.Game.Cols;
                        int rows = GameSettings.Game.Rows;
                        //Push to the center for now
                        if (pirate.CanPush(wormhole))
                        {
                            pirate.Push(wormhole, new Location(rows / 2, cols / 2));
                            GameSettings.Game.Debug("Pirate pushed wormhole");
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
コード例 #2
0
ファイル: Backup.cs プロジェクト: SIGMAPlayers/UltimateBot
        /// <summary>
        /// Makes the defender try to push an enemy pirate. Returns true if it did.
        /// If can be pushed out of the map, else push againts the motherboard.
        /// </summary>
        /// <returns> true if the pirate pushed.</returns>
        public override bool Push()
        {
            foreach (Asteroid asteroid in GameSettings.Game.GetLivingAsteroids())
            {
                if (pirate.CanPush(asteroid))
                {
                    GameSettings.Game.Debug("Pirate in Backup = " + pirate);
                    GameSettings.Game.Debug("Location in Backup = " + asteroidHandler.FindBestLocationToPushTo(this.Pirate));
                    pirate.Push(asteroid, asteroidHandler.FindBestLocationToPushTo(this.Pirate));
                    return(true);
                }
            }

            if (PirateToPush != null && WhereToPush != null)
            {
                if (pirate.CanPush(PirateToPush))
                {
                    pirate.Push(PirateToPush, WhereToPush);
                    return(true);
                }
            }

            Pirate enemyToPush = Protect();

            if (enemyToPush != null)
            {
                if (pirate.CanPush(enemyToPush))
                {
                    //Sorry about those location numbers :\
                    //#Onemanarmy
                    if (GameSettings.Game.GetMyMotherships().Length == 0 && GameSettings.Game.GetMyCapsules().Length == 0)
                    {
                        pirate.Push(enemyToPush, new Location(3097, 1557));
                        return(true);
                    }
                    Location pushTowardsOutOfMap = FieldAnalyzer.GetCloseEnoughToBorder(enemyToPush, Pirate.PushDistance);
                    if (pushTowardsOutOfMap != null)
                    {
                        pirate.Push(enemyToPush, pushTowardsOutOfMap);
                        return(true);
                    }
                    else
                    {
                        if (GameSettings.Game.GetEnemyMotherships().Length > 0)
                        {
                            Location oppositeSide = enemyToPush.GetLocation().Subtract(GameSettings.Game.GetEnemyMotherships()[0].GetLocation());
                            //Vector: the distance (x,y) you need to go through to go from the mothership to the enemy
                            oppositeSide = enemyToPush.GetLocation().Towards(enemyToPush.GetLocation().Add(oppositeSide), 600);
                            Pirate.Push(enemyToPush, oppositeSide);
                            //Print a message.
                            //GameSettings.Game.Debug("defender " + Pirate + " pushes " + enemyToPush + " towards " + enemyToPush.InitialLocation);
                            //Did push.
                            return(true);
                        }
                        else
                        {
                            Location oppositeSide = enemyToPush.GetLocation().Subtract(new Location(0, 0));
                            //Vector: the distance (x,y) you need to go through to go from the mothership to the enemy
                            oppositeSide = enemyToPush.GetLocation().Towards(enemyToPush.GetLocation().Add(oppositeSide), 600);
                            Pirate.Push(enemyToPush, oppositeSide);
                        }
                        return(true);
                    }
                }
            }

            GameSettings.Game.Debug("Push distance = " + pirate.PushDistance);
            GameSettings.Game.Debug("Reached Wormhole zone");
            bool canPushWormhole = true;

            foreach (Wormhole wormhole in GameSettings.Game.GetAllWormholes())
            {
                GameSettings.Game.Debug("wormhole foreach");
                if (pirate.CanPush(wormhole))
                {
                    //GameSettings.Game.Debug("pirate.PushRange ==> " + pirate.PushRange);
                    //GameSettings.Game.Debug("pirate.MaxSpeed ==> " + pirate.MaxSpeed);
                    GameSettings.Game.Debug("wormhole.Distance(pirate)" + wormhole.Distance(pirate));

                    if (GameSettings.Game.GetEnemyMotherships().Length > 0)
                    {
                        Mothership mothership   = FieldAnalyzer.FindClosestMotherShip(pirate);
                        Pirate     enemyCarrier = FieldAnalyzer.GetMostThreatningEnemyCarrier(mothership);
                        if (enemyCarrier != null)
                        {
                            //Checks if the enemyPirate can come in more then 5 turns
                            GameSettings.Game.Debug("pirate.CanPush(wormhole) = " + pirate.CanPush(wormhole));
                            //Checks if the enemyPirate can come in more then 8 turns
                            if (enemyCarrier.Distance(pirate) < enemyCarrier.MaxSpeed * 8)
                            {
                                canPushWormhole = false;
                            }
                            if (canPushWormhole)
                            {
                                int cols = GameSettings.Game.Cols;
                                int rows = GameSettings.Game.Rows;
                                //Push to the center for now
                                pirate.Push(wormhole, new Location(rows / 2, cols / 2));
                                GameSettings.Game.Debug("Pirate pushed wormhole");
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }