bool CanBuild(Elf elf, Game game, Building building = Building.Portal)
        {
            switch (building)
            {
            case Building.Portal:
                if (!elf.CanBuildPortal() || elf.AlreadyActed || elf.Distance(game.GetMyCastle()) < MinPortalBuildRadius)
                {
                    return(false);
                }
                break;

            case Building.Fountain:
                if (!elf.CanBuildManaFountain() || elf.AlreadyActed)
                {
                    return(false);
                }
                break;

            default:
                break;
            }
            foreach (Elf anElf in game.GetMyLivingElves())
            {
                if (anElf == elf)
                {
                    continue;
                }
                if (anElf.Distance(elf) <= game.PortalSize * 2 && anElf.IsBuilding)
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #2
0
        /// <summary>
        ///     returns the best mission for the elf
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public static Mission GetBestMission(this Elf e)
        {
            if (e.IsBuilding)
            {
                return(Mission.CurrentlyBuilding);
            }

            // compute optimal location now to avoid additional computation later.
            Location attackOptimalLocation = MissionExtensions.OptimalAttackingPortalLocations[e];

            if (GameState.Game.CanBuildManaFountainAt(e.Location))
            {
                if (e.ShouldBuildFountain() && e.CanBuildManaFountain() &&
                    GameState.HasManaFor(CreatableObject.ManaFountain))
                {
                    return(Mission.BuildFountain);
                }

                if (e.ShouldSaveForFountain())
                {
                    return(Mission.SaveForFountain);
                }
            }

            if (GameState.Game.CanBuildPortalAt(e.Location) &&
                e.ShouldBuildPortal(attackOptimalLocation) && e.SafeNotToMove())
            {
                System.Console.WriteLine(e.SafeNotToMove());
                if (e.CanBuildPortal() && GameState.HasManaFor(CreatableObject.Portal))
                {
                    return(Mission.BuildPortal);
                }

                // make sure we can wait for mana and that it wouldn't take so long and that its a good portal
                if (e.ShouldSaveForPortal())
                {
                    return(Mission.SaveForPortal);
                }
            }

            GameObject target = e.GetAttackTarget();

            if (target != null && e.ShouldAttack(target))
            {
                return(Mission.AttackTarget);
            }

            var moveTarget = e.GetMoveTarget();

            if (moveTarget != null && !moveTarget.Equals(target) &&
                (attackOptimalLocation == null || e.Distance(moveTarget) < e.Distance(attackOptimalLocation) || moveTarget is ManaFountain ||
                 GameState.AttackingPortals > 0))
            {
                return(Mission.MoveToTarget);
            }

            if (e.Distance(GameState.EnemyCastle) <= ElfExtensions.ATTACKING_RADIUS &&
                (GameState.AttackingPortals < ElfExtensions.MAX_ATTACKING_PORTALS ||
                 GameState.CurrentMana > ElfExtensions.EXCESS_MANA * 2) &&
                attackOptimalLocation != null && (e.ShouldSaveForPortal() || GameState.MyPortals.Count == 0))

            {
                System.Console.WriteLine(e.ShouldBuildPortal(attackOptimalLocation));
                return(Mission.MoveToBuildPortal);
            }

            return(Mission.MoveToCastle);
        }
Beispiel #3
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);
        }