Beispiel #1
0
        public void Attack(TurnManager turnManager)
        {
            //var country = GetRandomOwnedCountryThatCanAttack();
            //var countryToAttack = GetRandomAdjacentCountryToAttack(country);

            var repeat  = 0;
            var timeout = 0;

            do
            {
                var tempList = turnManager.GetGameInfo().GetAllCountriesOwnedByPlayer(this);
                foreach (var country in tempList)
                {
                    var adjacentCountryList = country.AdjacentCountries.Where(p => p.Owner != this);

                    foreach (var countryToAttack in adjacentCountryList)
                    {
                        if (countryToAttack.NumberOfTroops < country.NumberOfTroops && country.NumberOfTroops > 3)
                        {
                            turnManager.Attack(country, countryToAttack,
                                               country.NumberOfTroops - 1);
                            repeat++;
                        }
                    }
                }

                timeout++;
            } while (repeat < 2 && timeout < 200);
        }
Beispiel #2
0
Datei: Aad.cs Projekt: resc/Risk
        public void Attack(TurnManager turnManager)
        {
            for (var i = 1; i < 250; i++)
            {
                var possibleAttacks = GetAllPossibleAttacks(turnManager);

                foreach (var possibleAttack in possibleAttacks)
                {
                    possibleAttack.SuccesRate = GetSuccessRate(possibleAttack);
                }

                var myAttack = possibleAttacks.OrderBy(pa => pa.SuccesRate).Last();

                var riskRate = 900;

                if (IsLastEnemyInContinent(turnManager, myAttack.Victim))
                {
                    riskRate = 400;
                }


                if (myAttack.SuccesRate < riskRate)
                {
                    return;
                }

                turnManager.Attack(myAttack.MyCountry, myAttack.Victim, myAttack.NumberOfTroops);
            }
        }
Beispiel #3
0
        public void Attack(TurnManager turnManager)
        {
            var country         = GetRandomOwnedCountryThatCanAttack(turnManager);
            var countryToAttack = GetRandomAdjacentCountryToAttack(turnManager, country);

            turnManager.Attack(country, countryToAttack, country.NumberOfTroops - 1);
        }
Beispiel #4
0
        public void Attack(TurnManager turnManager)
        {
            gameInformation = turnManager.GetGameInfo();

            var countryToAttackWith = GetCountryToAttackWith();

            while (countryToAttackWith != null)
            {
                turnManager.Attack(countryToAttackWith.Item1, countryToAttackWith.Item2,
                                   countryToAttackWith.Item1.NumberOfTroops - 1);
                countryToAttackWith = GetCountryToAttackWith();
            }
        }
Beispiel #5
0
 public void Execute()
 {
     Succeeded = turnManager.Attack(FromCountry, ToCountry, Troops);
 }
Beispiel #6
0
        public void Attack(TurnManager turnManager)
        {
            /// [Wil je aanvallen?]
            /// 1. Als je maar net genoeg troepen hebt om je continent te verdedigen, niet of beperkt aanvallen.
            /// 2. Is er 1 of zijn er n landen om aan te vallen?
            /// 3. var countryToAttack = aanvalBareLanden.Select(x =>  { bepaal aanvalkans % o.b.v. onze troepen vs de troepen van de tegenstander }.OrderByDescending().FirstOrDefault()
            /// 4. Val land aan

            /// 5. Beoordeel resultaat, wil ik nogmaals aanvallen? Of Doel veranderen?

            try
            {
                var preferencedContinent = GetPreferencedContinent();
                var ourCountries         =
                    turnManager.GetGameInfo().GetAllCountries()
                    .Where(
                        x => x.Continent.Equals(preferencedContinent) && x.Owner == this);

                var adjecentEnemies = from ourCountry in ourCountries
                                      let enemyCountries =
                    turnManager.GetGameInfo().GetAdjacentCountriesWithDifferentOwner(
                        ourCountry)
                    select
                    new
                {
                    OurCountry   = ourCountry,
                    EnemyCountry = GetPossibleVictim(ourCountry, enemyCountries)
                };

                var victoryIsReachable = adjecentEnemies.Any(x => x.EnemyCountry != null);

                var roundsLost = 0;

                while (victoryIsReachable)
                {
                    foreach (var roundOfAttack in adjecentEnemies.Where(x => x.EnemyCountry != null))
                    {
                        if (
                            !turnManager.Attack(roundOfAttack.OurCountry,
                                                roundOfAttack.EnemyCountry,
                                                roundOfAttack.OurCountry.NumberOfTroops - 1))
                        {
                            roundsLost++;
                        }

                        if (roundsLost >= 5)
                        {
                            return;
                        }
                    }

                    ourCountries = turnManager.GetGameInfo().GetAllCountries()
                                   .Where(
                        x =>
                        x.Continent.Equals(preferencedContinent) &&
                        x.Owner == this);

                    adjecentEnemies = from ourCountry in ourCountries
                                      let enemyCountries =
                        turnManager.GetGameInfo().GetAdjacentCountriesWithDifferentOwner(
                            ourCountry)
                        select
                        new
                    {
                        OurCountry   = ourCountry,
                        EnemyCountry = GetPossibleVictim(ourCountry, enemyCountries)
                    };

                    victoryIsReachable = adjecentEnemies.Any(x => x.EnemyCountry != null);
                }
            }
            catch (RiskException)
            {
                //Attack();
            }
        }