Reduce MoveOrder.Season to string

This commit is contained in:
Tim Van Baak 2024-08-14 22:28:56 -07:00
parent f2d3d5a583
commit 9185534f70
6 changed files with 32 additions and 34 deletions

View File

@ -60,9 +60,9 @@ public class MovementDecisions
{
case MoveOrder move:
AdvanceTimeline.Ensure(
move.Season,
() => new(move.Season, world.OrderHistory[move.Season.Designation].Orders));
AdvanceTimeline[move.Season].Orders.Add(move);
world.Seasons[move.Season],
() => new(world.Seasons[move.Season], world.OrderHistory[move.Season].Orders));
AdvanceTimeline[world.Seasons[move.Season]].Orders.Add(move);
break;
case SupportHoldOrder supportHold:
@ -91,23 +91,25 @@ public class MovementDecisions
.Distinct()
.ToList();
(Province province, Season season) Point(Unit unit)
(Province province, Season season) UnitPoint(Unit unit)
=> (world.Map.GetLocation(unit.Location).Province, unit.Season);
(Province province, Season season) MovePoint(MoveOrder move)
=> (move.Province, world.Seasons[move.Season]);
// Create a hold strength decision with an associated order for every province with a unit.
foreach (UnitOrder order in relevantOrders)
{
HoldStrength[Point(order.Unit)] = new(Point(order.Unit), order);
HoldStrength[UnitPoint(order.Unit)] = new(UnitPoint(order.Unit), order);
}
bool IsIncoming(UnitOrder me, MoveOrder other)
=> me != other
&& other.Season == me.Unit.Season
&& world.Seasons[other.Season] == me.Unit.Season
&& other.Province == world.Map.GetLocation(me.Unit).Province;
bool AreOpposing(MoveOrder one, MoveOrder two)
=> one.Season == two.Unit.Season
&& two.Season == one.Unit.Season
=> one.Season == two.Unit.Season.Designation
&& two.Season == one.Unit.Season.Designation
&& one.Province == world.Map.GetLocation(two.Unit).Province
&& two.Province == world.Map.GetLocation(one.Unit).Province;
@ -148,7 +150,7 @@ public class MovementDecisions
DoesMove[move] = new(move, opposingMove, competing);
// Ensure a hold strength decision exists for the destination.
HoldStrength.Ensure(move.Point, () => new(move.Point));
HoldStrength.Ensure(MovePoint(move), () => new(MovePoint(move)));
}
else if (order is SupportOrder support)
{
@ -156,11 +158,11 @@ public class MovementDecisions
GivesSupport[support] = new(support, incoming);
// Ensure a hold strength decision exists for the target's province.
HoldStrength.Ensure(Point(support.Target), () => new(Point(support.Target)));
HoldStrength.Ensure(UnitPoint(support.Target), () => new(UnitPoint(support.Target)));
if (support is SupportHoldOrder supportHold)
{
HoldStrength[Point(support.Target)].Supports.Add(supportHold);
HoldStrength[UnitPoint(support.Target)].Supports.Add(supportHold);
}
else if (support is SupportMoveOrder supportMove)
{

View File

@ -77,7 +77,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
// Trivial check: a unit cannot move to where it already is.
AdjudicatorHelpers.InvalidateIfNotMatching(
order => !(order.Location.Designation == order.Unit.Location && order.Season == order.Unit.Season),
order => !(order.Location.Designation == order.Unit.Location && order.Season == order.Unit.Season.Designation),
ValidationReason.DestinationMatchesOrigin,
ref moveOrders,
ref validationResults);
@ -92,9 +92,9 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
// Map adjacency
world.Map.GetLocation(order.Unit).Adjacents.Contains(order.Location)
// Turn adjacency
&& Math.Abs(order.Unit.Season.Turn - order.Season.Turn) <= 1
&& Math.Abs(order.Unit.Season.Turn - world.Seasons[order.Season].Turn) <= 1
// Timeline adjacency
&& world.InAdjacentTimeline(order.Unit.Season, order.Season));
&& world.InAdjacentTimeline(order.Unit.Season, world.Seasons[order.Season]));
List<MoveOrder> adjacentMoveOrders = moveOrdersByAdjacency[true].ToList();
List<MoveOrder> nonAdjacentMoveOrders = moveOrdersByAdjacency[false].ToList();
@ -334,10 +334,10 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
foreach (DoesMove doesMove in moves.Values)
{
logger.Log(2, "{0} = {1}", doesMove, doesMove.Outcome?.ToString() ?? "?");
Season moveSeason = doesMove.Order.Season;
if (doesMove.Outcome == true && createdFutures.ContainsKey(moveSeason))
Season moveSeason = world.Seasons[doesMove.Order.Season];
if (doesMove.Outcome == true && createdFutures.TryGetValue(moveSeason, out Season? future))
{
Unit next = doesMove.Order.Unit.Next(doesMove.Order.Location.Designation, createdFutures[moveSeason]);
Unit next = doesMove.Order.Unit.Next(doesMove.Order.Location.Designation, future);
logger.Log(3, "Advancing unit to {0}", next);
createdUnits.Add(next);
}
@ -493,8 +493,8 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
// The season target of a new (i.e. not previously adjudicated) and successful move always advances.
IEnumerable<MoveOrder> newIncomingMoves = decision.Orders
.OfType<MoveOrder>()
.Where(order => order.Season == decision.Season
&& !world.OrderHistory[order.Season.Designation].DoesMoveOutcomes.ContainsKey(order.Unit.Designation));
.Where(order => order.Season == decision.Season.Designation
&& !world.OrderHistory[order.Season].DoesMoveOutcomes.ContainsKey(order.Unit.Designation));
foreach (MoveOrder moveOrder in newIncomingMoves)
{
DoesMove doesMove = decisions.DoesMove[moveOrder];
@ -635,9 +635,9 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
if (// Map adjacency
world.Map.GetLocation(decision.Order.Unit).Adjacents.Contains(decision.Order.Location)
// Turn adjacency
&& Math.Abs(decision.Order.Unit.Season.Turn - decision.Order.Season.Turn) <= 1
&& Math.Abs(decision.Order.Unit.Season.Turn - world.Seasons[decision.Order.Season].Turn) <= 1
// Timeline adjacency
&& world.InAdjacentTimeline(decision.Order.Unit.Season, decision.Order.Season))
&& world.InAdjacentTimeline(decision.Order.Unit.Season, world.Seasons[decision.Order.Season]))
{
bool update = LoggedUpdate(decision, true, depth, "Adjacent move");
return progress | update;
@ -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
// 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.Point].Order;
UnitOrder? destOrder = decisions.HoldStrength[(decision.Order.Province, world.Seasons[decision.Order.Season])].Order;
DoesMove? destMoveAway = destOrder is MoveOrder moveAway
? decisions.DoesMove[moveAway]
: null;
@ -953,7 +953,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
// strength.
NumericAdjudicationDecision defense = decision.OpposingMove != null
? decisions.DefendStrength[decision.OpposingMove]
: decisions.HoldStrength[decision.Order.Point];
: decisions.HoldStrength[(decision.Order.Province, world.Seasons[decision.Order.Season])];
progress |= ResolveDecision(defense, world, decisions, depth + 1);
// If the attack doesn't beat the defense, resolve the move to false.

View File

@ -18,7 +18,7 @@ public static class PathFinder
/// Determines if a convoy path exists for a move order.
/// </summary>
public static bool ConvoyPathExists(World world, MoveOrder order)
=> ConvoyPathExists(world, order.Unit, order.Location, order.Season);
=> ConvoyPathExists(world, order.Unit, order.Location, world.Seasons[order.Season]);
private static bool ConvoyPathExists(
World world,

View File

@ -9,8 +9,9 @@ public class MoveOrder : UnitOrder
{
/// <summary>
/// The destination season to which the unit should move.
/// TODO replace this with timeline and turn individually so ToString can do the proper format
/// </summary>
public Season Season { get; }
public string Season { get; }
/// <summary>
/// The destination location to which the unit should move.
@ -22,12 +23,7 @@ public class MoveOrder : UnitOrder
/// </summary>
public Province Province => this.Location.Province;
/// <summary>
/// The destination's spatiotemporal location as a province-season tuple.
/// </summary>
public (Province province, Season season) Point => (this.Province, this.Season);
public MoveOrder(Power power, Unit unit, Season season, Location location)
public MoveOrder(Power power, Unit unit, string season, Location location)
: base (power, unit)
{
this.Season = season;
@ -36,7 +32,7 @@ public class MoveOrder : UnitOrder
public override string ToString()
{
return $"{this.Unit} -> {(this.Province, this.Season).ToShort()}";
return $"{this.Unit} -> {this.Season} {this.Province}";
}
/// <summary>

View File

@ -41,6 +41,6 @@ public class SupportMoveOrder : SupportOrder
public bool IsSupportFor(MoveOrder move)
=> this.Target == move.Unit
&& this.Season == move.Season
&& this.Season.Designation == move.Season
&& this.Location == move.Location;
}

View File

@ -419,7 +419,7 @@ public class TestCaseBuilder
MoveOrder moveOrder = new MoveOrder(
this.PowerContext.Power,
this.Unit,
destSeason,
destSeason.Designation,
destination);
this.Builder.OrderList.Add(moveOrder);
return new OrderDefinedContext<MoveOrder>(this, moveOrder);