Ejemplo n.º 1
0
    // The DoTurn function is where your code goes. The PlanetWars 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 pw.IssueOrder() function. For example, to send 10 ships from
    // planet 3 to planet 8, you would say pw.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. Check out the tutorials and articles on the contest website at
    // http://www.ai-contest.com/resources.
    public static void DoTurn(PlanetWars pw)
    {
        _spaceFile = new StreamWriter("C:\\Users\\Public\\Spacelist.txt", true);
        _openFile = new StreamWriter("C:\\Users\\Public\\Openlist.txt", true);
        _closedFile = new StreamWriter("C:\\Users\\Public\\Closedlist.txt", true);

        //bij iedere beurt wordt de root knoop opnieuw gelijk gezet aan de huidige (ongemuteerde) map state
        Mapstate root = new Mapstate(pw.MyPlanets(), pw.NumShips(1), pw.EnemyPlanets(), pw.NotMyPlanets(), pw.MyFleets(),
            pw.EnemyFleets(), new List<Strategyfleet>());
        root = root.RootState(pw);

        List<Strategyfleet> ordersWillBe = strategize(root);

        //loop door de lijst van orders
        foreach (Strategyfleet move in ordersWillBe)
        {
            pw.IssueOrder(move.Bron, move.Doel, move.Sterkte);
        }

        _spaceFile.Close();
        _openFile.Close();
        _closedFile.Close();

        //pw.IssueOrder(1, 2, 2000); //onmogelijke zet zodat we de boom op beurt 1 kunnen bekijken in de log file
    }
Ejemplo n.º 2
0
    public static void DoTurn(PlanetWars pw)
    {
        // (1) If we current have a fleet in flight, then do nothing until it
        // arrives.
        if (pw.MyFleets().Count >= 1)
        {
            return;
        }
        // (2) Pick one of my planets at random.
        Random        r      = new Random();
        Planet        source = null;
        List <Planet> p      = pw.MyPlanets();

        if (p.Count > 0)
        {
            source = p[(int)(r.NextDouble() * p.Count)];
        }
        // (3) Pick a target planet at random.
        Planet dest = null;

        p = pw.Planets();
        if (p.Count > 0)
        {
            dest = p[(int)(r.NextDouble() * p.Count)];
        }
        // (4) Send half the ships from source to dest.
        if (source != null && dest != null)
        {
            int numShips = source.NumShips() / 2;
            pw.IssueOrder(source, dest, numShips);
        }
    }
Ejemplo n.º 3
0
 // The DoTurn function is where your code goes. The PlanetWars 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 pw.IssueOrder() function. For example, to send 10 ships from
 // planet 3 to planet 8, you would say pw.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. Check out the tutorials and articles on the contest website at
 // http://www.ai-contest.com/resources.
 public static void DoTurn(PlanetWars pw)
 {
     // (1) If we currently have a fleet in flight, just do nothing.
     if (pw.MyFleets().Count >= 1) {
     return;
     }
     // (2) Find my strongest planet.
     Planet source = null;
     double sourceScore = Double.MinValue;
     foreach (Planet p in pw.MyPlanets()) {
     double score = (double)p.NumShips();
     if (score > sourceScore) {
     sourceScore = score;
     source = p;
     }
     }
     // (3) Find the weakest enemy or neutral planet.
     Planet dest = null;
     double destScore = Double.MinValue;
     foreach (Planet p in pw.NotMyPlanets()) {
     double score = 1.0 / (1 + p.NumShips());
     if (score > destScore) {
     destScore = score;
     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;
     pw.IssueOrder(source, dest, numShips);
     }
 }
Ejemplo n.º 4
0
 public Mapstate RootState(PlanetWars pw)
 {
     MijnPlaneten = pw.MyPlanets();
     MijnAantalSchepen = pw.NumShips(1);
     VijandigePlaneten = pw.EnemyPlanets();
     NietMijnPlaneten = pw.NotMyPlanets();
     MijnPlaneten = pw.MyPlanets();
     VijandigeVloten = pw.EnemyFleets();
     Knoopstrategie = new List<Strategyfleet>();
     MijnVloten = pw.MyFleets();
     return this;
 }
Ejemplo n.º 5
0
    // The DoTurn function is where your code goes. The PlanetWars 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 pw.IssueOrder() function. For example, to send 10 ships from
    // planet 3 to planet 8, you would say pw.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. Check out the tutorials and articles on the contest website at
    // http://www.ai-contest.com/resources.
    public static void DoTurn(PlanetWars pw)
    {
        // (1) If we currently have a fleet in flight, just do nothing.
        if (pw.MyFleets().Count >= 1)
        {
            return;
        }
        // (2) Find my strongest planet.
        Planet source      = null;
        double sourceScore = Double.MinValue;

        foreach (Planet p in pw.MyPlanets())
        {
            double score = (double)p.NumShips();
            if (score > sourceScore)
            {
                sourceScore = score;
                source      = p;
            }
        }
        // (3) Find the weakest enemy or neutral planet.
        Planet dest      = null;
        double destScore = Double.MinValue;

        foreach (Planet p in pw.NotMyPlanets())
        {
            double score = 1.0 / (1 + p.NumShips());
            if (score > destScore)
            {
                destScore = score;
                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;
            pw.IssueOrder(source, dest, numShips);
        }
    }
Ejemplo n.º 6
0
    private static int GetNumFleetsToSend(Planet source, Planet dest, PlanetWars pw)
    {
        int distance = pw.Distance(source.PlanetID, dest.PlanetID);
        int inFlight = pw.MyFleets().Where(f => f.DestinationPlanet == dest.PlanetID && f.TurnsRemaining < distance)
                                    .Sum(f => f.NumShips);

        int shipsOnArrival = (dest.Owner == 0) ? dest.NumShips : dest.NumShips + (distance * dest.GrowthRate);
        return (shipsOnArrival  + 1) - inFlight;
    }
Ejemplo n.º 7
0
 private static bool CanSend(Planet source, Planet dest, PlanetWars pw)
 {
     int fleetsHeaded = pw.MyFleets().Where(f => f.DestinationPlanet == dest.PlanetID).Sum(f => f.NumShips);
     int destFleets = dest.NumShips;
     int sourceFleets = source.NumShips;
     return (destFleets < sourceFleets && fleetsHeaded < destFleets);
 }
Ejemplo n.º 8
0
    public static void DoTurn(PlanetWars pw)
    {
        int     numFleets  = 1;
        Boolean attackMode = false;

        if (pw.NumShips(1) > pw.NumShips(2))
        {
            if (pw.Production(1) > pw.Production(2))
            {
                numFleets  = 1;
                attackMode = true;
            }
            else
            {
                numFleets = 3;
            }
        }
        else
        {
            if (pw.Production(1) > pw.Production(2))
            {
                numFleets = 1;
            }
            else
            {
                numFleets = 5;
            }
        }
        // (1) If we current have more tha numFleets fleets in flight, just do
        // nothing until at least one of the fleets arrives.
        if (pw.MyFleets().Count >= numFleets)
        {
            return;
        }
        // (2) Find my strongest planet.
        Planet source      = null;
        double sourceScore = Double.MinValue;

        foreach (Planet p in pw.MyPlanets())
        {
            double score = (double)p.NumShips() / (1 + p.GrowthRate());
            if (score > sourceScore)
            {
                sourceScore = score;
                source      = p;
            }
        }
        // (3) Find the weakest enemy or neutral planet.
        Planet        dest       = null;
        double        destScore  = Double.MinValue;
        List <Planet> candidates = pw.NotMyPlanets();

        if (attackMode)
        {
            candidates = pw.EnemyPlanets();
        }
        foreach (Planet p in candidates)
        {
            double score = (double)(1 + p.GrowthRate()) / p.NumShips();
            if (score > destScore)
            {
                destScore = score;
                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;
            pw.IssueOrder(source, dest, numShips);
        }
    }
Ejemplo n.º 9
0
    public static void DoTurn(PlanetWars pw)
    {
        /*
         * basically I need to find out if I need to do something to maintain my advantage, by either attacking, reinforcing, or waiting
         */
        //double x = 0, y = 0;
        List<Planet> blue = pw.MyPlanets();
        List<Planet> opfor = pw.EnemyPlanets();
        List<Planet> targets = pw.NotMyPlanets();

        int opfor_army = 0;
        int opfor_production = 0;
        int blue_army = 0;
        int blue_production = 0;
        foreach (Planet p in opfor)
        {
            opfor_army += p.NumShips();
            opfor_production += p.GrowthRate();
        }
        foreach (Fleet f in pw.EnemyFleets())
        {
            opfor_army += f.NumShips();
        }
        foreach (Planet p in blue)
        {
            blue_army += p.NumShips();
            blue_production += p.GrowthRate();
        }
        foreach (Fleet f in pw.MyFleets())
        {
            blue_army += f.NumShips();
        }
        if (blue_army > opfor_army && blue_production > opfor_production)
        {
            // I win, attack
            foreach (Planet planet in blue)
            {
                targetSort = planet;
                opfor.Sort(SortTarget);
                foreach (Planet target in opfor)
                {
                    int shipsToSend = (int)Math.Floor(planet.NumShips()*0.5);
                    pw.IssueOrder(planet, target, shipsToSend);
                    planet.NumShips(planet.NumShips() - shipsToSend);
                }

            }
        }
        targets.Sort(ComparePlanetValue);
        foreach (Planet planet in blue)
        {
            foreach (Planet target in targets)
            {
                int turns = pw.Distance(planet.PlanetID(), target.PlanetID());
                int shipsToSend = target.NumShips() + (turns * target.GrowthRate()) + 1;
                int shipsSent = 0;
                foreach (Fleet fleet in pw.MyFleets())
                {
                    if (fleet.SourcePlanet() == planet.PlanetID())
                    {
                        shipsSent += fleet.NumShips();
                    }
                }
                if (planet.NumShips() > shipsToSend && shipsSent <= shipsToSend)
                {
                    int order = shipsToSend - shipsSent;
                    pw.IssueOrder(planet, target, order);
                    planet.NumShips(planet.NumShips() - order);
                }
            }

        }
        for (int i = 0; i < 3; i++)
        {
            Planet target = targets[i];
            targetSort = target;
            if (blue.Count > 1)
            {
            //    blue.Sort(SortTarget);
            }

            //pw.IssueOrder(pw.GetPlanet(blue[0].PlanetID()), target, pw.GetPlanet(blue[0].PlanetID()).NumShips() - 5);
            /*for (int j = 0; j < blue.Count; j++)
            {
                pw.IssueOrder(blue[j], target, 1);
                //blue[j].NumShips(0);
            }*/

        }
        /*foreach (Planet planet in blue)
        {
            if (planet.Owner() == 1)
            {
                foreach (Planet target in targets)
                {
                    int shipsExtra = 0;
                    int shipsSent = 0;
                    int shipsNeeded = 0;
                    shipsNeeded = target.NumShips() + 1;
                    int takeover = shipsExtra + shipsNeeded;
                    if (target.Owner() == 2)
                    {
                        int turns = pw.Distance(planet.PlanetID(), target.PlanetID());
                        takeover += turns * target.GrowthRate();
                    }
                    if (shipsSent < takeover)
                    {
                        if (planet.NumShips() <= shipsNeeded && planet.NumShips() > planet.GrowthRate()*5)
                        {
                          //  int shipsToSend = planet.NumShips();
                          //  shipsSent += shipsToSend;
                         //   pw.IssueOrder(planet, target, shipsToSend);
                         //   planet.NumShips(planet.NumShips() - shipsToSend);
                        }
                        else if (planet.NumShips() > takeover)
                        {
                            int shipsToSend = takeover;
                            shipsSent += shipsToSend;
                            pw.IssueOrder(planet, target, shipsToSend);
                            planet.NumShips(planet.NumShips() - shipsToSend);
                        }
                    }
                }
            }

        }*/

        /*

        else
        {
            if (closest != null)
            {
                int shipCount = 0;
                foreach (Planet p in blue)
                {
                    shipCount += p.NumShips();
                }
                foreach (Planet p in blue)
                {
                    if (shipCount > closest.NumShips())
                        pw.IssueOrder(p, closest, (int)Math.Floor(p.NumShips() * 0.5));
                }
            }
            if (next_closest != null)
            {
                foreach (Planet p in pw.MyPlanets())
                {
                    if (p.NumShips() > next_closest.NumShips())
                        pw.IssueOrder(p, next_closest, (int)Math.Floor(p.NumShips() * 0.5));
                }
            }
        }*/
    }