|
|
@@ -14,23 +14,25 @@ namespace D24._1
|
|
|
public bool Healthy = true;
|
|
|
public string Team { get; set; }
|
|
|
public int Number { get; set; }
|
|
|
+ public int OrigNumber { get; set; }
|
|
|
public int Initiative { get; set; }
|
|
|
public int HitPoints { get; set; }
|
|
|
public int Atk { get; set; }
|
|
|
+ public int AtkBonus { get; set; }
|
|
|
public string AtkType { get; set; }
|
|
|
public HashSet<string> Weaknesses = new HashSet<string>();
|
|
|
public HashSet<string> Immunities = new HashSet<string>();
|
|
|
- public int EffectivePower => Number * Atk;
|
|
|
+ public int EffectivePower => Number * (Atk + AtkBonus);
|
|
|
public Group Target { get; set; }
|
|
|
public bool Targeted { get; set; }
|
|
|
|
|
|
private int _computeDamage(Group target)
|
|
|
{
|
|
|
- int damage = 0;
|
|
|
- if (target.Weaknesses.Contains(AtkType))
|
|
|
- damage = 2 * EffectivePower;
|
|
|
- else if (target.Immunities.Contains(AtkType) == false)
|
|
|
- damage = EffectivePower;
|
|
|
+ if (target.Immunities.Contains(AtkType)) return 0;
|
|
|
+
|
|
|
+ int damage = EffectivePower;
|
|
|
+ if (target.Weaknesses.Contains(AtkType)) damage *= 2;
|
|
|
+
|
|
|
return damage;
|
|
|
}
|
|
|
|
|
|
@@ -43,12 +45,13 @@ namespace D24._1
|
|
|
return damage;
|
|
|
}
|
|
|
|
|
|
- public void DealDamage(Group target)
|
|
|
+ public int DealDamage(Group target)
|
|
|
{
|
|
|
var kill = target.ReceiveDamage(this);
|
|
|
#if PRINT
|
|
|
Console.WriteLine($"{Team} group {Id} attacks defending group {target.Id}, killing {kill} units");
|
|
|
#endif
|
|
|
+ return kill;
|
|
|
}
|
|
|
|
|
|
int ReceiveDamage(Group source)
|
|
|
@@ -59,13 +62,13 @@ namespace D24._1
|
|
|
kill = Math.Min(kill, Number);
|
|
|
|
|
|
Number -= kill;
|
|
|
- if (Number == 0) Healthy = false;
|
|
|
+ if (Number <= 0) Healthy = false;
|
|
|
|
|
|
return kill;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- class Program
|
|
|
+ public class Program
|
|
|
{
|
|
|
static void Main(string[] args)
|
|
|
{
|
|
|
@@ -117,7 +120,7 @@ namespace D24._1
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static void ParseFile(string[] args, out List<Group> all, out Dictionary<string, int> teams)
|
|
|
+ public static void ParseFile(string[] args, out List<Group> all, out Dictionary<string, int> teams)
|
|
|
{
|
|
|
var file = File.OpenText(args[0]);
|
|
|
|
|
|
@@ -154,6 +157,7 @@ namespace D24._1
|
|
|
|
|
|
g.Id = teams[rgroup];
|
|
|
g.Number = int.Parse(res.Groups["n"].Value);
|
|
|
+ g.OrigNumber = g.Number;
|
|
|
g.HitPoints = int.Parse(res.Groups["hp"].Value);
|
|
|
g.Atk = int.Parse(res.Groups["atk"].Value);
|
|
|
g.AtkType = res.Groups["atkt"].Value;
|
|
|
@@ -177,27 +181,31 @@ namespace D24._1
|
|
|
file.Close();
|
|
|
}
|
|
|
|
|
|
- private static void AttackPhase(List<Group> all, Dictionary<string, int> teams)
|
|
|
+ public static bool AttackPhase(List<Group> all, Dictionary<string, int> teams)
|
|
|
{
|
|
|
var attackingOrder = all
|
|
|
.OrderByDescending(s => s.Initiative);
|
|
|
|
|
|
+ int attacks = 0;
|
|
|
foreach (var group in attackingOrder)
|
|
|
{
|
|
|
if (group.Target == null) continue;
|
|
|
if (group.Healthy == false) continue;
|
|
|
|
|
|
- AttackTarget(teams, group);
|
|
|
+ var kill = AttackTarget(teams, group);
|
|
|
+ if (kill > 0) attacks++;
|
|
|
}
|
|
|
+
|
|
|
+ return attacks > 0;
|
|
|
}
|
|
|
|
|
|
- private static void AttackTarget(Dictionary<string, int> teams, Group group)
|
|
|
+ private static int AttackTarget(Dictionary<string, int> teams, Group group)
|
|
|
{
|
|
|
var target = group.Target;
|
|
|
group.Target = null;
|
|
|
target.Targeted = false;
|
|
|
|
|
|
- group.DealDamage(target);
|
|
|
+ var kill = group.DealDamage(target);
|
|
|
if (target.Healthy == false)
|
|
|
{
|
|
|
if (target.Target != null)
|
|
|
@@ -207,13 +215,14 @@ namespace D24._1
|
|
|
}
|
|
|
teams[target.Team] = teams[target.Team] - 1;
|
|
|
}
|
|
|
+ return kill;
|
|
|
}
|
|
|
|
|
|
- private static void TargetSelectionPhase(List<Group> all)
|
|
|
+ public static void TargetSelectionPhase(List<Group> all)
|
|
|
{
|
|
|
var targetingOrder = all
|
|
|
.OrderByDescending(a => a.EffectivePower)
|
|
|
- .ThenBy(a => a.Initiative);
|
|
|
+ .ThenByDescending(a => a.Initiative);
|
|
|
|
|
|
foreach (var group in targetingOrder)
|
|
|
{
|