Exemplo n.º 1
0
        public List <Action> GenerateActions()
        {
            List <Action> actions = new List <Action>();

            if (elf.IsBuilding)
            {
                return(actions);
            }

            //can we place a portal here?
            if (elf.CanBuildPortal())
            {
                actions.Add(new BuildPortalAction(elf));
            }

            if (elf.CanBuildManaFountain())
            {
                actions.Add(new BuildManaFountainAction(elf));
            }

            if (elf.CanCastInvisibility())
            {
                actions.Add(new CastInvisibility(elf));
            }

            if (Constants.Game.ElfMaxSpeed != 0)
            {
                if (elf.CanCastSpeedUp() && !elf.IsBuilding)
                {
                    actions.Add(new CastSpeedUp(elf));
                }

                //check movement in every direction in 5 degrees steps
                for (int i = 0; i < 360; i += 5)
                {
                    Location newLocation = elf.GetNewLocation(i, elf.MaxSpeed /*(elf.MaxSpeed + Constants.Game.ElfMaxSpeed) / 2*/);

                    if (newLocation.InMap())
                    {
                        actions.Add(new MoveAction(elf, newLocation));
                    }
                }

                /*foreach (Location permMoveLocation in ElfMoveTargets.PermanentMoveLocations)
                 * {
                 *  Location newLocation = elf.GetLocation().Towards(permMoveLocation, (elf.MaxSpeed + Constants.Game.ElfMaxSpeed) / 2);
                 *
                 *  actions.Add(new MoveAction(elf, newLocation));
                 * }
                 *
                 * foreach (Location moveLocation in moveTargets.moveLocations)
                 * {
                 *  Location newLocation = elf.GetLocation().Towards(moveLocation, (elf.MaxSpeed + Constants.Game.ElfMaxSpeed) / 2);
                 *
                 *  actions.Add(new MoveAction(elf, newLocation));
                 * }*/
            }

            //We used to use InRange here (and also in other places in the bot) but we actually found InRange to be too unreliable and sometimes didn't return the expected results. So we check manually.

            if (Constants.Game.GetVolcano().IsActive() && Constants.Game.GetVolcano().DamageByEnemy <= Constants.Game.VolcanoMaxHealth / 2 && elf.Distance(Constants.Game.GetVolcano()) <= (Constants.Game.ElfAttackRange + Constants.Game.VolcanoSize))
            {
                actions.Add(new AttackAction(elf, Constants.Game.GetVolcano()));
            }

            if (elf.Distance(Constants.Game.GetEnemyCastle()) <= (Constants.Game.ElfAttackRange + Constants.Game.CastleSize))
            {
                actions.Add(new AttackAction(elf, Constants.Game.GetEnemyCastle()));
            }

            foreach (Portal enemyPortal in Constants.GameCaching.GetEnemyPortals())
            {
                if (elf.Distance(enemyPortal) <= (Constants.Game.ElfAttackRange + enemyPortal.Size))
                {
                    actions.Add(new AttackAction(elf, enemyPortal));
                }
            }

            foreach (ManaFountain enemyGameObject in Constants.GameCaching.GetEnemyManaFountains())
            {
                if (elf.Distance(enemyGameObject) <= (Constants.Game.ElfAttackRange + enemyGameObject.Size))
                {
                    actions.Add(new AttackAction(elf, enemyGameObject));
                }
            }



            foreach (Elf enemyGameObject in Constants.GameCaching.GetEnemyLivingElves())
            {
                if (elf.Distance(enemyGameObject) <= Constants.Game.ElfAttackRange)
                {
                    actions.Add(new AttackAction(elf, enemyGameObject));
                }
            }

            foreach (GameObject enemyGameObject in Constants.GameCaching.GetEnemyCreatures())
            {
                if (elf.Distance(enemyGameObject) <= Constants.Game.ElfAttackRange)
                {
                    actions.Add(new AttackAction(elf, enemyGameObject));
                }
            }

            return(actions);
        }
Exemplo n.º 2
0
        public void DoTurn(Game game)
        {
            turnsWithoutTrolls++;
            int startingMana = game.GetMyMana();

            Elf[]    enemyElves;
            Elf[]    myElves = game.GetMyLivingElves();
            Portal[] portals = game.GetMyPortals();
            totalPortals += portals.Length;
            if (game.Turn % 100 == 0)
            {
                buildRange = 2800;
                if (game.Turn < 400)
                {
                    buildRange = 2300;
                }
                if (game.Turn < 200)
                {
                    buildRange = 1800;
                }
            }
            if (game.GetMyCastle().CurrentHealth < 125 && buildRange > 2300)
            {
                buildRange = 2300;
            }
            if (game.GetMyCastle().CurrentHealth < 100 && buildRange > 1800)
            {
                buildRange = 1800;
            }
            if (game.GetMyCastle().CurrentHealth < 50 && buildRange > 1300)
            {
                buildRange = 1300;
            }
            if (portals.Length >= 1)
            {
                if (turnsWithoutTrolls >= 8)
                {
                    bool       flag        = false;
                    Creature[] enemyGiants = game.GetEnemyLavaGiants();
                    if (enemyGiants != null && !flag)
                    {
                        foreach (Creature giant in enemyGiants)
                        {
                            if (giant.Distance(game.GetMyCastle()) <= 2000)
                            {
                                Portal currentBest = FindNearest(giant, game);
                                if (currentBest.CanSummonIceTroll() && !flag)
                                {
                                    currentBest.SummonIceTroll();
                                    flag = true;
                                }
                                break;
                            }
                        }
                    }
                    enemyElves = game.GetAllEnemyElves();
                    if (enemyElves != null)
                    {
                        foreach (Elf elf in enemyElves)
                        {
                            if (elf.Location == null)
                            {
                                continue;
                            }
                            foreach (Portal current in portals)
                            {
                                if (elf.Distance(current) <= 700)
                                {
                                    if (current.CanSummonIceTroll() && !flag)
                                    {
                                        current.SummonIceTroll();
                                        flag = true;
                                    }
                                }
                            }
                        }
                    }
                    if (enemyElves != null)
                    {
                        foreach (Elf elf in enemyElves)
                        {
                            if (elf.Location == null)
                            {
                                continue;
                            }
                            if (elf.Distance(game.GetMyCastle()) <= 2000)
                            {
                                Portal currentBest = FindNearest(game.GetMyCastle(), game);
                                if (currentBest.CanSummonIceTroll() && !flag)
                                {
                                    currentBest.SummonIceTroll();
                                    flag = true;
                                }
                                break;
                            }
                        }
                    }
                    if (flag)
                    {
                        turnsWithoutTrolls = 0;
                    }
                }
                if (game.Turn % 40 == 1 && game.Turn > 1)
                {
                    Portal currentBest = FindNearest(game.GetEnemyCastle(), game);
                    if (currentBest.CanSummonLavaGiant())
                    {
                        currentBest.SummonLavaGiant();
                    }
                    else if (portals[0].CanSummonLavaGiant())
                    {
                        portals[0].SummonLavaGiant();
                    }
                }
                game.Debug("Average portals: " + (float)totalPortals / game.Turn);
                if ((game.Turn >= 600 && (totalPortals / game.Turn <= portals.Length)) || (game.GetMyCastle().CurrentHealth < 40 && game.GetMyMana() > 50))
                {
                    Portal currentBest = FindNearest(game.GetEnemyCastle(), game);
                    if (currentBest.CanSummonLavaGiant())
                    {
                        currentBest.SummonLavaGiant();
                    }
                    foreach (Portal portal in game.GetMyPortals())
                    {
                        if (portal.CanSummonLavaGiant())
                        {
                            portal.SummonLavaGiant();
                        }
                    }
                }
            }
            if (myElves.Length < 1)
            {
                return;
            }
            if (PortalsInRadius(1300, game) >= 4)
            {
                DefendAgainst(game.GetAllEnemyElves(), game, myElves, 0, 300);
                DefendAgainst(game.GetEnemyPortals(), game, myElves, enemyAggressivePortalRangeFromCastle, 700);
            }
            else
            {
                if (game.GetMyMana() > 100)
                {
                    if (myElves[0].CanBuildPortal() && !myElves[0].AlreadyActed)
                    {
                        myElves[0].BuildPortal();
                    }
                    else
                    {
                        BuildInRadius(1300, myElves[0], game);
                    }
                }
            }
            if (myElves.Length >= 1 && !myElves[0].AlreadyActed)
            {
                if (game.GetMyMana() > 100 && PortalsInRadius(buildRange, game) < 5)
                {
                    if (myElves[0].CanBuildPortal() && !myElves[0].AlreadyActed)
                    {
                        myElves[0].BuildPortal();
                    }
                    else
                    {
                        BuildInRadius(buildRange, myElves[0], game);
                    }
                }
            }
            DefendAgainst(game.GetAllEnemyElves(), game, myElves, 0, 300);
            DefendAgainst(game.GetEnemyPortals(), game, myElves, enemyAggressivePortalRangeFromCastle, 700);
            DefendAgainst(game.GetAllEnemyElves(), game, myElves, 1500, 500);
            DefendAgainst(game.GetEnemyLavaGiants(), game, myElves);
            //Defult 1 - defend portals
            DefendOn(game.GetMyPortals(), game.GetEnemyLivingElves(), myElves, 750);
            //Defult 2 - look at enemies
            if (game.GetEnemyLivingElves().Length > 0)
            {
                for (int i = 1; i < myElves.Length; i++)
                {
                    if (myElves[i].AlreadyActed)
                    {
                        continue;
                    }
                    Elf nearestElf = game.GetEnemyLivingElves()[0];
                    foreach (var item in game.GetEnemyLivingElves())
                    {
                        if (item.Distance(myElves[i]) < nearestElf.Distance(myElves[i]))
                        {
                            nearestElf = item;
                        }
                    }
                    double degree = DegreeBetween(nearestElf.Location, game.GetMyCastle().Location);
                    myElves[i].MoveTo(Cis(defendRadius, degree, game.GetMyCastle().Location));
                }
            }
            //Defult 3 - pretend you're working
            foreach (var elf in myElves)
            {
                if (elf.AlreadyActed)
                {
                    continue;
                }
                if (game.GetMyMana() > 100 && PortalsInRadius(1300, game) < 5 && elf.CanBuildPortal())
                {
                    elf.BuildPortal();
                    continue;
                }
                BuildInRadius(buildRange, elf, game);
            }
            manaWasted += startingMana - game.GetMyMana();
            game.Debug(manaWasted);
        }