private bool WillEnemyIceTrollKillUsBeforeWeDestroy(Elf elf, ManaFountain manaFountain)
        {
            //the range of the circle is how long it would take us to destroy the manafountain times the ElfMaxSpeed
            var circle = new Circle(manaFountain, manaFountain.CurrentHealth / Constants.Game.ElfAttackMultiplier * Constants.Game.ElfMaxSpeed);

            int timeToReachManaFountain = (elf.Distance(manaFountain) - elf.AttackRange - manaFountain.Size) / Constants.Game.ElfMaxSpeed;
            //total time it will take to kill manafountain (including getting there)
            int totalTimeToKillManaFountain = manaFountain.CurrentHealth / elf.AttackMultiplier + timeToReachManaFountain;

            //this is the location we will finally attack the manafountain from
            Location attackManaFountainLocation = manaFountain.Location.Towards(elf, manaFountain.Size + elf.AttackRange);

            foreach (IceTroll enemyIceTroll in Constants.GameCaching.GetEnemyIceTrollsInArea(circle))
            {
                int timeToReachOurAttackingLocation = enemyIceTroll.Distance(attackManaFountainLocation) / Constants.Game.IceTrollMaxSpeed;
                int totalTimeToKillUs = elf.CurrentHealth / enemyIceTroll.AttackMultiplier + timeToReachOurAttackingLocation;

                if (totalTimeToKillUs >= totalTimeToKillManaFountain)
                {
                    return(true);
                }
            }

            return(false);
        }
        private bool CanForSureSafelyReachManaFountain(Elf myElf, ManaFountain manaFountain)
        {
            //TODO, implement all these functions into GameCaching as GetEnemyIceTrollsInConeArea
            foreach (IceTroll iceTroll in Constants.GameCaching.GetEnemyIceTrolls())
            {
                //0.68f is almost about 45 degrees (not exactly but close enough)
                if (Utilities.IsLocationInCone(myElf, manaFountain, iceTroll, 0.68f))
                {
                    return(false);
                }
            }

            foreach (Elf enemyElf in Constants.GameCaching.GetEnemyLivingElves())
            {
                //0.68f is almost about 45 degrees (not exactly but close enough)
                if (Utilities.IsLocationInCone(myElf, manaFountain, enemyElf, 0.68f))
                {
                    return(false);
                }
            }

            foreach (Portal enemyPortal in Constants.GameCaching.GetEnemyPortalsCurrentlySummoningIceTrolls())
            {
                //0.68f is almost about 45 degrees (not exactly but close enough)
                if (Utilities.IsLocationInCone(myElf, manaFountain, enemyPortal, 0.68f))
                {
                    return(false);
                }
            }

            return(true);
        }
示例#3
0
        /// <summary>
        ///     returns true if the portal should defend the mana fountains
        /// </summary>
        /// <param name="p"></param>
        /// <param name="fountain"></param>
        /// <returns></returns>
        public static bool ShouldDefendFountain(this Portal p, ManaFountain fountain)
        {
            double savingDuration = 1.0 * (GameState.Game.IceTrollCost - GameState.CurrentMana) /
                                    GameState.Game.GetMyself().ManaPerTurn;

            savingDuration = System.Math.Ceiling(savingDuration);
            int responseTime = System.Math.Max(0, (int)savingDuration) + GameState.Game.IceTrollSummoningDuration + 1;

            System.Func <Elf, Location> attackLocationFunc = elf =>
                                                             fountain.Location.Towards(elf, fountain.Size + elf.AttackRange);
            System.Func <Elf, int> rangeFunc = elf =>
                                               elf.MaxSpeed * (responseTime + p.TurnsToReach(attackLocationFunc(elf), GameState.Game.IceTrollMaxSpeed));

            return(GameState.EnemyLivingElves.Count > 0 && GameState.EnemyLivingElves.Any(e => e.InRange(attackLocationFunc(e), rangeFunc(e))));
        }
        public override void UpdateState(Game game)
        {
            if (elfState != null)
            {
                bool stopPlan = false;

                if (elfState.step == ElfPlanState.Step.SpeedUp)
                {
                    if (elfState.elf.HasSpeedUp())
                    {
                        elfState.step = ElfPlanState.Step.Movement;
                    }
                    else
                    {
                        stopPlan = true;
                    }
                }
                else if (elfState.step == ElfPlanState.Step.Movement)
                {
                    Location expectedLocation = elfState.elf.GetLocation().Towards(elfState.targetLocation, elfState.elf.MaxSpeed);
                    if (elfState.elf.GetLocation().Distance(expectedLocation) > Constants.Game.ElfMaxSpeed)
                    {
                        stopPlan = true;
                    }
                    if (stopPlan)
                    {
                        ElfMoveTargets.RemoveHeuristicCircle(GetType().Name);
                        elfState = null;
                    }
                }
            }

            if (elfState == null && Constants.GameCaching.GetEnemyManaFountains().Length == 1)
            {
                foreach (Elf elf in Constants.Game.GetMyLivingElves())
                {
                    ManaFountain suitableTargetManaFountain = FindSuitableManaFountain(elfState.elf);

                    if (suitableTargetManaFountain != null)
                    {
                        elfState = CreateElfState(elf, suitableTargetManaFountain);
                        ElfMoveTargets.AddHeuristicCircleWithTurnLimit(GetType().Name, new Circle(elfState.targetLocation, Constants.Game.ManaFountainSize + Constants.Game.ElfAttackRange), numOfTurns);
                        break;
                    }
                }
            }
        }
示例#5
0
        public static bool ShouldTargetFountain(this Elf e, out ManaFountain fountain)
        {
            var closestFountain = GameState.Game.GetEnemyManaFountains().OrderBy(e.Distance).FirstOrDefault();

            if (closestFountain == null)
            {
                fountain = null;
                return(false);
            }

            int range = GameState.Game.SpeedUpMultiplier * GameState.Game.ElfMaxSpeed * GameState.Game.SpeedUpExpirationTurns;

            if (!e.InRange(e.GetAttackLocation(closestFountain), range))
            {
                fountain = null;
                return(false);
            }

            fountain = closestFountain;
            return(true);
        }
 private float GetEnemyManaFountainScore(VirtualGame virtualGame, ManaFountain manaFountain)
 {
     return(virtualGame.GetVirtualPortalsInArea(manaFountain.GetLocation(), maxDistanceFromEnemyManaFountain).Count);
 }
        private ElfPlanState CreateElfState(Elf elf, ManaFountain targetManaFountain)
        {
            Location targetLocation = targetManaFountain.GetLocation().Towards(elf, Constants.Game.ManaFountainSize + Constants.Game.ElfAttackRange);

            return(new ElfPlanState(elf, targetLocation));
        }