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
Archivo: MyBot.cs Proyecto: minskowl/MY
    private static Planet GetToAttack(PlanetWars pw, Planet source)
    {
        // (3) Find the weakest enemy or neutral planet.
        Planet dest = null;

        log.WriteLine("========== Enemy planets ====");
        double destScore = Double.MinValue;

        foreach (Planet p in pw.NotMyPlanets())
        {
            int    requiredShips = GetPlannedShips(pw, p);
            var    distance      = pw.Distance(source.PlanetID, p.PlanetID);
            var    rate          = p.GrowthRate;
            double score         = (double)rate / (double)(requiredShips * distance);

            log.WriteLine("Planet ID={0} Score={6} Owner{1} Ships={2} GrowthRate={3} Dist={4} requiredShips={5}",
                          p.PlanetID, p.Owner, p.NumShips, rate, distance, requiredShips, score);

            if (score > destScore)
            {
                destScore = score;
                dest      = p;
            }
        }
        return(dest);
    }
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
    public static void DoTurn(PlanetWars pw)
    {
        if (CurrentTurn == 0 && pw.Distance(pw.MyPlanets().First().PlanetID, pw.EnemyPlanets().First().PlanetID) <= 8)
            IsKamikazi = true;

        if (IsKamikazi)
        {
            foreach (var planet in pw.MyPlanets())
            {
                var enemy = pw.EnemyPlanets().FirstOrDefault();
                int shipsHeaded = pw.Fleets().Where(f => f.DestinationPlanet == planet.PlanetID).Sum(f => f.NumShips);
                if (enemy != null)
                {
                    if (planet.NumShips - shipsHeaded - 1 > 0)
                        pw.IssueOrder(planet, enemy, planet.NumShips - shipsHeaded - 1);
                }
                else
                {
                    foreach (int dest in pw.EnemyFleets().Select(f => f.DestinationPlanet).Distinct())
                    {
                        if (dest == planet.PlanetID)
                            break;

                        int headedTo = pw.EnemyFleets().Where(f => f.DestinationPlanet == dest).Sum(f => f.NumShips);
                        int numToSend = ( (planet.NumShips - shipsHeaded) > headedTo) ? headedTo + 1 : (planet.NumShips - shipsHeaded);

                        if (numToSend > 0)
                            pw.IssueOrder(planet, pw.GetPlanet(dest), numToSend);
                    }
                }
            }
        }
        else
        {
            foreach (var planet in pw.MyPlanets())
            {
                int available = AvailableFleets(planet, pw);
                var enemy = pw.NotMyPlanets().Where(p => CanSend(planet, p, pw));
                enemy = enemy.OrderBy(p => GetScore(planet, p, pw));
                int skip = 0;

                while (available > 0)
                {
                    var bestEnemy = enemy.Skip(skip).FirstOrDefault();
                    skip++;

                    if (bestEnemy != null)
                    {
                        int numToSend = GetNumFleetsToSend(planet, bestEnemy, pw);
                        if (available > numToSend)
                        {

                            pw.IssueOrder(planet, bestEnemy, numToSend);
                            available = available - numToSend;
                        }
                    }
                    else
                    {
                        available = 0;
                    }
                }
            }
        }
    }
Ejemplo n.º 7
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.º 8
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));
                }
            }
        }*/
    }