Example #1
0
 public void Move(TurnManager turnManager)
 {
     turnManager.MoveTroops(GetRandomOwnedCountryThatCanAttack(turnManager),
                                                   GetRandomOwnedCountryThatCanAttack(turnManager), 1);
 }
Example #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);
                }
            }
        }
Example #3
0
File: Pros.cs Project: resc/Risk
        public void Move(TurnManager turnManager)
        {
            var movesLeft = 7;

            var tempList = turnManager.GetGameInfo().GetAllCountriesOwnedByPlayer(this);

            foreach (var country in tempList)
            {
                if (country.NumberOfTroops > 1)
                {
                    var hasHostile = false;
                    var checkForHostileCountries =
                        country.AdjacentCountries.Where(p => p.Owner != this).ToList();

                    if (checkForHostileCountries.Count > 0)
                    {
                        hasHostile = true;
                    }

                    if (hasHostile == false)
                    {
                        var adjacentCountryListOwned =
                            country.AdjacentCountries.Where(p => p.Owner == this).ToList();

                        foreach (var countryToMove in adjacentCountryListOwned)
                        {
                            var adjacentCountryListEnemey =
                                countryToMove.AdjacentCountries.Where(p => p.Owner != this).ToList();
                            var hasHostile2 = false;
                            if (adjacentCountryListEnemey.Count > 0)
                            {
                                hasHostile2 = true;
                            }

                            if (hasHostile2)
                            {
                                if (country.NumberOfTroops - 1 > 0 && movesLeft > 0)
                                {
                                    if (movesLeft > (country.NumberOfTroops - 1))
                                    {
                                        turnManager.MoveTroops(country, countryToMove,
                                                                                      country.NumberOfTroops - 1);
                                        movesLeft = movesLeft - (country.NumberOfTroops - 1);
                                    }
                                    else
                                    {
                                        turnManager.MoveTroops(country, countryToMove, movesLeft);
                                        movesLeft = 0;
                                    }
                                }
                            }
                            else
                            {
                                var adjacentCountryListOwned2 =
                                    countryToMove.AdjacentCountries.Where(p => p.Owner == this).ToList();

                                foreach (var countryToMove2 in adjacentCountryListOwned2)
                                {
                                    var adjacentCountryListEnemey2 =
                                        countryToMove2.AdjacentCountries.Where(p => p.Owner != this).ToList();
                                    var hasHostile3 = false;
                                    if (adjacentCountryListEnemey2.Count > 0)
                                    {
                                        hasHostile3 = true;
                                    }

                                    if (hasHostile3)
                                    {
                                        if (country.NumberOfTroops - 1 > 0 && movesLeft > 0)
                                        {
                                            if (movesLeft > (country.NumberOfTroops - 1))
                                            {
                                                turnManager.MoveTroops(country, countryToMove,
                                                                                              country.NumberOfTroops - 1);
                                                movesLeft = movesLeft - (country.NumberOfTroops - 1);
                                            }
                                            else
                                            {
                                                turnManager.MoveTroops(country, countryToMove,
                                                                                              movesLeft);
                                                movesLeft = 0;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        //hmm
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #4
0
File: Aad.cs Project: resc/Risk
 private void MoveTroopsToSurroundingCountries(TurnManager turnManager, Country country)
 {
     turnManager.MoveTroops(country, GetMostImportantSurroundingCountry(turnManager, country), 1);
 }