diff --git a/MultiversalDiplomacy/Adjudicate/Decision/MovementDecisions.cs b/MultiversalDiplomacy/Adjudicate/Decision/MovementDecisions.cs index d1bc9bd..66b8976 100644 --- a/MultiversalDiplomacy/Adjudicate/Decision/MovementDecisions.cs +++ b/MultiversalDiplomacy/Adjudicate/Decision/MovementDecisions.cs @@ -91,19 +91,33 @@ public class MovementDecisions .Distinct() .ToList(); + (Province province, Season season) Point(Unit unit) + => (world.Map.GetLocation(unit.LocationId).Province, unit.Season); + // Create a hold strength decision with an associated order for every province with a unit. foreach (UnitOrder order in relevantOrders) { - HoldStrength[order.Unit.Point] = new(order.Unit.Point, order); + HoldStrength[Point(order.Unit)] = new(Point(order.Unit), order); } + bool IsIncoming(UnitOrder me, MoveOrder other) + => me != other + && other.Season == me.Unit.Season + && other.Province == world.Map.GetLocation(me.Unit).Province; + + bool AreOpposing(MoveOrder one, MoveOrder two) + => one.Season == two.Unit.Season + && two.Season == one.Unit.Season + && one.Province == world.Map.GetLocation(two.Unit).Province + && two.Province == world.Map.GetLocation(one.Unit).Province; + // Create all other relevant decisions for each order in the affected timelines. foreach (UnitOrder order in relevantOrders) { // Create a dislodge decision for this unit. List incoming = relevantOrders .OfType() - .Where(order.IsIncoming) + .Where(other => IsIncoming(order, other)) .ToList(); IsDislodged[order.Unit] = new(order, incoming); @@ -118,7 +132,7 @@ public class MovementDecisions // Determine if this move is a head-to-head battle. MoveOrder? opposingMove = relevantOrders .OfType() - .FirstOrDefault(other => other!.IsOpposing(move), null); + .FirstOrDefault(other => AreOpposing(move, other!), null); // Find competing moves. List competing = relevantOrders @@ -142,11 +156,11 @@ public class MovementDecisions GivesSupport[support] = new(support, incoming); // Ensure a hold strength decision exists for the target's province. - HoldStrength.Ensure(support.Target.Point, () => new(support.Target.Point)); + HoldStrength.Ensure(Point(support.Target), () => new(Point(support.Target))); if (support is SupportHoldOrder supportHold) { - HoldStrength[support.Target.Point].Supports.Add(supportHold); + HoldStrength[Point(support.Target)].Supports.Add(supportHold); } else if (support is SupportMoveOrder supportMove) { diff --git a/MultiversalDiplomacy/Model/Unit.cs b/MultiversalDiplomacy/Model/Unit.cs index ec512e2..5d4ceb0 100644 --- a/MultiversalDiplomacy/Model/Unit.cs +++ b/MultiversalDiplomacy/Model/Unit.cs @@ -19,12 +19,6 @@ public class Unit public string LocationId => Location.Designation; - /// - /// The province where the unit is. - /// - [JsonIgnore] - public Province Province => this.Location.Province; - /// /// The season in time when the unit is. /// @@ -40,11 +34,6 @@ public class Unit /// public UnitType Type { get; } - /// - /// The unit's spatiotemporal location as a province-season tuple. - /// - public (Province province, Season season) Point => (this.Province, this.Season); - private Unit(Unit? past, Location location, Season season, Power power, UnitType type) { this.Past = past; @@ -55,9 +44,7 @@ public class Unit } public override string ToString() - { - return $"{this.Power.Name[0]} {this.Type.ToShort()} {(this.Province, this.Season).ToShort()}"; - } + => $"{Power.Name[0]} {Type.ToShort()} {Season.Timeline}-{LocationId}@{Season.Turn}"; /// /// Create a new unit. No validation is performed; the adjudicator should only call this diff --git a/MultiversalDiplomacy/Model/World.cs b/MultiversalDiplomacy/Model/World.cs index b90309e..5421921 100644 --- a/MultiversalDiplomacy/Model/World.cs +++ b/MultiversalDiplomacy/Model/World.cs @@ -1,4 +1,3 @@ -using System.Collections.ObjectModel; using System.Text.Json.Serialization; namespace MultiversalDiplomacy.Model; diff --git a/MultiversalDiplomacy/Orders/MoveOrder.cs b/MultiversalDiplomacy/Orders/MoveOrder.cs index fbad4ea..a60f222 100644 --- a/MultiversalDiplomacy/Orders/MoveOrder.cs +++ b/MultiversalDiplomacy/Orders/MoveOrder.cs @@ -39,15 +39,6 @@ public class MoveOrder : UnitOrder return $"{this.Unit} -> {(this.Province, this.Season).ToShort()}"; } - /// - /// Returns whether another move order is in a head-to-head battle with this order. - /// - public bool IsOpposing(MoveOrder other) - => this.Season == other.Unit.Season - && other.Season == this.Unit.Season - && this.Province == other.Unit.Province - && other.Province == this.Unit.Province; - /// /// Returns whether another move order has the same destination as this order. /// diff --git a/MultiversalDiplomacy/Orders/UnitOrder.cs b/MultiversalDiplomacy/Orders/UnitOrder.cs index a3aceb1..e6d1f6d 100644 --- a/MultiversalDiplomacy/Orders/UnitOrder.cs +++ b/MultiversalDiplomacy/Orders/UnitOrder.cs @@ -16,12 +16,4 @@ public abstract class UnitOrder : Order { this.Unit = unit; } - - /// - /// Returns whether a move order is moving into this order's unit's province. - /// - public bool IsIncoming(MoveOrder other) - => this != other - && other.Season == this.Unit.Season - && other.Province == this.Unit.Province; } \ No newline at end of file diff --git a/MultiversalDiplomacyTests/OrderReference.cs b/MultiversalDiplomacyTests/OrderReference.cs index 89d017b..e28c7c8 100644 --- a/MultiversalDiplomacyTests/OrderReference.cs +++ b/MultiversalDiplomacyTests/OrderReference.cs @@ -108,8 +108,7 @@ public abstract class OrderReference DefendStrength defend => defend.Order == this.Order, PreventStrength prevent => prevent.Order == this.Order, HoldStrength hold => this.Order is UnitOrder unitOrder - ? hold.Province == unitOrder.Unit.Province - : false, + && hold.Province == Builder.World.Map.GetLocation(unitOrder.Unit).Province, _ => false, }).ToList(); return adjudications; diff --git a/MultiversalDiplomacyTests/TestCaseBuilder.cs b/MultiversalDiplomacyTests/TestCaseBuilder.cs index 1fe04fb..1ca5d41 100644 --- a/MultiversalDiplomacyTests/TestCaseBuilder.cs +++ b/MultiversalDiplomacyTests/TestCaseBuilder.cs @@ -262,7 +262,7 @@ public class TestCaseBuilder foreach (Unit unit in this.World.Units) { if (unit.Power == power - && unit.Province == location.Province + && World.Map.GetLocation(unit).Province == location.Province && unit.Season == season) { return unit; diff --git a/MultiversalDiplomacyTests/TestCaseBuilderTest.cs b/MultiversalDiplomacyTests/TestCaseBuilderTest.cs index de2e931..412aabf 100644 --- a/MultiversalDiplomacyTests/TestCaseBuilderTest.cs +++ b/MultiversalDiplomacyTests/TestCaseBuilderTest.cs @@ -68,7 +68,7 @@ class TestCaseBuilderTest List orders = setup.Orders.OfType().ToList(); Func OrderForProvince(string name) - => order => order.Unit.Province.Name == name; + => order => setup.World.Map.GetLocation(order.Unit).Province.Name == name; UnitOrder orderBer = orders.Single(OrderForProvince("Berlin")); Assert.That(orderBer, Is.InstanceOf(), "Unexpected order type");