public AACalculatorConsole(Army attacker, Army defender, bool showRounds, IHitSelector hitSelector) { Attacker = attacker; Defender = defender; ShowRounds = showRounds; HitSelector = hitSelector; }
private static void Launch(Options options) { var attackingArmy = Army.Parse(options.Attacker); var defendingArmy = Army.Parse(options.Defender); IHitSelector hitSelector = options.HitMethod == "score" ? new HitSelectorByScore() : new ManualHitSelector(); var aa = new AACalculatorConsole(attackingArmy, defendingArmy, options.ShowRounds, hitSelector); aa.Launch(); }
/// <summary> /// Simulates the battle between the attacking army and the defending army and returns the result. /// </summary> /// <param name="attacker">The attacking army.</param> /// <param name="defender">The defending army.</param> /// <param name="hitSelector">The <see cref="IHitSelector"/> to use when taking causualties.</param> /// <returns>A <see cref="BattleResult"/> representing the result of the battle.</returns> public static BattleResult Calculate(Army attacker, Army defender, IHitSelector hitSelector) { return new BattleSimulator(attacker, defender, hitSelector).Simulate(); }
public static IEnumerable <HitResult> Hit(Army army, UnitType firer, Army firingArmy, decimal amt, bool attacker, IHitSelector selector) { // If the army is empty, no hits are necessary. Return such. if (army.Empty) { return(NoHits()); } var type = selector.Select(army, firer, firingArmy, amt, !attacker); // Check if the hitType is null. If so, no valid hits are possible. Thus, return an ineffective hit result for the appropriate amount. if (type == null) { return(OneHit(HitResult.NewIneffective(amt))); } // Take the appropriate number of casualties from the army and capture the result. var result = army.Hit(type, amt); // Check if the resulting hit completed the required amount. if (result.Amount == amt) { // If so, simply return that hit result. return(OneHit(result)); } else { // If not, then further hits need to be made. Recursively take away the remaining number of causualties, adding the results // to the current one. return(Hit(army, firer, firingArmy, amt - result.Amount, attacker, selector).Prepend(result)); } }
/// <summary> /// Constructs a new <see cref="BattleSimulator"/> with the given attacking/defending armies and hit selector. /// </summary> /// <param name="attacker">The attacking army.</param> /// <param name="defender">The defending army.</param> /// <param name="hitSelector">The <see cref="IHitSelector"/> to use when taking causualties.</param> public BattleSimulator(Army attacker, Army defender, IHitSelector hitSelector) { Attacker = attacker; Defender = defender; HitSelector = hitSelector; }