private float GetElfScore(VirtualGame virtualGame, FutureLocation elfFutureLocation)
        {
            IceTroll[] enemyIceTrolls = Constants.GameCaching.GetEnemyIceTrolls();

            float score = 0;

            foreach (IceTroll enemyIceTroll in enemyIceTrolls)
            {
                if (enemyIceTroll.CurrentHealth == 1)
                {
                    continue;
                }

                float distance             = elfFutureLocation.GetFutureLocation().DistanceF(enemyIceTroll);
                float avoidRadiusFromTroll = avoidRadius;
                if (elfFutureLocation.GetElf().CurrentHealth < whatIsNotMuchHealth)
                {
                    avoidRadiusFromTroll += addMoreElfMaxStepsToAvoidRadiusWhenElfHasNotMuchHealth;
                }

                avoidRadiusFromTroll = Mathf.Min(avoidRadiusFromTroll, enemyIceTroll.CurrentHealth * enemyIceTroll.MaxSpeed + enemyIceTroll.AttackRange);

                if (distance < avoidRadiusFromTroll)
                {
                    score -= avoidRadiusFromTroll - distance;
                }
            }

            return(score);
        }
Beispiel #2
0
        private float GetScore(Dictionary <int, FutureLocation> myFutureElfLocations, Dictionary <int, GameObject> enemyGameObjects)
        {
            float score = 0;

            while (myFutureElfLocations.Count > 0 && enemyGameObjects.Count > 0)
            {
                float bestScore = 0;
                bool  iterated  = false;

                int myElfUniqueId           = -1;
                int enemyGameObjectUniqueId = -1;

                foreach (KeyValuePair <int, FutureLocation> myFutureElfLocation in myFutureElfLocations)
                {
                    FutureLocation elfFutureLocation = myFutureElfLocation.Value;
                    foreach (KeyValuePair <int, GameObject> enemyGameObjectPair in enemyGameObjects)
                    {
                        float tempScore = GetPairScore(enemyGameObjectPair, elfFutureLocation.GetFutureLocation());
                        foreach (Spell spell in elfFutureLocation.GetElf().CurrentSpells)
                        {
                            if (spell is SpeedUp)
                            {
                                tempScore = tempScore * GetSpeedUpMultiplier();
                                break;
                            }
                        }
                        if (!iterated || tempScore > bestScore)
                        {
                            iterated  = true;
                            bestScore = tempScore;

                            myElfUniqueId           = myFutureElfLocation.Key;
                            enemyGameObjectUniqueId = enemyGameObjectPair.Key;
                        }
                    }
                }

                myFutureElfLocations.Remove(myElfUniqueId);
                enemyGameObjects.Remove(enemyGameObjectUniqueId);

                score += bestScore;
            }

            return(score);
        }
        private float GetElfScore(FutureLocation elfFutureLocation)
        {
            Location curLocation    = elfFutureLocation.GetElf().GetLocation();
            Location futureLocation = elfFutureLocation.GetFutureLocation();

            if (curLocation.Row == futureLocation.Row && curLocation.Col == futureLocation.Col)
            {
                return(0);
            }
            if (!Constants.Game.CanBuildPortalAt(curLocation))
            {
                return(0);
            }
            if (Constants.GameCaching.GetMyManaFountainsInArea(new Circle(curLocation, maxDistFromMyManaFountain)).Count == 0)
            {
                return(0);
            }

            return(-1);
        }
        private float GetElfScore(VirtualGame virtualGame, Elf sourceElf)
        {
            FutureLocation elfFutureLocation = virtualGame.GetFutureLocation(sourceElf);

            float score = 0;

            foreach (KeyValuePair <int, FutureLocation> myOtherElfPair in virtualGame.GetFutureLocations())
            {
                Location myOtherElfFutureLocation = myOtherElfPair.Value.GetFutureLocation();

                float distance = elfFutureLocation.GetFutureLocation().DistanceF(myOtherElfFutureLocation);

                if (myOtherElfPair.Key != sourceElf.UniqueId && distance < avoidRadius)
                {
                    score -= avoidRadius - distance;
                }
            }

            return(score);
        }
        private float GetEnemyElfScore(VirtualGame virtualGame, Elf myElf)
        {
            if (Constants.GameCaching.GetEnemyElvesInArea(new Circle(myElf, Constants.Game.ElfAttackRange)).Count > 0)
            {
                return(0);
            }

            //The future location of the given elf
            FutureLocation elfFutureLocation = virtualGame.GetFutureLocation(myElf);
            //Get all enemy elves in area near the future location elf within `radius`
            List <Elf> enemyElves = Constants.GameCaching.GetEnemyElvesInArea(new Circle(elfFutureLocation.GetFutureLocation(), radius));

            if (enemyElves.Count == 0)
            {
                return(0);                       //if there are no enemy elves, return 0
            }
            Dictionary <int, GameObject> myElves = new Dictionary <int, GameObject>();

            float enemyCombinedHealth = 0;
            float minimumDistance     = radius;

            foreach (Elf enemyElf in enemyElves)
            {
                //add combined health of enemy elf
                enemyCombinedHealth += enemyElf.CurrentHealth;

                //get distance from enemyElf to my elf's future location
                float distanceToMyElf = enemyElf.DistanceF(elfFutureLocation.GetFutureLocation());

                //if the distance is less than the minimum distance, set the minimum distance
                if (distanceToMyElf < minimumDistance)
                {
                    minimumDistance = distanceToMyElf;
                }

                //add all of my elves within radius of enemy elf based on future location
                foreach (GameObject elf in enemyElf.GetMyLivingElvesInAreaBasedOnFutureLocation(virtualGame, radius))
                {
                    myElves[elf.UniqueId] = elf;
                }
            }

            float ourCombinedHealth = myElf.CurrentHealth;

            //add all combined health of our elves
            foreach (KeyValuePair <int, GameObject> pair in myElves)
            {
                if (myElf.UniqueId == pair.Key)
                {
                    continue;
                }
                ourCombinedHealth += pair.Value.CurrentHealth;
            }

            //if we are weaker than the enemy
            if (ourCombinedHealth < enemyCombinedHealth)
            {
                return(0);
            }
            //if we are equal in power to the enemy
            else if (ourCombinedHealth == enemyCombinedHealth)
            {
                //go through each enemy elf
                foreach (GameObject enemyElf in enemyElves)
                {
                    //if the enemy elf is on our castle side
                    if (enemyElf.OnSameSideAsCastle()) //if enemy elf is our side of the map
                    {
                        return(radius - minimumDistance);
                    }
                }

                //if we didn't find any elves on our castle side, return 0
                return(0);
            }

            return((radius - minimumDistance) * ourCombinedHealth / enemyCombinedHealth);
        }
Beispiel #6
0
 public Point3D GetFutureLocation()
 {
     return(FutureLocation.GetFutureLocation(X, Y, Z, Shifts.Dx, Shifts.Dy, Shifts.Dz,
                                             Tracker, Path, CalcAndSetShifts, AircraftOptions.PredictInterval));
 }
Beispiel #7
0
        private float GetMyElfScore(VirtualGame virtualGame, Elf myElf)
        {
            FutureLocation elfFutureLocation = virtualGame.GetFutureLocation(myElf);
            float          useRadius         = radius;

            if (myElf.CurrentHealth < whatIsNotMuchHealth)
            {
                useRadius = radiusWhenDontHaveMuchHealth;
            }

            List <Elf> enemyElves = elfFutureLocation.GetFutureLocation().GetEnemyLivingElvesInArea(useRadius);

            if (enemyElves.Count == 0)
            {
                return(0);
            }

            Dictionary <int, GameObject> myElves = new Dictionary <int, GameObject>();

            int   enemyCombinedHealth = 0;
            float minimumDistance     = useRadius;

            foreach (Elf enemyElf in enemyElves)
            {
                enemyCombinedHealth += enemyElf.CurrentHealth;

                float distanceToMyElf = enemyElf.DistanceF(elfFutureLocation.GetFutureLocation());

                if (distanceToMyElf < minimumDistance)
                {
                    minimumDistance = distanceToMyElf;
                }

                foreach (Elf elf in enemyElf.GetMyLivingElvesInAreaBasedOnFutureLocation(virtualGame, useRadius))
                {
                    myElves[elf.UniqueId] = elf;
                }
            }

            float ourCombinedHealth = 0;

            foreach (KeyValuePair <int, GameObject> pair in myElves)
            {
                ourCombinedHealth += pair.Value.CurrentHealth;
            }

            if (ourCombinedHealth == enemyCombinedHealth)
            {
                foreach (GameObject enemyElf in enemyElves)
                {
                    //if (enemyElf.OnSameSideAsCastle()) //if enemy elf is our side of the map
                    if (enemyElf.Distance(myElf) <= Constants.Game.ElfAttackRange || enemyElf.OnSameSideAsCastle())
                    {
                        return(0);
                    }
                }
            }
            else if (ourCombinedHealth > enemyCombinedHealth)
            {
                return(0);
            }

            /*don't round to int.
             * We should consider calculating the enemy health only if its turnsToBuild<2 (only remember this but don't implement it)
             * There are more differences but I prefer what you implemented. Lets see how it works.*/
            ourCombinedHealth = Mathf.Max(1f, myElf.CurrentHealth - 2);
            float factor = (enemyCombinedHealth / ourCombinedHealth);
            float diffDistFromMyCastle = myElf.GetLocation().Distance(Constants.Game.GetMyCastle()) - elfFutureLocation.GetFutureLocation().Distance(Constants.Game.GetMyCastle());

            if (diffDistFromMyCastle > Constants.Game.ElfMaxSpeed * 0.5f)
            {
                return(-1 * useRadius * factor);
            }
            else
            {
                return(-1 * (useRadius - minimumDistance) * factor);
            }
        }