Reduce Unit.Power to string

This commit is contained in:
Tim Van Baak 2024-08-15 07:37:05 -07:00
parent 2e6e6c55b8
commit bfdf2d5636
7 changed files with 21 additions and 21 deletions

View File

@ -77,13 +77,13 @@ internal static class AdjudicatorHelpers
{
InvalidateIfNotMatching(
order => order switch {
ConvoyOrder convoy => convoy.Power == convoy.Unit.Power.Name,
DisbandOrder disband => disband.Power == disband.Unit.Power.Name,
HoldOrder hold => hold.Power == hold.Unit.Power.Name,
MoveOrder move => move.Power == move.Unit.Power.Name,
RetreatOrder retreat => retreat.Power == retreat.Unit.Power.Name,
SupportHoldOrder support => support.Power == support.Unit.Power.Name,
SupportMoveOrder support => support.Power == support.Unit.Power.Name,
ConvoyOrder convoy => convoy.Power == convoy.Unit.Power,
DisbandOrder disband => disband.Power == disband.Unit.Power,
HoldOrder hold => hold.Power == hold.Unit.Power,
MoveOrder move => move.Power == move.Unit.Power,
RetreatOrder retreat => retreat.Power == retreat.Unit.Power,
SupportHoldOrder support => support.Power == support.Unit.Power,
SupportMoveOrder support => support.Power == support.Unit.Power,
// Any order not given to a unit, by definition, cannot be given to a unit of the
// wrong power
_ => true,

View File

@ -262,7 +262,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
.Where(unit => !orderedUnits.Contains(unit))
.ToList();
List<HoldOrder> implicitHolds = unorderedUnits
.Select(unit => new HoldOrder(unit.Power.Name, unit))
.Select(unit => new HoldOrder(unit.Power, unit))
.ToList();
validationResults = validationResults
.Concat(implicitHolds.Select(o => o.Validate(ValidationReason.Valid)))
@ -793,7 +793,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
// Is failing to move away
|| destMoveAway.Outcome == false))
{
Power destPower = destOrder.Unit.Power;
string destPower = destOrder.Unit.Power;
if (decision.Order.Unit.Power == destPower)
{
// Cannot dislodge own unit.
@ -823,7 +823,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
// the case where it doesn't move and the attack strength is mitigated by supports not
// helping to dislodge units of the same power as the support. The maximum tracks the
// case where it does move and the attack strength is unmitigated.
Power destPower = destMoveAway.Order.Unit.Power;
string destPower = destMoveAway.Order.Unit.Power;
int min = 1;
int max = 1;
foreach (SupportMoveOrder support in decision.Supports)

View File

@ -25,7 +25,7 @@ public class Unit
/// <summary>
/// The allegiance of the unit.
/// </summary>
public Power Power { get; }
public string Power { get; }
/// <summary>
/// The type of unit.
@ -38,7 +38,7 @@ public class Unit
[JsonIgnore]
public string Key => $"{Type.ToShort()} {Season.Timeline}-{Location}@{Season.Turn}";
public Unit(string? past, string location, Season season, Power power, UnitType type)
public Unit(string? past, string location, Season season, string power, UnitType type)
{
this.Past = past;
this.Location = location;
@ -48,13 +48,13 @@ public class Unit
}
public override string ToString()
=> $"{Power.Name[0]} {Type.ToShort()} {Season.Timeline}-{Location}@{Season.Turn}";
=> $"{Power[0]} {Type.ToShort()} {Season.Timeline}-{Location}@{Season.Turn}";
/// <summary>
/// Create a new unit. No validation is performed; the adjudicator should only call this
/// method after accepting a build order.
/// </summary>
public static Unit Build(string location, Season season, Power power, UnitType type)
public static Unit Build(string location, Season season, string power, UnitType type)
=> new(past: null, location, season, power, type);
/// <summary>

View File

@ -202,7 +202,7 @@ public class World
: splits.Length == 3
? Map.GetWater(splits[2])
: Map.GetWater(splits[2], splits[3]);
Unit unit = Unit.Build(location.Key, this.RootSeason, power, type);
Unit unit = Unit.Build(location.Key, this.RootSeason, power.Name, type);
return unit;
});
return this.Update(units: units);

View File

@ -261,7 +261,7 @@ public class TestCaseBuilder
{
foreach (Unit unit in this.World.Units)
{
if (unit.Power == power
if (unit.Power == power.Name
&& World.Map.GetLocation(unit).Province == location.Province
&& unit.Season == season)
{
@ -270,7 +270,7 @@ public class TestCaseBuilder
}
// Not found
Unit newUnit = Unit.Build(location.Key, season, power, type);
Unit newUnit = Unit.Build(location.Key, season, power.Name, type);
this.World = this.World.Update(units: this.World.Units.Append(newUnit));
return newUnit;
}

View File

@ -28,15 +28,15 @@ class TestCaseBuilderTest
Assert.That(setup.World.Units, Is.Not.Empty, "Expected units to be created");
Unit armyLON = setup.World.GetUnitAt("London");
Assert.That(armyLON.Power.Name, Is.EqualTo("England"), "Unit created with wrong power");
Assert.That(armyLON.Power, Is.EqualTo("England"), "Unit created with wrong power");
Assert.That(armyLON.Type, Is.EqualTo(UnitType.Army), "Unit created with wrong type");
Unit fleetIRI = setup.World.GetUnitAt("Irish Sea");
Assert.That(fleetIRI.Power.Name, Is.EqualTo("England"), "Unit created with wrong power");
Assert.That(fleetIRI.Power, Is.EqualTo("England"), "Unit created with wrong power");
Assert.That(fleetIRI.Type, Is.EqualTo(UnitType.Fleet), "Unit created with wrong type");
Unit fleetSTP = setup.World.GetUnitAt("Saint Petersburg");
Assert.That(fleetSTP.Power.Name, Is.EqualTo("Russia"), "Unit created with wrong power");
Assert.That(fleetSTP.Power, Is.EqualTo("Russia"), "Unit created with wrong power");
Assert.That(fleetSTP.Type, Is.EqualTo(UnitType.Fleet), "Unit created with wrong type");
Assert.That(
fleetSTP.Location,

View File

@ -15,7 +15,7 @@ public class UnitTests
Tyr = world.Map.GetLand("Tyr");
Power pw1 = world.Map.GetPower("Austria");
Season a0 = world.RootSeason;
Unit u1 = Unit.Build(Mun.Key, a0, pw1, UnitType.Army);
Unit u1 = Unit.Build(Mun.Key, a0, pw1.Name, UnitType.Army);
world = world.ContinueOrFork(a0, out Season a1);
Unit u2 = u1.Next(Boh.Key, a1);