Beispiel #1
0
            public int Start()
            {
                bool fightTied = false;

                while (ImmuneSystem.Any(g => !g.Removed) && Infection.Any(g => !g.Removed) && !fightTied)
                {
                    var unitCountBeforeRound = GroupsInTargetSelectionOrder.Sum(g => g.Units);

                    var alreadySelected = new HashSet <int>();
                    foreach (var group in GroupsInTargetSelectionOrder)
                    {
                        var target = group.SelectTarget(alreadySelected);
                        if (target != null)
                        {
                            alreadySelected.Add(target.Id);
                        }
                    }

                    foreach (var group in GroupsInAttackingOrder)
                    {
                        group.AttackTarget();
                    }

                    fightTied = unitCountBeforeRound == GroupsInTargetSelectionOrder.Sum(g => g.Units);
                }

                var immuneSystemPoints = ImmuneSystem.Where(g => g.Units >= 0).Sum(g => g.Units);
                var infectionPoints    = Infection.Where(g => g.Units >= 0).Sum(g => g.Units);

                return(Math.Max(immuneSystemPoints, infectionPoints));
            }
Beispiel #2
0
    static void Main()
    {
        string virus;
        bool   immuneSystemExists = false;
        var    immuneSystem       = new ImmuneSystem(int.Parse(ReadLine()));

        while ((virus = ReadLine()) != "end")
        {
            int virusStrength = 0, defeatTime = 0;
            immuneSystemExists = immuneSystem.EncounterVirus(virus, ref defeatTime, ref virusStrength);
            if (immuneSystemExists)
            {
                WriteLine($"Virus {virus}: {virusStrength} => {defeatTime} seconds\n" +
                          $"{virus} defeated in {ConvertToMinutes(defeatTime)}.\n" +
                          $"Remaining health: {immuneSystem.Health}");
                immuneSystem.HealSystem();
            }
            else
            {
                WriteLine($"Virus {virus}: {virusStrength} => {defeatTime} seconds\n" +
                          $"Immune System Defeated.");
                return;
            }
        }

        if (immuneSystemExists)
        {
            WriteLine($"Final Health: {immuneSystem.Health}");
        }
    }
Beispiel #3
0
    public Fight <Group> SetupFight(int boost = 0)
    {
        var groups = Groups.SelectMany(groups =>
        {
            var friendly = groups[0].Contains("Immune");
            return(groups.Skip(1)
                   .Extract <Group>(@"(?<UnitCount>\d+) units each with (?<UnitHp>\d+) hit points (?:\((?<Mods>.+?)\) )?with an attack that does (?<Damage>\d+) (?<DamageType>.+?) damage at initiative (?<Initiative>\d+)")
                   .Peek(group =>
            {
                group.Friendly = friendly;
                if (friendly)
                {
                    group.Damage += boost;
                }
            }));
        });
        var fight = new ImmuneSystem();

        fight.Units.AddRange(groups);
        return(fight);
    }