Compare commits

...

2 Commits

Author SHA1 Message Date
Tim Van Baak 601ce2d297 HoldStrength uses season string 2024-08-14 22:40:40 -07:00
Tim Van Baak 64f48064fc AdvanceTimeline key to string 2024-08-14 22:32:48 -07:00
2 changed files with 28 additions and 21 deletions

View File

@ -8,12 +8,12 @@ public class MovementDecisions
public Dictionary<Unit, IsDislodged> IsDislodged { get; } public Dictionary<Unit, IsDislodged> IsDislodged { get; }
public Dictionary<MoveOrder, HasPath> HasPath { get; } public Dictionary<MoveOrder, HasPath> HasPath { get; }
public Dictionary<SupportOrder, GivesSupport> GivesSupport { get; } public Dictionary<SupportOrder, GivesSupport> GivesSupport { get; }
public Dictionary<(Province, Season), HoldStrength> HoldStrength { get; } public Dictionary<(Province, string), HoldStrength> HoldStrength { get; }
public Dictionary<MoveOrder, AttackStrength> AttackStrength { get; } public Dictionary<MoveOrder, AttackStrength> AttackStrength { get; }
public Dictionary<MoveOrder, DefendStrength> DefendStrength { get; } public Dictionary<MoveOrder, DefendStrength> DefendStrength { get; }
public Dictionary<MoveOrder, PreventStrength> PreventStrength { get; } public Dictionary<MoveOrder, PreventStrength> PreventStrength { get; }
public Dictionary<MoveOrder, DoesMove> DoesMove { get; } public Dictionary<MoveOrder, DoesMove> DoesMove { get; }
public Dictionary<Season, AdvanceTimeline> AdvanceTimeline { get; } public Dictionary<string, AdvanceTimeline> AdvanceTimeline { get; }
public IEnumerable<AdjudicationDecision> Values => public IEnumerable<AdjudicationDecision> Values =>
IsDislodged.Values.Cast<AdjudicationDecision>() IsDislodged.Values.Cast<AdjudicationDecision>()
@ -47,7 +47,7 @@ public class MovementDecisions
var submittedOrdersBySeason = orders.Cast<UnitOrder>().ToLookup(order => order.Unit.Season); var submittedOrdersBySeason = orders.Cast<UnitOrder>().ToLookup(order => order.Unit.Season);
foreach (var group in submittedOrdersBySeason) foreach (var group in submittedOrdersBySeason)
{ {
AdvanceTimeline[group.Key] = new(group.Key, group); AdvanceTimeline[group.Key.Designation] = new(group.Key, group);
} }
// Create timeline decisions for each season potentially affected by the submitted orders. // Create timeline decisions for each season potentially affected by the submitted orders.
@ -60,27 +60,27 @@ public class MovementDecisions
{ {
case MoveOrder move: case MoveOrder move:
AdvanceTimeline.Ensure( AdvanceTimeline.Ensure(
world.Seasons[move.Season], move.Season,
() => new(world.Seasons[move.Season], world.OrderHistory[move.Season].Orders)); () => new(world.Seasons[move.Season], world.OrderHistory[move.Season].Orders));
AdvanceTimeline[world.Seasons[move.Season]].Orders.Add(move); AdvanceTimeline[move.Season].Orders.Add(move);
break; break;
case SupportHoldOrder supportHold: case SupportHoldOrder supportHold:
AdvanceTimeline.Ensure( AdvanceTimeline.Ensure(
supportHold.Target.Season, supportHold.Target.Season.Designation,
() => new(supportHold.Target.Season, world.OrderHistory[supportHold.Target.Season.Designation].Orders)); () => new(supportHold.Target.Season, world.OrderHistory[supportHold.Target.Season.Designation].Orders));
AdvanceTimeline[supportHold.Target.Season].Orders.Add(supportHold); AdvanceTimeline[supportHold.Target.Season.Designation].Orders.Add(supportHold);
break; break;
case SupportMoveOrder supportMove: case SupportMoveOrder supportMove:
AdvanceTimeline.Ensure( AdvanceTimeline.Ensure(
supportMove.Target.Season, supportMove.Target.Season.Designation,
() => new(supportMove.Target.Season, world.OrderHistory[supportMove.Target.Season.Designation].Orders)); () => new(supportMove.Target.Season, world.OrderHistory[supportMove.Target.Season.Designation].Orders));
AdvanceTimeline[supportMove.Target.Season].Orders.Add(supportMove); AdvanceTimeline[supportMove.Target.Season.Designation].Orders.Add(supportMove);
AdvanceTimeline.Ensure( AdvanceTimeline.Ensure(
supportMove.Season, supportMove.Season.Designation,
() => new(supportMove.Season, world.OrderHistory[supportMove.Season.Designation].Orders)); () => new(supportMove.Season, world.OrderHistory[supportMove.Season.Designation].Orders));
AdvanceTimeline[supportMove.Season].Orders.Add(supportMove); AdvanceTimeline[supportMove.Season.Designation].Orders.Add(supportMove);
break; break;
} }
} }
@ -91,15 +91,18 @@ public class MovementDecisions
.Distinct() .Distinct()
.ToList(); .ToList();
(Province province, Season season) UnitPoint(Unit unit) (Province province, string season) UnitPoint(Unit unit)
=> (world.Map.GetLocation(unit.Location).Province, unit.Season); => (world.Map.GetLocation(unit.Location).Province, unit.Season.Designation);
(Province province, Season season) MovePoint(MoveOrder move) (Province province, string season) MovePoint(MoveOrder move)
=> (move.Province, world.Seasons[move.Season]); => (move.Province, move.Season);
// Create a hold strength decision with an associated order for every province with a unit. // Create a hold strength decision with an associated order for every province with a unit.
foreach (UnitOrder order in relevantOrders) foreach (UnitOrder order in relevantOrders)
{ {
HoldStrength[UnitPoint(order.Unit)] = new(UnitPoint(order.Unit), order); HoldStrength[UnitPoint(order.Unit)] = new(
world.Map.GetLocation(order.Unit.Location).Province,
order.Unit.Season,
order);
} }
bool IsIncoming(UnitOrder me, MoveOrder other) bool IsIncoming(UnitOrder me, MoveOrder other)
@ -150,7 +153,7 @@ public class MovementDecisions
DoesMove[move] = new(move, opposingMove, competing); DoesMove[move] = new(move, opposingMove, competing);
// Ensure a hold strength decision exists for the destination. // Ensure a hold strength decision exists for the destination.
HoldStrength.Ensure(MovePoint(move), () => new(MovePoint(move))); HoldStrength.Ensure(MovePoint(move), () => new(move.Province, world.Seasons[move.Season]));
} }
else if (order is SupportOrder support) else if (order is SupportOrder support)
{ {
@ -158,7 +161,9 @@ public class MovementDecisions
GivesSupport[support] = new(support, incoming); GivesSupport[support] = new(support, incoming);
// 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(UnitPoint(support.Target))); HoldStrength.Ensure(UnitPoint(support.Target), () => new(
world.Map.GetLocation(support.Target.Location).Province,
support.Target.Season));
if (support is SupportHoldOrder supportHold) if (support is SupportHoldOrder supportHold)
{ {
@ -167,7 +172,9 @@ public class MovementDecisions
else if (support is SupportMoveOrder supportMove) else if (support is SupportMoveOrder supportMove)
{ {
// Ensure a hold strength decision exists for the target's destination. // Ensure a hold strength decision exists for the target's destination.
HoldStrength.Ensure(supportMove.Point, () => new(supportMove.Point)); HoldStrength.Ensure(
(supportMove.Province, supportMove.Season.Designation),
() => new(supportMove.Province, supportMove.Season));
} }
} }
} }

View File

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