Exemple #1
0
        private void DeployRemaining(TurnManager turnManager, RiskAnalysis analysis, int troops, GameInformation gameInfo)
        {
            if (troops <= 0)
            {
                return;
            }
            // deploy remainder evenly...
            var deployments = gameInfo.GetAllCountriesOwnedByPlayer(_player)
                              .OrderBy(x => x.NumberOfTroops)
                              .Select(x => new Deployment(turnManager)
            {
                ToCountry = x
            })
                              .ToList();

            while (troops > 0)
            {
                foreach (var deployment in deployments.TakeWhile(deployment => -- troops >= 0))
                {
                    deployment.Troops++;
                }
            }

            analysis.Deployments.AddRange(deployments.Where(x => x.Troops > 0));
        }
Exemple #2
0
        public void Move(TurnManager turnManager)
        {
            var countriesToAimAt =
                gameInformation.GetAllCountriesOwnedByPlayer(this)
                .Where(x => gameInformation.GetAdjacentCountriesWithSameOwner(x).Any())
                .ToArray();

            if (countriesToAimAt.Any())
            {
                //Determine defensiveRate.
                //While there are countries with low defensiveRate (number of own troops / number of surrounding troups), make those stronger.
                var countriesWithEnemyNeighbours =
                    countriesToAimAt.Where(x => gameInformation.GetAdjacentCountriesWithDifferentOwner(x).Count > 0)
                    .ToArray();
                var defensiveRates =
                    GetDefensiveRates(countriesWithEnemyNeighbours).OrderBy(x => x.Value);

                var moveCounter = 0;

                while (defensiveRates.Any(x => x.Value < DEFENSIVE_THRESHOLD_FOR_DEPLOYMENT) && moveCounter++ < 250)
                {
                    var first = defensiveRates.First();

                    var adjacentCountriesWithSameOwner =
                        gameInformation.GetAdjacentCountriesWithSameOwner(first.Key)
                        .Where(
                            x =>
                            defensiveRates.Single(y => y.Key == x).Value >
                            DEFENSIVE_THRESHOLD_FOR_DEPLOYMENT)
                        .ToArray();
                    if (adjacentCountriesWithSameOwner.Any())
                    {
                        turnManager.MoveTroops(first.Key, adjacentCountriesWithSameOwner.First(),
                                               adjacentCountriesWithSameOwner.First()
                                               .NumberOfTroops - 1);
                    }

                    defensiveRates = GetDefensiveRates(countriesWithEnemyNeighbours).OrderBy(x => x.Value);
                }
            }
        }
Exemple #3
0
        public void Deploy(TurnManager turnManager, int numberOfTroops)
        {
            gameInformation = turnManager.GetGameInfo();

            //exclude all isolated countries (all countries with only enemy neighbours)
            var countriesToAimAt =
                gameInformation.GetAllCountriesOwnedByPlayer(this)
                .Where(x => gameInformation.GetAdjacentCountriesWithSameOwner(x).Any())
                .ToArray();

            //Determine defensiveRate.
            //While there are countries with low defensiveRate (number of own troops / number of surrounding troups), make those stronger.
            var countriesWithEnemyNeighbours =
                countriesToAimAt.Where(x => gameInformation.GetAdjacentCountriesWithDifferentOwner(x).Count > 0)
                .ToArray();
            var defensiveRates =
                GetDefensiveRates(countriesWithEnemyNeighbours).OrderBy(x => x.Value);

            while (defensiveRates.First().Value < DEFENSIVE_THRESHOLD_FOR_DEPLOYMENT && numberOfTroops > 0)
            {
                turnManager.DeployTroops(defensiveRates.First().Key, 1);
                defensiveRates = GetDefensiveRates(countriesWithEnemyNeighbours).OrderByDescending(x => x.Value);
                numberOfTroops--;
            }

            //Get the continent with the biggest presence.
            //Determine what country has the highest defensiveRate (number of own troops / number of surrounding troups), make those even stronger.
            //Make sure this ratio is not too big.
            var biggestContinent = GetBiggestOwnedContinentWithRemainingEnemyCountries();

            var allOwnCountriesInBiggestContinent =
                countriesToAimAt.Where(x => x.Continent == biggestContinent.Key).ToArray();
            var countriesWithRates =
                GetDefensiveRates(allOwnCountriesInBiggestContinent)
                .Where(x => x.Key.NumberOfTroops < MAX_TROOPS_FOR_DEPLOYMENT)
                .OrderByDescending(x => x.Value);

            while (countriesWithRates.Any() && numberOfTroops > 0)
            {
                turnManager.DeployTroops(countriesWithRates.First().Key, 1);
                countriesWithRates =
                    GetDefensiveRates(allOwnCountriesInBiggestContinent)
                    .Where(x => x.Key.NumberOfTroops < MAX_TROOPS_FOR_DEPLOYMENT)
                    .OrderByDescending(x => x.Value);
                numberOfTroops--;
            }

            while (numberOfTroops > 0)
            {
                turnManager.DeployTroops(GetRandomOwnedCountry(turnManager), 1);
                numberOfTroops--;
            }
        }