diff --git a/MultiversalDiplomacy/Model/Unit.cs b/MultiversalDiplomacy/Model/Unit.cs
index e303629..e1bda17 100644
--- a/MultiversalDiplomacy/Model/Unit.cs
+++ b/MultiversalDiplomacy/Model/Unit.cs
@@ -8,7 +8,7 @@ public class Unit
///
/// The previous iteration of a unit. This is null if the unit was just built.
///
- public Unit? Past { get; }
+ public string? Past { get; }
///
/// The location on the map where the unit is.
@@ -30,7 +30,12 @@ public class Unit
///
public UnitType Type { get; }
- private Unit(Unit? past, string location, Season season, Power power, UnitType type)
+ ///
+ /// A unique designation for this unit.
+ ///
+ public string Designation => $"{Type.ToShort()} {Season.Timeline}-{Location}@{Season.Turn}";
+
+ private Unit(string? past, string location, Season season, Power power, UnitType type)
{
this.Past = past;
this.Location = location;
@@ -53,5 +58,5 @@ public class Unit
/// Advance this unit's timeline to a new location and season.
///
public Unit Next(string location, Season season)
- => new(past: this, location, season, this.Power, this.Type);
+ => new(past: this.Designation, location, season, this.Power, this.Type);
}
diff --git a/MultiversalDiplomacy/Model/World.cs b/MultiversalDiplomacy/Model/World.cs
index dc5b802..530086b 100644
--- a/MultiversalDiplomacy/Model/World.cs
+++ b/MultiversalDiplomacy/Model/World.cs
@@ -332,4 +332,8 @@ public class World
?? throw new KeyNotFoundException($"Unit at {province} at {season} not found");
return foundUnit;
}
+
+ public Unit GetUnitByDesignation(string designation)
+ => Units.SingleOrDefault(u => u!.Designation == designation, null)
+ ?? throw new KeyNotFoundException($"Unit {designation} not found");
}
diff --git a/MultiversalDiplomacyTests/MDATC_A.cs b/MultiversalDiplomacyTests/MDATC_A.cs
index 59887e3..3d09311 100644
--- a/MultiversalDiplomacyTests/MDATC_A.cs
+++ b/MultiversalDiplomacyTests/MDATC_A.cs
@@ -46,12 +46,12 @@ 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));
- Assert.That(aTyr.Past?.Past, Is.EqualTo(mun0.Order.Unit));
+ Assert.That(aTyr.Past, Is.EqualTo(mun1.Order.Unit.Designation));
+ Assert.That(world.GetUnitByDesignation(aTyr.Past!).Past, Is.EqualTo(mun0.Order.Unit.Designation));
// 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));
+ Assert.That(aMun1.Past, Is.EqualTo(originalUnit.Designation));
}
[Test]
@@ -95,7 +95,7 @@ public class TimeTravelTest
Unit tyr1 = world.GetUnitAt("Tyr", fork);
Assert.That(
tyr1.Past,
- Is.EqualTo(mun0.Order.Unit),
+ Is.EqualTo(mun0.Order.Unit.Designation),
"Expected A Mun a0 to advance to Tyr b1");
Assert.That(
world.RetreatingUnits.Count,
diff --git a/MultiversalDiplomacyTests/MovementAdjudicatorTest.cs b/MultiversalDiplomacyTests/MovementAdjudicatorTest.cs
index 100e624..0874058 100644
--- a/MultiversalDiplomacyTests/MovementAdjudicatorTest.cs
+++ b/MultiversalDiplomacyTests/MovementAdjudicatorTest.cs
@@ -209,7 +209,7 @@ public class MovementAdjudicatorTest
Unit u2 = updated.GetUnitAt("Mun", s2);
Assert.That(updated.Units.Count, Is.EqualTo(2));
Assert.That(u2, Is.Not.EqualTo(mun1.Order.Unit));
- Assert.That(u2.Past, Is.EqualTo(mun1.Order.Unit));
+ Assert.That(u2.Past, Is.EqualTo(mun1.Order.Unit.Designation));
Assert.That(u2.Season, Is.EqualTo(s2));
setup[("a", 1)]
@@ -229,7 +229,7 @@ public class MovementAdjudicatorTest
updated = setup.UpdateWorld();
Season s3 = updated.GetSeason(s2.Timeline, s2.Turn + 1);
Unit u3 = updated.GetUnitAt("Mun", s3);
- Assert.That(u3.Past, Is.EqualTo(mun2.Order.Unit));
+ Assert.That(u3.Past, Is.EqualTo(mun2.Order.Unit.Designation));
}
[Test]
@@ -259,7 +259,7 @@ public class MovementAdjudicatorTest
Unit u2 = updated.GetUnitAt("Tyr", s2);
Assert.That(updated.Units.Count, Is.EqualTo(2));
Assert.That(u2, Is.Not.EqualTo(mun1.Order.Unit));
- Assert.That(u2.Past, Is.EqualTo(mun1.Order.Unit));
+ Assert.That(u2.Past, Is.EqualTo(mun1.Order.Unit.Designation));
Assert.That(u2.Season, Is.EqualTo(s2));
setup[("a", 1)]
@@ -279,6 +279,6 @@ public class MovementAdjudicatorTest
updated = setup.UpdateWorld();
Season s3 = updated.GetSeason(s2.Timeline, s2.Turn + 1);
Unit u3 = updated.GetUnitAt("Mun", s3);
- Assert.That(u3.Past, Is.EqualTo(u2));
+ Assert.That(u3.Past, Is.EqualTo(u2.Designation));
}
}
diff --git a/MultiversalDiplomacyTests/SerializationTest.cs b/MultiversalDiplomacyTests/SerializationTest.cs
index 44be89c..73c5fdf 100644
--- a/MultiversalDiplomacyTests/SerializationTest.cs
+++ b/MultiversalDiplomacyTests/SerializationTest.cs
@@ -94,7 +94,7 @@ public class SerializationTest
Unit tyr1 = world.GetUnitAt("Tyr", fork);
Assert.That(
tyr1.Past,
- Is.EqualTo(mun0.Order.Unit),
+ Is.EqualTo(mun0.Order.Unit.Designation),
"Expected A Mun a0 to advance to Tyr b1");
Assert.That(
world.RetreatingUnits.Count,
diff --git a/MultiversalDiplomacyTests/UnitTests.cs b/MultiversalDiplomacyTests/UnitTests.cs
index 97611d0..3090fba 100644
--- a/MultiversalDiplomacyTests/UnitTests.cs
+++ b/MultiversalDiplomacyTests/UnitTests.cs
@@ -23,8 +23,8 @@ public class UnitTests
_ = world.ContinueOrFork(a1, out Season a2);
Unit u3 = u2.Next(Tyr.Designation, a2);
- Assert.That(u3.Past, Is.EqualTo(u2), "Missing unit past");
- Assert.That(u2.Past, Is.EqualTo(u1), "Missing unit past");
+ Assert.That(u3.Past, Is.EqualTo(u2.Designation), "Missing unit past");
+ Assert.That(u2.Past, Is.EqualTo(u1.Designation), "Missing unit past");
Assert.That(u1.Past, Is.Null, "Unexpected unit past");
Assert.That(u1.Season, Is.EqualTo(a0), "Unexpected unit season");