Eliminate MoveOrder.Province

This commit is contained in:
Tim Van Baak 2024-08-15 21:48:41 -07:00
parent ff9e6196ad
commit f21b1e500c
3 changed files with 14 additions and 19 deletions

View File

@ -8,7 +8,7 @@ public class MovementDecisions
public Dictionary<Unit, IsDislodged> IsDislodged { get; }
public Dictionary<MoveOrder, HasPath> HasPath { get; }
public Dictionary<SupportOrder, GivesSupport> GivesSupport { get; }
public Dictionary<(Province, string), HoldStrength> HoldStrength { get; }
public Dictionary<(string, string), HoldStrength> HoldStrength { get; }
public Dictionary<MoveOrder, AttackStrength> AttackStrength { get; }
public Dictionary<MoveOrder, DefendStrength> DefendStrength { get; }
public Dictionary<MoveOrder, PreventStrength> PreventStrength { get; }
@ -91,10 +91,10 @@ public class MovementDecisions
.Distinct()
.ToList();
(Province province, string season) UnitPoint(Unit unit)
=> (world.Map.GetLocation(unit.Location).Province, unit.Season.Key);
(Province province, string season) MovePoint(MoveOrder move)
=> (move.Province, move.Season.Key);
(string province, string season) UnitPoint(Unit unit)
=> (world.Map.GetLocation(unit.Location).Province.Name, unit.Season.Key);
(string province, string season) MovePoint(MoveOrder move)
=> (move.Location.Province.Name, move.Season.Key);
// Create a hold strength decision with an associated order for every province with a unit.
foreach (UnitOrder order in relevantOrders)
@ -108,13 +108,13 @@ public class MovementDecisions
bool IsIncoming(UnitOrder me, MoveOrder other)
=> me != other
&& other.Season == me.Unit.Season
&& other.Province == world.Map.GetLocation(me.Unit).Province;
&& other.Location.Province.Name == world.Map.GetLocation(me.Unit).Province.Name;
bool AreOpposing(MoveOrder one, MoveOrder two)
=> one.Season == two.Unit.Season
&& two.Season == one.Unit.Season
&& one.Province == world.Map.GetLocation(two.Unit).Province
&& two.Province == world.Map.GetLocation(one.Unit).Province;
&& one.Location.Province.Name == world.Map.GetLocation(two.Unit).Province.Name
&& two.Location.Province.Name == world.Map.GetLocation(one.Unit).Province.Name;
// Create all other relevant decisions for each order in the affected timelines.
foreach (UnitOrder order in relevantOrders)
@ -153,7 +153,7 @@ public class MovementDecisions
DoesMove[move] = new(move, opposingMove, competing);
// Ensure a hold strength decision exists for the destination.
HoldStrength.Ensure(MovePoint(move), () => new(move.Province, move.Season));
HoldStrength.Ensure(MovePoint(move), () => new(move.Location.Province, move.Season));
}
else if (order is SupportOrder support)
{
@ -173,7 +173,7 @@ public class MovementDecisions
{
// Ensure a hold strength decision exists for the target's destination.
HoldStrength.Ensure(
(supportMove.Province, supportMove.Season.Key),
(supportMove.Province.Name, supportMove.Season.Key),
() => new(supportMove.Province, supportMove.Season));
}
}

View File

@ -776,7 +776,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
// If there is a head to head battle, a unit at the destination that isn't moving away, or
// a unit at the destination that will fail to move away, then the attacking unit will have
// to dislodge it.
UnitOrder? destOrder = decisions.HoldStrength[(decision.Order.Province, decision.Order.Season.Key)].Order;
UnitOrder? destOrder = decisions.HoldStrength[(decision.Order.Location.Province.Name, decision.Order.Season.Key)].Order;
DoesMove? destMoveAway = destOrder is MoveOrder moveAway
? decisions.DoesMove[moveAway]
: null;
@ -955,7 +955,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
// strength.
NumericAdjudicationDecision defense = decision.OpposingMove != null
? decisions.DefendStrength[decision.OpposingMove]
: decisions.HoldStrength[(decision.Order.Province, decision.Order.Season.Key)];
: decisions.HoldStrength[(decision.Order.Location.Province.Name, decision.Order.Season.Key)];
progress |= ResolveDecision(defense, world, decisions, depth + 1);
// If the attack doesn't beat the defense, resolve the move to false.

View File

@ -17,11 +17,6 @@ public class MoveOrder : UnitOrder
/// </summary>
public Location Location { get; }
/// <summary>
/// The destination province to which the unit should move.
/// </summary>
public Province Province => this.Location.Province;
public MoveOrder(string power, Unit unit, Season season, Location location)
: base (power, unit)
{
@ -31,7 +26,7 @@ public class MoveOrder : UnitOrder
public override string ToString()
{
return $"{this.Unit} -> {Season.Timeline}-{Province}@{Season.Turn}";
return $"{this.Unit} -> {Season.Timeline}-{Location.Province}@{Season.Turn}";
}
/// <summary>
@ -40,5 +35,5 @@ public class MoveOrder : UnitOrder
public bool IsCompeting(MoveOrder other)
=> this != other
&& this.Season == other.Season
&& this.Province == other.Province;
&& this.Location.Province == other.Location.Province;
}