public int AttackWall(long day, Dictionary <long, long> wall, Dictionary <long, long> improvements) { if (Expired || !DoesAttackDay(day)) { return(0); } AttacksSoFar++; int breach = 0; for (long i = AttackInterval.Min; i <= AttackInterval.Max; i++) { if (!wall.ContainsKey(i)) { wall[i] = 0; } if (wall[i] < Strength) { breach = 1; improvements[i] = Math.Max(improvements.ContainsKey(i) ? improvements[i] : 0, Strength); } } if (AttacksSoFar == TotalNumAttacks) { Expired = true; } AttackInterval = AttackInterval.AddDelta(DeltaDistance); Strength += DeltaStrength; AttackDay += AttackPeriod; return(breach); }
public int AttackWall(long day, Dictionary <Interval, long> wall, Dictionary <Interval, long> improvements, HashSet <Interval> obsolete) { if (Expired || !DoesAttackDay(day)) { return(0); } AttacksSoFar++; int breach = 0; var overlaps = GetOverlaps(wall, AttackInterval); var segmentedAttack = new HashSet <Interval>(); segmentedAttack.Add(AttackInterval); foreach (var wallSegment in overlaps) { if (wall[wallSegment] >= Strength) { wallSegment.SubtractFrom(segmentedAttack); } else { obsolete.Add(wallSegment); } } if (segmentedAttack.Count > 0) { breach = 1; } foreach (var attackBreach in segmentedAttack) { if (improvements.ContainsKey(attackBreach)) { improvements[attackBreach] = Math.Max(Strength, improvements[attackBreach]); } else { improvements[attackBreach] = Strength; } } if (AttacksSoFar == TotalNumAttacks) { Expired = true; } AttackInterval = AttackInterval.AddDelta(DeltaDistance); Strength += DeltaStrength; AttackDay += AttackPeriod; return(breach); }