Compare commits

...

2 Commits

Author SHA1 Message Date
Tim Van Baak 1eeb5115e6 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.
2024-09-09 19:40:22 -07:00
Tim Van Baak 4ce5faaac2 Replace Map lookup methods with Unit methods
This makes the flow of data easier to read and is slightly shorter in some cases. This pattern will be better for replacing more reference members with keys.
2024-09-09 12:11:44 -07:00
15 changed files with 36 additions and 60 deletions

View File

@ -94,7 +94,7 @@ public class MovementDecisions
.ToList(); .ToList();
(string province, string season) UnitPoint(Unit unit) (string province, string season) UnitPoint(Unit unit)
=> (world.Map.GetLocation(unit.Location).Province.Name, unit.Season.Key); => (unit.GetProvince(world).Name, unit.Season.Key);
(string province, string season) MovePoint(MoveOrder move) (string province, string season) MovePoint(MoveOrder move)
=> (SplitKey(move.Location).province, move.Season.Key); => (SplitKey(move.Location).province, move.Season.Key);
@ -102,7 +102,7 @@ public class MovementDecisions
foreach (UnitOrder order in relevantOrders) foreach (UnitOrder order in relevantOrders)
{ {
HoldStrength[UnitPoint(order.Unit)] = new( HoldStrength[UnitPoint(order.Unit)] = new(
world.Map.GetLocation(order.Unit.Location).Province, order.Unit.GetProvince(world),
order.Unit.Season, order.Unit.Season,
order); order);
} }
@ -110,7 +110,7 @@ public class MovementDecisions
bool IsIncoming(UnitOrder me, MoveOrder other) bool IsIncoming(UnitOrder me, MoveOrder other)
=> me != other => me != other
&& other.Season == me.Unit.Season && other.Season == me.Unit.Season
&& SplitKey(other.Location).province == world.Map.GetLocation(me.Unit).Province.Name; && SplitKey(other.Location).province == me.Unit.GetProvince(world).Name;
bool IsSupportFor(SupportMoveOrder me, MoveOrder move) bool IsSupportFor(SupportMoveOrder me, MoveOrder move)
=> me.Target.Key == move.Unit.Key => me.Target.Key == move.Unit.Key
@ -120,8 +120,8 @@ public class MovementDecisions
bool AreOpposing(MoveOrder one, MoveOrder two) bool AreOpposing(MoveOrder one, MoveOrder two)
=> one.Season == two.Unit.Season => one.Season == two.Unit.Season
&& two.Season == one.Unit.Season && two.Season == one.Unit.Season
&& SplitKey(one.Location).province == world.Map.GetLocation(two.Unit).Province.Name && SplitKey(one.Location).province == two.Unit.GetProvince(world).Name
&& SplitKey(two.Location).province == world.Map.GetLocation(one.Unit).Province.Name; && SplitKey(two.Location).province == one.Unit.GetProvince(world).Name;
bool AreCompeting(MoveOrder one, MoveOrder two) bool AreCompeting(MoveOrder one, MoveOrder two)
=> one != two => one != two
@ -174,7 +174,7 @@ public class MovementDecisions
// Ensure a hold strength decision exists for the target's province. // Ensure a hold strength decision exists for the target's province.
HoldStrength.Ensure(UnitPoint(support.Target), () => new( HoldStrength.Ensure(UnitPoint(support.Target), () => new(
world.Map.GetLocation(support.Target.Location).Province, support.Target.GetProvince(world),
support.Target.Season)); support.Target.Season));
if (support is SupportHoldOrder supportHold) if (support is SupportHoldOrder supportHold)

View File

@ -92,7 +92,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
ILookup<bool, MoveOrder> moveOrdersByAdjacency = moveOrders ILookup<bool, MoveOrder> moveOrdersByAdjacency = moveOrders
.ToLookup(order => .ToLookup(order =>
// Map adjacency // Map adjacency
world.Map.GetLocation(order.Unit).Adjacents.Select(loc => loc.Key).Contains(order.Location) order.Unit.GetLocation(world).Adjacents.Select(loc => loc.Key).Contains(order.Location)
// Turn adjacency // Turn adjacency
&& Math.Abs(order.Unit.Season.Turn - order.Season.Turn) <= 1 && Math.Abs(order.Unit.Season.Turn - order.Season.Turn) <= 1
// Timeline adjacency // Timeline adjacency
@ -177,8 +177,8 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
AdjudicatorHelpers.InvalidateIfNotMatching( AdjudicatorHelpers.InvalidateIfNotMatching(
order => order =>
// Map adjacency with respect to province // Map adjacency with respect to province
world.Map.GetLocation(order.Unit).Adjacents.Any( order.Unit.GetLocation(world).Adjacents.Any(
adjLocation => adjLocation.Province == world.Map.GetLocation(order.Target).Province) adjLocation => adjLocation.Province == order.Target.GetLocation(world).Province)
// Turn adjacency // Turn adjacency
&& Math.Abs(order.Unit.Season.Turn - order.Target.Season.Turn) <= 1 && Math.Abs(order.Unit.Season.Turn - order.Target.Season.Turn) <= 1
// Timeline adjacency // Timeline adjacency
@ -197,7 +197,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
// Support-move orders are invalid if the unit supports a move to any location in its own // Support-move orders are invalid if the unit supports a move to any location in its own
// province. // province.
AdjudicatorHelpers.InvalidateIfNotMatching( AdjudicatorHelpers.InvalidateIfNotMatching(
order => world.Map.GetLocation(order.Unit).Province != order.Province, order => order.Unit.GetProvince(world) != order.Province,
ValidationReason.NoSupportMoveAgainstSelf, ValidationReason.NoSupportMoveAgainstSelf,
ref supportMoveOrders, ref supportMoveOrders,
ref validationResults); ref validationResults);
@ -209,7 +209,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
AdjudicatorHelpers.InvalidateIfNotMatching( AdjudicatorHelpers.InvalidateIfNotMatching(
order => order =>
// Map adjacency with respect to province // Map adjacency with respect to province
world.Map.GetLocation(order.Unit).Adjacents.Any( order.Unit.GetLocation(world).Adjacents.Any(
adjLocation => adjLocation.Province == order.Province) adjLocation => adjLocation.Province == order.Province)
// Turn adjacency // Turn adjacency
&& Math.Abs(order.Unit.Season.Turn - order.Season.Turn) <= 1 && Math.Abs(order.Unit.Season.Turn - order.Season.Turn) <= 1
@ -370,7 +370,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
if (isDislodged.Outcome == false) if (isDislodged.Outcome == false)
{ {
// Non-dislodged units continue into the future. // Non-dislodged units continue into the future.
Unit next = order.Unit.Next(world.Map.GetLocation(order.Unit).Key, future); Unit next = order.Unit.Next(order.Unit.GetLocation(world).Key, future);
logger.Log(3, "Advancing unit to {0}", next); logger.Log(3, "Advancing unit to {0}", next);
createdUnits.Add(next); createdUnits.Add(next);
} }
@ -379,7 +379,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
// Create a retreat for each dislodged unit. // Create a retreat for each dislodged unit.
// TODO check valid retreats and disbands // TODO check valid retreats and disbands
logger.Log(3, "Creating retreat for {0}", order.Unit); logger.Log(3, "Creating retreat for {0}", order.Unit);
var validRetreats = world.Map.GetLocation(order.Unit).Adjacents var validRetreats = order.Unit.GetLocation(world).Adjacents
.Select(loc => (future, loc)) .Select(loc => (future, loc))
.ToList(); .ToList();
RetreatingUnit retreat = new(order.Unit, validRetreats); RetreatingUnit retreat = new(order.Unit, validRetreats);
@ -640,7 +640,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
// If the origin and destination are adjacent, then there is a path. // If the origin and destination are adjacent, then there is a path.
if (// Map adjacency if (// Map adjacency
world.Map.GetLocation(decision.Order.Unit).Adjacents.Select(loc => loc.Key).Contains(decision.Order.Location) decision.Order.Unit.GetLocation(world).Adjacents.Select(loc => loc.Key).Contains(decision.Order.Location)
// Turn adjacency // Turn adjacency
&& Math.Abs(decision.Order.Unit.Season.Turn - decision.Order.Season.Turn) <= 1 && Math.Abs(decision.Order.Unit.Season.Turn - decision.Order.Season.Turn) <= 1
// Timeline adjacency // Timeline adjacency

View File

@ -12,7 +12,7 @@ public static class PathFinder
/// Determines if a convoy path exists for a move in a convoy order. /// Determines if a convoy path exists for a move in a convoy order.
/// </summary> /// </summary>
public static bool ConvoyPathExists(World world, ConvoyOrder order) public static bool ConvoyPathExists(World world, ConvoyOrder order)
=> ConvoyPathExists(world, world.Map.GetLocation(order.Target), order.Location, order.Season); => ConvoyPathExists(world, order.Target.GetLocation(world), order.Location, order.Season);
/// <summary> /// <summary>
/// Determines if a convoy path exists for a move order. /// Determines if a convoy path exists for a move order.
@ -20,7 +20,7 @@ public static class PathFinder
public static bool ConvoyPathExists(World world, MoveOrder order) public static bool ConvoyPathExists(World world, MoveOrder order)
=> ConvoyPathExists( => ConvoyPathExists(
world, world,
world.Map.GetLocation(order.Unit), order.Unit.GetLocation(world),
world.Map.GetLocation(order.Location), world.Map.GetLocation(order.Location),
order.Season); order.Season);

View File

@ -72,9 +72,6 @@ public class Map
public Location GetLocation(string designation) public Location GetLocation(string designation)
=> LocationLookup[designation]; => LocationLookup[designation];
public Location GetLocation(Unit unit)
=> GetLocation(unit.Location);
/// <summary> /// <summary>
/// Get the sole land location of a province. /// Get the sole land location of a province.
/// </summary> /// </summary>

View File

@ -259,7 +259,7 @@ public class OrderParser(World world)
// and the location is ignored. This also satisfies DATC 4.B.5, which requires that a wrong coast for the // and the location is ignored. This also satisfies DATC 4.B.5, which requires that a wrong coast for the
// subject be ignored. // subject be ignored.
subject = world.Units.FirstOrDefault(unit subject = world.Units.FirstOrDefault(unit
=> world.Map.GetLocation(unit!.Location).ProvinceName == province.Name => unit!.GetProvince(world).Name == province.Name
&& unit!.Season.Timeline == timeline && unit!.Season.Timeline == timeline
&& unit!.Season.Turn == turn, && unit!.Season.Turn == turn,
null); null);
@ -338,7 +338,7 @@ public class OrderParser(World world)
// If the order location didn't disambiguate the coasts, either because it's missing or it's nonsense, the // If the order location didn't disambiguate the coasts, either because it's missing or it's nonsense, the
// order can be disambiguated by there being one accessible coast from the order source. // order can be disambiguated by there being one accessible coast from the order source.
if (destLocationKey is null) { if (destLocationKey is null) {
Location source = world.Map.GetLocation(subject.Location); Location source = subject.GetLocation(world);
var accessibleLocations = destProvince.Locations.Where(loc => loc.Adjacents.Contains(source)); var accessibleLocations = destProvince.Locations.Where(loc => loc.Adjacents.Contains(source));
if (accessibleLocations.Count() == 1) destLocationKey ??= accessibleLocations.Single().Key; if (accessibleLocations.Count() == 1) destLocationKey ??= accessibleLocations.Single().Key;
} }
@ -434,7 +434,7 @@ public class OrderParser(World world)
// If the order location didn't disambiguate the coasts, either because it's missing or it's nonsense, the // If the order location didn't disambiguate the coasts, either because it's missing or it's nonsense, the
// order can be disambiguated by there being one accessible coast from the order source. // order can be disambiguated by there being one accessible coast from the order source.
if (destLocationKey is null) { if (destLocationKey is null) {
Location source = world.Map.GetLocation(target.Location); Location source = target.GetLocation(world);
var accessibleLocations = destProvince.Locations.Where(loc => loc.Adjacents.Contains(source)); var accessibleLocations = destProvince.Locations.Where(loc => loc.Adjacents.Contains(source));
if (accessibleLocations.Count() == 1) destLocationKey ??= accessibleLocations.Single().Key; if (accessibleLocations.Count() == 1) destLocationKey ??= accessibleLocations.Single().Key;
} }

View File

@ -7,11 +7,6 @@ namespace MultiversalDiplomacy.Model;
/// </summary> /// </summary>
public class Unit public class Unit
{ {
/// <summary>
/// The previous iteration of a unit. This is null if the unit was just built.
/// </summary>
public string? Past { get; }
/// <summary> /// <summary>
/// The location on the map where the unit is. /// The location on the map where the unit is.
/// </summary> /// </summary>
@ -38,9 +33,8 @@ public class Unit
[JsonIgnore] [JsonIgnore]
public string Key => $"{Type.ToShort()} {Season.Timeline}-{Location}@{Season.Turn}"; 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.Location = location;
this.Season = season; this.Season = season;
this.Power = power; this.Power = power;
@ -55,11 +49,15 @@ public class Unit
/// method after accepting a build order. /// method after accepting a build order.
/// </summary> /// </summary>
public static Unit Build(string location, Season season, string power, UnitType type) public static Unit Build(string location, Season season, string power, UnitType type)
=> new(past: null, location, season, power, type); => new(location, season, power, type);
/// <summary> /// <summary>
/// Advance this unit's timeline to a new location and season. /// Advance this unit's timeline to a new location and season.
/// </summary> /// </summary>
public Unit Next(string location, Season 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);
public Province GetProvince(World world) => GetLocation(world).Province;
} }

View File

@ -231,7 +231,7 @@ public class World
Province province = Map.GetProvince(provinceName); Province province = Map.GetProvince(provinceName);
season ??= Season.First; season ??= Season.First;
Unit? foundUnit = this.Units.SingleOrDefault( Unit? foundUnit = this.Units.SingleOrDefault(
u => Map.GetLocation(u!).Province == province && u!.Season == season, u => u!.GetProvince(this) == province && u!.Season == season,
null) null)
?? throw new KeyNotFoundException($"Unit at {province} at {season} not found"); ?? throw new KeyNotFoundException($"Unit at {province} at {season} not found");
return foundUnit; return foundUnit;

View File

@ -100,7 +100,7 @@ public class AdjudicationQueryScriptHandler(
=> val.Valid => val.Valid
&& val.Order is HoldOrder hold && val.Order is HoldOrder hold
&& hold.Unit.Season == season && hold.Unit.Season == season
&& World.Map.GetLocation(hold.Unit.Location).ProvinceName == province.Name); && hold.Unit.GetProvince(World).Name == province.Name);
if (!matchingHolds.Any()) return ScriptResult.Fail("No matching holds"); if (!matchingHolds.Any()) return ScriptResult.Fail("No matching holds");
return ScriptResult.Succeed(this); return ScriptResult.Succeed(this);
@ -129,7 +129,7 @@ public class AdjudicationQueryScriptHandler(
var matching = Validations.Where(val var matching = Validations.Where(val
=> val.Order is UnitOrder order => val.Order is UnitOrder order
&& order.Unit.Season == season && order.Unit.Season == season
&& World.Map.GetLocation(order.Unit.Location).ProvinceName == province.Name); && order.Unit.GetProvince(World).Name == province.Name);
if (!matching.Any()) return ScriptResult.Fail("No matching validations"); if (!matching.Any()) return ScriptResult.Fail("No matching validations");
if (args[0] == "order-valid" && !matching.First().Valid) { if (args[0] == "order-valid" && !matching.First().Valid) {
@ -181,7 +181,7 @@ public class AdjudicationQueryScriptHandler(
var matchingDislodges = Adjudications.Where(adj var matchingDislodges = Adjudications.Where(adj
=> adj is IsDislodged dislodge => adj is IsDislodged dislodge
&& dislodge.Order.Unit.Season == season && dislodge.Order.Unit.Season == season
&& World.Map.GetLocation(dislodge.Order.Unit.Location).ProvinceName == province.Name); && dislodge.Order.Unit.GetProvince(World).Name == province.Name);
if (!matchingDislodges.Any()) return ScriptResult.Fail("No matching dislodge decisions"); if (!matchingDislodges.Any()) return ScriptResult.Fail("No matching dislodge decisions");
var isDislodged = matchingDislodges.Cast<IsDislodged>().First(); var isDislodged = matchingDislodges.Cast<IsDislodged>().First();
@ -219,7 +219,7 @@ public class AdjudicationQueryScriptHandler(
var matchingMoves = Adjudications.Where(adj var matchingMoves = Adjudications.Where(adj
=> adj is DoesMove moves => adj is DoesMove moves
&& moves.Order.Unit.Season == season && moves.Order.Unit.Season == season
&& World.Map.GetLocation(moves.Order.Unit.Location).ProvinceName == province.Name); && moves.Order.Unit.GetProvince(World).Name == province.Name);
if (!matchingMoves.Any()) return ScriptResult.Fail("No matching movement decisions"); if (!matchingMoves.Any()) return ScriptResult.Fail("No matching movement decisions");
var doesMove = matchingMoves.Cast<DoesMove>().First(); var doesMove = matchingMoves.Cast<DoesMove>().First();
@ -257,7 +257,7 @@ public class AdjudicationQueryScriptHandler(
var matchingSupports = Adjudications.Where(adj var matchingSupports = Adjudications.Where(adj
=> adj is GivesSupport sup => adj is GivesSupport sup
&& sup.Order.Unit.Season == season && sup.Order.Unit.Season == season
&& World.Map.GetLocation(sup.Order.Unit.Location).ProvinceName == province.Name); && sup.Order.Unit.GetProvince(World).Name == province.Name);
if (!matchingSupports.Any()) return ScriptResult.Fail("No matching support decisions"); if (!matchingSupports.Any()) return ScriptResult.Fail("No matching support decisions");
var supports = matchingSupports.Cast<GivesSupport>().First(); var supports = matchingSupports.Cast<GivesSupport>().First();

View File

@ -47,12 +47,9 @@ public class TimeTravelTest
Unit originalUnit = world.GetUnitAt("Mun", s0); Unit originalUnit = world.GetUnitAt("Mun", s0);
Unit aMun0 = world.GetUnitAt("Mun", s1); Unit aMun0 = world.GetUnitAt("Mun", s1);
Unit aTyr = world.GetUnitAt("Tyr", fork); 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 // Confirm that there is a unit in Mun b1 originating from Mun a0
Unit aMun1 = world.GetUnitAt("Mun", fork); Unit aMun1 = world.GetUnitAt("Mun", fork);
Assert.That(aMun1.Past, Is.EqualTo(originalUnit.Key));
} }
[Test] [Test]
@ -94,10 +91,6 @@ public class TimeTravelTest
World world = setup.UpdateWorld(); World world = setup.UpdateWorld();
Season fork = new("b1"); Season fork = new("b1");
Unit tyr1 = world.GetUnitAt("Tyr", fork); 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( Assert.That(
world.RetreatingUnits.Count, world.RetreatingUnits.Count,
Is.EqualTo(1), Is.EqualTo(1),

View File

@ -171,7 +171,7 @@ public class MovementAdjudicatorTest
// Confirm the unit was created // Confirm the unit was created
Assert.That(updated.Units.Count, Is.EqualTo(2)); 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.Location, Is.EqualTo(mun.Order.Unit.Location));
Assert.That(second.Season.Timeline, Is.EqualTo(mun.Order.Unit.Season.Timeline)); 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); Unit u2 = updated.GetUnitAt("Mun", s2);
Assert.That(updated.Units.Count, Is.EqualTo(2)); Assert.That(updated.Units.Count, Is.EqualTo(2));
Assert.That(u2.Key, Is.Not.EqualTo(mun1.Order.Unit.Key)); 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)); Assert.That(u2.Season, Is.EqualTo(s2));
setup[("a", 1)] setup[("a", 1)]
@ -228,7 +227,6 @@ public class MovementAdjudicatorTest
updated = setup.UpdateWorld(); updated = setup.UpdateWorld();
Season s3 = new(s2.Timeline, s2.Turn + 1); Season s3 = new(s2.Timeline, s2.Turn + 1);
Unit u3 = updated.GetUnitAt("Mun", s3); Unit u3 = updated.GetUnitAt("Mun", s3);
Assert.That(u3.Past, Is.EqualTo(mun2.Order.Unit.Key));
} }
[Test] [Test]
@ -258,7 +256,6 @@ public class MovementAdjudicatorTest
Unit u2 = updated.GetUnitAt("Tyr", s2); Unit u2 = updated.GetUnitAt("Tyr", s2);
Assert.That(updated.Units.Count, Is.EqualTo(2)); Assert.That(updated.Units.Count, Is.EqualTo(2));
Assert.That(u2.Key, Is.Not.EqualTo(mun1.Order.Unit.Key)); 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)); Assert.That(u2.Season, Is.EqualTo(s2));
setup[("a", 1)] setup[("a", 1)]
@ -278,6 +275,5 @@ public class MovementAdjudicatorTest
updated = setup.UpdateWorld(); updated = setup.UpdateWorld();
Season s3 = new(s2.Timeline, s2.Turn + 1); Season s3 = new(s2.Timeline, s2.Turn + 1);
Unit u3 = updated.GetUnitAt("Mun", s3); Unit u3 = updated.GetUnitAt("Mun", s3);
Assert.That(u3.Past, Is.EqualTo(u2.Key));
} }
} }

View File

@ -108,7 +108,7 @@ public abstract class OrderReference
DefendStrength defend => defend.Order == this.Order, DefendStrength defend => defend.Order == this.Order,
PreventStrength prevent => prevent.Order == this.Order, PreventStrength prevent => prevent.Order == this.Order,
HoldStrength hold => this.Order is UnitOrder unitOrder HoldStrength hold => this.Order is UnitOrder unitOrder
&& hold.Province == Builder.World.Map.GetLocation(unitOrder.Unit).Province, && hold.Province == unitOrder.Unit.GetProvince(Builder.World),
_ => false, _ => false,
}).ToList(); }).ToList();
return adjudications; return adjudications;

View File

@ -133,10 +133,6 @@ public class SerializationTest
World world = setup.UpdateWorld(); World world = setup.UpdateWorld();
Season fork = new("b1"); Season fork = new("b1");
Unit tyr1 = world.GetUnitAt("Tyr", fork); 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( Assert.That(
world.RetreatingUnits.Count, world.RetreatingUnits.Count,
Is.EqualTo(1), Is.EqualTo(1),

View File

@ -263,7 +263,7 @@ public class TestCaseBuilder
foreach (Unit unit in this.World.Units) foreach (Unit unit in this.World.Units)
{ {
if (unit.Power == power if (unit.Power == power
&& World.Map.GetLocation(unit).Province == location.Province && unit.GetProvince(World) == location.Province
&& unit.Season == season) && unit.Season == season)
{ {
return unit; return unit;

View File

@ -68,7 +68,7 @@ class TestCaseBuilderTest
List<UnitOrder> orders = setup.Orders.OfType<UnitOrder>().ToList(); List<UnitOrder> orders = setup.Orders.OfType<UnitOrder>().ToList();
Func<UnitOrder, bool> OrderForProvince(string name) Func<UnitOrder, bool> OrderForProvince(string name)
=> order => setup.World.Map.GetLocation(order.Unit).Province.Name == name; => order => order.Unit.GetProvince(setup.World).Name == name;
UnitOrder orderBer = orders.Single(OrderForProvince("Berlin")); UnitOrder orderBer = orders.Single(OrderForProvince("Berlin"));
Assert.That(orderBer, Is.InstanceOf<MoveOrder>(), "Unexpected order type"); Assert.That(orderBer, Is.InstanceOf<MoveOrder>(), "Unexpected order type");

View File

@ -22,10 +22,6 @@ public class UnitTests
_ = world.WithNewSeason(a1, out Season a2); _ = world.WithNewSeason(a1, out Season a2);
Unit u3 = u2.Next(Tyr.Key, 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(u1.Season, Is.EqualTo(a0), "Unexpected unit season");
Assert.That(u2.Season, Is.EqualTo(a1), "Unexpected unit season"); Assert.That(u2.Season, Is.EqualTo(a1), "Unexpected unit season");
Assert.That(u3.Season, Is.EqualTo(a2), "Unexpected unit season"); Assert.That(u3.Season, Is.EqualTo(a2), "Unexpected unit season");