distance() public méthode

public distance ( int sourcePlanet, int destinationPlanet ) : int
sourcePlanet int
destinationPlanet int
Résultat int
Exemple #1
0
        // The DoTurn function is where your code goes. The Game object
        // contains the state of the game, including information about all planets
        // and fleets that currently exist. Inside this function, you issue orders
        // using the game.issueOrder() function. For example, to send 10 ships from
        // planet 3 to planet 8, you would say game.issueOrder(3, 8, 10).
        //
        // There is already a basic strategy in place here. You can use it as a
        // starting point, or you can throw it out entirely and replace it with
        // your own.
        public static void doTurn(Game game)
        {
            Planet source = null;
            Planet dest = null;
            // (1) If an economic planet have more than 50 ships, send 50 ships to the closest military planet.
            foreach (Planet p in game.getMyEconomicPlanets()) {
                int score = p.numShips;
                if (score > 50) {
                    source = p;
                    dest = game.findClosestMilitaryPlanet(source);
                    if (dest != null) {
                        game.issueOrder(source, dest, 50);
                    }
                }
            }

            // (2) If we currently have more than 2 fleet in flight, just do nothing.
            if (game.getMyMilitaryFleets().Count() >= 2)
            {
                return;
            }

            // (3) Find my strongest military planet.
            source = null;
            int sourceShips = int.MinValue;
            foreach (Planet p in game.getMyMilitaryPlanets()) {
                int score = p.numShips;
                if (score > sourceShips) {
                    sourceShips = score;
                    source = p;
                }
            }

            // No military planet found, just stop here.
            if (source == null)
            {
                return;
            }

            // (4) Find the closest enemy or neutral planet.
            dest = null;
            int destDist = int.MaxValue;
            foreach (Planet p in game.getNotMyPlanets()) {
                int dist = game.distance(source.id, p.id);
                if (dist < destDist) {
                    destDist = dist;
                    dest = p;
                }
            }

            // (5) Send all the ships from my strongest planet to the closest
            // planet that I do not own.
            if (source != null && dest != null) {
                int numShips = source.numShips;
                game.issueOrder(source, dest, numShips);
            }
        }
Exemple #2
0
        // The DoTurn function is where your code goes. The Game object
        // contains the state of the game, including information about all planets
        // and fleets that currently exist. Inside this function, you issue orders
        // using the game.issueOrder() function. For example, to send 10 ships from
        // planet 3 to planet 8, you would say game.issueOrder(3, 8, 10).
        //
        // There is already a basic strategy in place here. You can use it as a
        // starting point, or you can throw it out entirely and replace it with
        // your own.

        public static void doTurn(Game game)
        {
            // (1) If we currently have a fleet in flight, just do nothing.
            if (game.getMyMilitaryFleets().Count() >= 1)
            {
                return;
            }
            // (2) Find my strongest military planet.
            Planet source      = null;
            int    sourceShips = int.MinValue;

            foreach (Planet p in game.getMyMilitaryPlanets())
            {
                int score = p.numShips;
                if (score > sourceShips)
                {
                    sourceShips = score;
                    source      = p;
                }
            }

            if (source == null)
            {
                return;
            }

            // (3) Find the weakest enemy or neutral planet.
            Planet dest     = null;
            int    destDist = int.MaxValue;

            foreach (Planet p in game.getNotMyPlanets())
            {
                int dist = game.distance(source.id, p.id);
                if (dist < destDist)
                {
                    destDist = dist;
                    dest     = p;
                }
            }

            // (4) Send half the ships from my strongest planet to the weakest
            // planet that I do not own.
            if (source != null && dest != null)
            {
                int numShips = source.numShips / 2;
                game.issueOrder(source, dest, numShips);
            }
        }