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)); }
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; }
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; }