Пример #1
0
        public Tuple <Army, int> Simulate(Army firstTurn, int dragons, int lords)
        {
            if (dragons < 0)
            {
                throw new ArgumentException();
            }
            if (lords < 0)
            {
                throw new ArgumentException();
            }

            var  sevenKingdomArmyStatus = new SevenKingdomArmyStatus(dragons);
            var  whiteWalkerArmyStatus  = new WhiteWalkerArmyStatus(lords);
            int  turnsAmount            = 0;
            Army currentTurn            = firstTurn;
            var  strategyPicker         = new StrategyPicker();

            while (sevenKingdomArmyStatus.IsAlive() && whiteWalkerArmyStatus.IsAlive())
            {
                var strategy = strategyPicker.GetStrategy(currentTurn);
                strategy.RunNextTurn(sevenKingdomArmyStatus, whiteWalkerArmyStatus);

                currentTurn = currentTurn == Army.SevenKingdom
                        ? Army.WhiteWalker
                        : Army.SevenKingdom;
                turnsAmount++;
            }

            return(sevenKingdomArmyStatus.IsAlive()
                ? new Tuple <Army, int>(Army.SevenKingdom, turnsAmount)
                : new Tuple <Army, int>(Army.WhiteWalker, turnsAmount));
        }
Пример #2
0
        public void RunNextTurn(SevenKingdomArmyStatus sevenKingdomArmyStatus,
                                WhiteWalkerArmyStatus whiteWalkerArmyStatus)
        {
            var damageLeft = sevenKingdomArmyStatus.Damage();

            var possibleAmountOfLordsToBeKilled = damageLeft / WhiteWalkerArmyStatus.DefenceLord;

            var actualAmountOfLordsToBeKilled = Math.Min(possibleAmountOfLordsToBeKilled,
                                                         whiteWalkerArmyStatus.Lords);

            damageLeft -= WhiteWalkerArmyStatus.DefenceLord * actualAmountOfLordsToBeKilled;
            whiteWalkerArmyStatus.Lords -= actualAmountOfLordsToBeKilled;

            var possibleAmountWalkersKilled = damageLeft / WhiteWalkerArmyStatus.DefenceWalker;

            var actualAmountWalkersKilled = Math.Min(possibleAmountWalkersKilled,
                                                     whiteWalkerArmyStatus.Walkers);

            whiteWalkerArmyStatus.Walkers -= actualAmountWalkersKilled;
        }
Пример #3
0
        public void RunNextTurn(SevenKingdomArmyStatus sevenKingdomArmyStatus,
                                WhiteWalkerArmyStatus whiteWalkerArmyStatus)
        {
            var damageLeft = whiteWalkerArmyStatus.Damage();

            var possibleAmountOfDragonsToBeKilled = damageLeft / SevenKingdomArmyStatus.DefenceDragon;

            var actualAmountOfDragonsKilled = Math.Min(possibleAmountOfDragonsToBeKilled,
                                                       sevenKingdomArmyStatus.Dragons);

            damageLeft -= SevenKingdomArmyStatus.DefenceDragon * actualAmountOfDragonsKilled;
            sevenKingdomArmyStatus.Dragons -= actualAmountOfDragonsKilled;

            var possibleAmountInfantryKilled = damageLeft / SevenKingdomArmyStatus.DefenceInfantry;

            var actualAmountInfantryKilled = Math.Min(possibleAmountInfantryKilled,
                                                      sevenKingdomArmyStatus.Infantry);

            sevenKingdomArmyStatus.Infantry -= actualAmountInfantryKilled;
        }