Exemplo 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
    }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
Arquivo: MyBot.cs Projeto: minskowl/MY
    // 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)
    {
        turn++;
        var enemyPlanet = pw.EnemyPlanets();

        maxEnemies = enemyPlanet.Count > 0 ? pw.EnemyPlanets().Max(e => e.NumShips) : 0;

        redyForEcsCount = maxEnemies / 2;
        if (redyForEcsCount == 0)
        {
            var fleets = pw.EnemyFleets();
            redyForEcsCount = fleets.Count > 0 ? fleets.Max(e => e.NumShips()) / 2 : 50;
        }
        log.WriteLine(string.Format("#########{0} My Sheeps {1} Enemy {2} Max {3}",
                                    turn, pw.NumShips(1), pw.NumShips(2), maxEnemies)
                      );

        InitSituation(pw);

        //DoHelp(pw);
        DoAttack(pw);
exit:
        log.Flush();
    }
Exemplo n.º 4
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;
                    }
                }
            }
        }
    }
Exemplo n.º 5
0
 private static int AvailableFleets(Planet p, PlanetWars pw)
 {
     int available = p.NumShips - pw.EnemyFleets().Where(f => f.DestinationPlanet == p.PlanetID).Sum(f => f.NumShips);
     return available;
 }
Exemplo n.º 6
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));
                }
            }
        }*/
    }