示例#1
0
文件: AI.cs 项目: Vin1000/Galcon
        public void update(UpdateContainer container)
        {
            Console.Out.WriteLine("Updating");
            var analyser = new Analyser(container, name);

            if (!_firstDataReceived)
            {
                InitPlanets(container.Planets);
                this._firstDataReceived = true;
            }
            else
            {
                //mettre a jour
                this.UpdatePlanets(container.Planets);
            }
            enemyMaster = EnemyPlanets.OrderBy(p => p.ShipCount).FirstOrDefault();

            int planetsToAttack = 2;
            var closestToEnemyMaster = enemyMaster.GetClosestPlanets(planetsToAttack, false);
            switch(attackStrategy)
            {
                case 0:
                    foreach (var planet in MyPlanets)
                    {
                        foreach (var closest in closestToEnemyMaster)
                        {
                            Game.AttackPlanet(planet, closest, (int)Math.Floor((double)planet.ShipCount * 0.8 / planetsToAttack));
                        }
                    }
                    if(!closestToEnemyMaster.Any(p => p.Owner != name))
                    {
                        attackStrategy = 1;
                    }
                    break;
                case 1:
                    if (closestToEnemyMaster.Any(p => p.Owner != name))
                    {
                        attackStrategy = 0;
                    }
                    foreach(var planet in MyPlanets)
                    {
                        Game.AttackPlanet(planet, enemyMaster, (int)Math.Floor((double)planet.ShipCount * 0.8 / planetsToAttack));
                    }
                    break;
                default:
                    break;
            }

            /*
            foreach (var planet in analyser.MyPlanets)
            {
                foreach (var idle in analyser.NeutralPlanets)
                {
                    Game.AttackPlanet(planet, idle, (int)Math.Floor((double)planet.ShipCount/analyser.NeutralPlanets.Count));
                }
            }
            if (analyser.NeutralPlanets.Count == 0)
            {
                foreach (var planet in analyser.MyPlanets)
                {
                    foreach (var enemy in analyser.EnemyPlanets)
                    {
                        Game.AttackPlanet(planet, enemy, planet.ShipCount-1);
                    }
                }
            }*/
            attackCount++;
        }
示例#2
0
文件: AI.cs 项目: Vin1000/Galcon
        public void update(UpdateContainer container)
        {
            //Console.Out.WriteLine("Updating");
            if (!_firstDataReceived)
            {
                InitPlanets(container.Planets);
                this._firstDataReceived = true;
            }
            else
            {
                //mettre a jour
                this.UpdatePlanets(container.Planets);
            }

            enemyMaster = EnemyPlanets.OrderBy(p => p.ShipCount).FirstOrDefault();
            closestToEnemyMaster = enemyMaster.GetClosestPlanets(planetsToAttack, false);

            Game.DeathstarDestroyPlanet(DeathStar, enemyMaster);

            if (DeathStar.ReadyToAttackNextTurn && DeathStar.Owner != name)
            {
                attackStrategy = 3;
            }

            switch (attackStrategy)
            {
                case 0:
                    Strategy0();
                    break;
                case 1:
                    Strategy1();
                    break;
                case 2:
                    Strategy2();
                    break;
                case 3:
                    Strategy3();
                    break;
                default:
                    //Console.Out.WriteLine("Error attackStrategy: " + attackStrategy);
                    break;
            }
            attackCount++;
        }