From 1eeb5115e6bb728eb6d2e7a53760f3d4694066b1 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Mon, 9 Sep 2024 19:40:22 -0700 Subject: [PATCH] Remove Unit.Past Past is only used in tests. It was added speculatively in expectation that it would be useful for clients. Removing this means that all the fields of a Unit are present in the key, so the key can uniquely determine the Unit or even be parsed into one, and therefore multiple Unit instances can be equivalent if their fields match. If unit pasts are useful later, they can be tracked extrinsically the way timelines are tracked. --- MultiversalDiplomacy/Model/Unit.cs | 12 +++--------- MultiversalDiplomacyTests/MDATC_A.cs | 7 ------- MultiversalDiplomacyTests/MovementAdjudicatorTest.cs | 6 +----- MultiversalDiplomacyTests/SerializationTest.cs | 4 ---- MultiversalDiplomacyTests/UnitTests.cs | 4 ---- 5 files changed, 4 insertions(+), 29 deletions(-) diff --git a/MultiversalDiplomacy/Model/Unit.cs b/MultiversalDiplomacy/Model/Unit.cs index 305d39f..a9cba9f 100644 --- a/MultiversalDiplomacy/Model/Unit.cs +++ b/MultiversalDiplomacy/Model/Unit.cs @@ -7,11 +7,6 @@ namespace MultiversalDiplomacy.Model; /// public class Unit { - /// - /// The previous iteration of a unit. This is null if the unit was just built. - /// - public string? Past { get; } - /// /// The location on the map where the unit is. /// @@ -38,9 +33,8 @@ public class Unit [JsonIgnore] public string Key => $"{Type.ToShort()} {Season.Timeline}-{Location}@{Season.Turn}"; - public Unit(string? past, string location, Season season, string power, UnitType type) + public Unit(string location, Season season, string power, UnitType type) { - this.Past = past; this.Location = location; this.Season = season; this.Power = power; @@ -55,13 +49,13 @@ public class Unit /// method after accepting a build order. /// public static Unit Build(string location, Season season, string power, UnitType type) - => new(past: null, location, season, power, type); + => new(location, season, power, type); /// /// Advance this unit's timeline to a new location and season. /// public Unit Next(string location, Season season) - => new(past: this.Key, location, season, this.Power, this.Type); + => new(location, season, this.Power, this.Type); public Location GetLocation(World world) => world.Map.GetLocation(Location); diff --git a/MultiversalDiplomacyTests/MDATC_A.cs b/MultiversalDiplomacyTests/MDATC_A.cs index b3de1c8..fcb41cb 100644 --- a/MultiversalDiplomacyTests/MDATC_A.cs +++ b/MultiversalDiplomacyTests/MDATC_A.cs @@ -47,12 +47,9 @@ public class TimeTravelTest Unit originalUnit = world.GetUnitAt("Mun", s0); Unit aMun0 = world.GetUnitAt("Mun", s1); Unit aTyr = world.GetUnitAt("Tyr", fork); - Assert.That(aTyr.Past, Is.EqualTo(mun1.Order.Unit.Key)); - Assert.That(world.GetUnitByKey(aTyr.Past!).Past, Is.EqualTo(mun0.Order.Unit.Key)); // Confirm that there is a unit in Mun b1 originating from Mun a0 Unit aMun1 = world.GetUnitAt("Mun", fork); - Assert.That(aMun1.Past, Is.EqualTo(originalUnit.Key)); } [Test] @@ -94,10 +91,6 @@ public class TimeTravelTest World world = setup.UpdateWorld(); Season fork = new("b1"); Unit tyr1 = world.GetUnitAt("Tyr", fork); - Assert.That( - tyr1.Past, - Is.EqualTo(mun0.Order.Unit.Key), - "Expected A Mun a0 to advance to Tyr b1"); Assert.That( world.RetreatingUnits.Count, Is.EqualTo(1), diff --git a/MultiversalDiplomacyTests/MovementAdjudicatorTest.cs b/MultiversalDiplomacyTests/MovementAdjudicatorTest.cs index 8b2be91..50e51e9 100644 --- a/MultiversalDiplomacyTests/MovementAdjudicatorTest.cs +++ b/MultiversalDiplomacyTests/MovementAdjudicatorTest.cs @@ -171,7 +171,7 @@ public class MovementAdjudicatorTest // Confirm the unit was created Assert.That(updated.Units.Count, Is.EqualTo(2)); - Unit second = updated.Units.Single(u => u.Past != null); + Unit second = updated.Units.OrderBy(u => -u.Season.Turn).First(); Assert.That(second.Location, Is.EqualTo(mun.Order.Unit.Location)); Assert.That(second.Season.Timeline, Is.EqualTo(mun.Order.Unit.Season.Timeline)); @@ -208,7 +208,6 @@ public class MovementAdjudicatorTest Unit u2 = updated.GetUnitAt("Mun", s2); Assert.That(updated.Units.Count, Is.EqualTo(2)); Assert.That(u2.Key, Is.Not.EqualTo(mun1.Order.Unit.Key)); - Assert.That(u2.Past, Is.EqualTo(mun1.Order.Unit.Key)); Assert.That(u2.Season, Is.EqualTo(s2)); setup[("a", 1)] @@ -228,7 +227,6 @@ public class MovementAdjudicatorTest updated = setup.UpdateWorld(); Season s3 = new(s2.Timeline, s2.Turn + 1); Unit u3 = updated.GetUnitAt("Mun", s3); - Assert.That(u3.Past, Is.EqualTo(mun2.Order.Unit.Key)); } [Test] @@ -258,7 +256,6 @@ public class MovementAdjudicatorTest Unit u2 = updated.GetUnitAt("Tyr", s2); Assert.That(updated.Units.Count, Is.EqualTo(2)); Assert.That(u2.Key, Is.Not.EqualTo(mun1.Order.Unit.Key)); - Assert.That(u2.Past, Is.EqualTo(mun1.Order.Unit.Key)); Assert.That(u2.Season, Is.EqualTo(s2)); setup[("a", 1)] @@ -278,6 +275,5 @@ public class MovementAdjudicatorTest updated = setup.UpdateWorld(); Season s3 = new(s2.Timeline, s2.Turn + 1); Unit u3 = updated.GetUnitAt("Mun", s3); - Assert.That(u3.Past, Is.EqualTo(u2.Key)); } } diff --git a/MultiversalDiplomacyTests/SerializationTest.cs b/MultiversalDiplomacyTests/SerializationTest.cs index 91ca56e..34a37d2 100644 --- a/MultiversalDiplomacyTests/SerializationTest.cs +++ b/MultiversalDiplomacyTests/SerializationTest.cs @@ -133,10 +133,6 @@ public class SerializationTest World world = setup.UpdateWorld(); Season fork = new("b1"); Unit tyr1 = world.GetUnitAt("Tyr", fork); - Assert.That( - tyr1.Past, - Is.EqualTo(mun0.Order.Unit.Key), - "Expected A Mun a0 to advance to Tyr b1"); Assert.That( world.RetreatingUnits.Count, Is.EqualTo(1), diff --git a/MultiversalDiplomacyTests/UnitTests.cs b/MultiversalDiplomacyTests/UnitTests.cs index f10dac6..5293be4 100644 --- a/MultiversalDiplomacyTests/UnitTests.cs +++ b/MultiversalDiplomacyTests/UnitTests.cs @@ -22,10 +22,6 @@ public class UnitTests _ = world.WithNewSeason(a1, out Season a2); Unit u3 = u2.Next(Tyr.Key, a2); - Assert.That(u3.Past, Is.EqualTo(u2.Key), "Missing unit past"); - Assert.That(u2.Past, Is.EqualTo(u1.Key), "Missing unit past"); - Assert.That(u1.Past, Is.Null, "Unexpected unit past"); - Assert.That(u1.Season, Is.EqualTo(a0), "Unexpected unit season"); Assert.That(u2.Season, Is.EqualTo(a1), "Unexpected unit season"); Assert.That(u3.Season, Is.EqualTo(a2), "Unexpected unit season");