diff --git a/MultiversalDiplomacy/Adjudicate/Decision/MovementDecisions.cs b/MultiversalDiplomacy/Adjudicate/Decision/MovementDecisions.cs index 14c5cc7..5364ff8 100644 --- a/MultiversalDiplomacy/Adjudicate/Decision/MovementDecisions.cs +++ b/MultiversalDiplomacy/Adjudicate/Decision/MovementDecisions.cs @@ -84,7 +84,7 @@ public class MovementDecisions // Create a dislodge decision for this unit. List incoming = orders .OfType() - .Where(move => move.Location.Province == order.Unit.Location.Province) + .Where(move => move.Province == order.Unit.Province) .ToList(); this.IsDislodged[order.Unit] = new(order, incoming); @@ -110,7 +110,7 @@ public class MovementDecisions .OfType() .Where(other => other != move - && other.Location.Province == move.Location.Province) + && other.Province == move.Province) .ToList(); // Create the move-related decisions. diff --git a/MultiversalDiplomacy/Adjudicate/MovementPhaseAdjudicator.cs b/MultiversalDiplomacy/Adjudicate/MovementPhaseAdjudicator.cs index b982610..fe6905e 100644 --- a/MultiversalDiplomacy/Adjudicate/MovementPhaseAdjudicator.cs +++ b/MultiversalDiplomacy/Adjudicate/MovementPhaseAdjudicator.cs @@ -124,7 +124,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator // Trivial check: cannot convoy to non-coastal province. AdjudicatorHelpers.InvalidateIfNotMatching( order => order.Location.Type == LocationType.Land - && order.Location.Province.Locations.Any(loc => loc.Type == LocationType.Water), + && order.Province.Locations.Any(loc => loc.Type == LocationType.Water), ValidationReason.IllegalDestinationType, ref convoyOrders, ref validationResults); @@ -170,7 +170,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator order => // Map adjacency with respect to province order.Unit.Location.Adjacents.Any( - adjLocation => adjLocation.Province == order.Target.Location.Province) + adjLocation => adjLocation.Province == order.Target.Province) // Turn adjacency && Math.Abs(order.Unit.Season.Turn - order.Target.Season.Turn) <= 1 // Timeline adjacency @@ -189,7 +189,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator // Support-move orders are invalid if the unit supports a move to any location in its own // province. AdjudicatorHelpers.InvalidateIfNotMatching( - order => order.Unit.Location.Province != order.Location.Province, + order => order.Unit.Province != order.Province, ValidationReason.NoSupportMoveAgainstSelf, ref supportMoveOrders, ref validationResults); @@ -202,7 +202,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator order => // Map adjacency with respect to province order.Unit.Location.Adjacents.Any( - adjLocation => adjLocation.Province == order.Location.Province) + adjLocation => adjLocation.Province == order.Province) // Turn adjacency && Math.Abs(order.Unit.Season.Turn - order.Season.Turn) <= 1 // Timeline adjacency diff --git a/MultiversalDiplomacy/Adjudicate/PathFinder.cs b/MultiversalDiplomacy/Adjudicate/PathFinder.cs index c9a8375..c01b391 100644 --- a/MultiversalDiplomacy/Adjudicate/PathFinder.cs +++ b/MultiversalDiplomacy/Adjudicate/PathFinder.cs @@ -36,7 +36,7 @@ public static class PathFinder // Verify that the origin is a coastal province. if (movingUnit.Location.Type != LocationType.Land) return false; - IEnumerable originCoasts = movingUnit.Location.Province.Locations + IEnumerable originCoasts = movingUnit.Province.Locations .Where(location => location.Type == LocationType.Water); if (!originCoasts.Any()) return false; diff --git a/MultiversalDiplomacy/Model/Unit.cs b/MultiversalDiplomacy/Model/Unit.cs index 74bde97..c0ff9be 100644 --- a/MultiversalDiplomacy/Model/Unit.cs +++ b/MultiversalDiplomacy/Model/Unit.cs @@ -15,6 +15,11 @@ public class Unit /// public Location Location { get; } + /// + /// The province where the unit is. + /// + public Province Province => this.Location.Province; + /// /// The season in time when the unit is. /// @@ -33,7 +38,7 @@ public class Unit /// /// The unit's spatiotemporal location as a province-season tuple. /// - public (Province province, Season season) Point => (this.Location.Province, this.Season); + public (Province province, Season season) Point => (this.Province, this.Season); private Unit(Unit? past, Location location, Season season, Power power, UnitType type) { @@ -46,7 +51,7 @@ public class Unit public override string ToString() { - return $"{this.Power} {this.Type} {this.Location.Province} {this.Season}"; + return $"{this.Power} {this.Type} {this.Province} {this.Season}"; } /// diff --git a/MultiversalDiplomacy/Model/World.cs b/MultiversalDiplomacy/Model/World.cs index 602a9c3..68baeed 100644 --- a/MultiversalDiplomacy/Model/World.cs +++ b/MultiversalDiplomacy/Model/World.cs @@ -291,7 +291,7 @@ public class World seasonCoord ??= (this.RootSeason.Turn, this.RootSeason.Timeline); Season season = GetSeason(seasonCoord.Value.turn, seasonCoord.Value.timeline); Unit? foundUnit = this.Units.SingleOrDefault( - u => u != null && u.Location.Province == province && u.Season == season, + u => u != null && u.Province == province && u.Season == season, null); if (foundUnit == null) throw new KeyNotFoundException( $"Unit at {province} at {season} not found"); diff --git a/MultiversalDiplomacy/Orders/ConvoyOrder.cs b/MultiversalDiplomacy/Orders/ConvoyOrder.cs index 665fef6..0bb3484 100644 --- a/MultiversalDiplomacy/Orders/ConvoyOrder.cs +++ b/MultiversalDiplomacy/Orders/ConvoyOrder.cs @@ -22,6 +22,11 @@ public class ConvoyOrder : UnitOrder /// public Location Location { get; } + /// + /// The destination province to which the target is moving. + /// + public Province Province => this.Location.Province; + public ConvoyOrder(Power power, Unit unit, Unit target, Season season, Location location) : base (power, unit) { diff --git a/MultiversalDiplomacy/Orders/MoveOrder.cs b/MultiversalDiplomacy/Orders/MoveOrder.cs index 3aa890b..cb1b6c5 100644 --- a/MultiversalDiplomacy/Orders/MoveOrder.cs +++ b/MultiversalDiplomacy/Orders/MoveOrder.cs @@ -17,10 +17,15 @@ public class MoveOrder : UnitOrder /// public Location Location { get; } + /// + /// The destination province to which the unit should move. + /// + public Province Province => this.Location.Province; + /// /// The destination's spatiotemporal location as a province-season tuple. /// - public (Province province, Season season) Point => (this.Location.Province, this.Season); + public (Province province, Season season) Point => (this.Province, this.Season); public MoveOrder(Power power, Unit unit, Season season, Location location) : base (power, unit) @@ -32,6 +37,6 @@ public class MoveOrder : UnitOrder public bool IsOpposing(MoveOrder other) => this.Season == other.Unit.Season && other.Season == this.Unit.Season - && this.Location.Province == other.Unit.Location.Province - && other.Location.Province == this.Unit.Location.Province; + && this.Province == other.Unit.Province + && other.Province == this.Unit.Province; } diff --git a/MultiversalDiplomacy/Orders/SupportMoveOrder.cs b/MultiversalDiplomacy/Orders/SupportMoveOrder.cs index df72eb8..035ac9e 100644 --- a/MultiversalDiplomacy/Orders/SupportMoveOrder.cs +++ b/MultiversalDiplomacy/Orders/SupportMoveOrder.cs @@ -17,10 +17,15 @@ public class SupportMoveOrder : SupportOrder /// public Location Location { get; } + /// + /// The destination province to which the target is moving. + /// + public Province Province => this.Location.Province; + /// /// The target's destination's spatiotemporal location as a province-season tuple. /// - public (Province province, Season season) Point => (this.Location.Province, this.Season); + public (Province province, Season season) Point => (this.Province, this.Season); public SupportMoveOrder(Power power, Unit unit, Unit target, Season season, Location location) : base(power, unit, target) diff --git a/MultiversalDiplomacyTests/OrderReference.cs b/MultiversalDiplomacyTests/OrderReference.cs index 3bcca25..89d017b 100644 --- a/MultiversalDiplomacyTests/OrderReference.cs +++ b/MultiversalDiplomacyTests/OrderReference.cs @@ -108,7 +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.Location.Province + ? hold.Province == unitOrder.Unit.Province : false, _ => false, }).ToList(); diff --git a/MultiversalDiplomacyTests/TestCaseBuilder.cs b/MultiversalDiplomacyTests/TestCaseBuilder.cs index 8697961..57577eb 100644 --- a/MultiversalDiplomacyTests/TestCaseBuilder.cs +++ b/MultiversalDiplomacyTests/TestCaseBuilder.cs @@ -249,7 +249,7 @@ public class TestCaseBuilder foreach (Unit unit in this.World.Units) { if (unit.Power == power - && unit.Location.Province == location.Province + && unit.Province == location.Province && unit.Season == season) { return unit; diff --git a/MultiversalDiplomacyTests/TestCaseBuilderTest.cs b/MultiversalDiplomacyTests/TestCaseBuilderTest.cs index 41c82dd..0d6fda0 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.Location.Province.Name == name; + => order => order.Unit.Province.Name == name; UnitOrder orderBer = orders.Single(OrderForProvince("Berlin")); Assert.That(orderBer, Is.InstanceOf(), "Unexpected order type");