Reduce MoveOrder.Season to string
This commit is contained in:
parent
f2d3d5a583
commit
9185534f70
|
@ -60,9 +60,9 @@ public class MovementDecisions
|
||||||
{
|
{
|
||||||
case MoveOrder move:
|
case MoveOrder move:
|
||||||
AdvanceTimeline.Ensure(
|
AdvanceTimeline.Ensure(
|
||||||
move.Season,
|
world.Seasons[move.Season],
|
||||||
() => new(move.Season, world.OrderHistory[move.Season.Designation].Orders));
|
() => new(world.Seasons[move.Season], world.OrderHistory[move.Season].Orders));
|
||||||
AdvanceTimeline[move.Season].Orders.Add(move);
|
AdvanceTimeline[world.Seasons[move.Season]].Orders.Add(move);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SupportHoldOrder supportHold:
|
case SupportHoldOrder supportHold:
|
||||||
|
@ -91,23 +91,25 @@ public class MovementDecisions
|
||||||
.Distinct()
|
.Distinct()
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
(Province province, Season season) Point(Unit unit)
|
(Province province, Season season) UnitPoint(Unit unit)
|
||||||
=> (world.Map.GetLocation(unit.Location).Province, unit.Season);
|
=> (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.
|
// 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[Point(order.Unit)] = new(Point(order.Unit), order);
|
HoldStrength[UnitPoint(order.Unit)] = new(UnitPoint(order.Unit), order);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsIncoming(UnitOrder me, MoveOrder other)
|
bool IsIncoming(UnitOrder me, MoveOrder other)
|
||||||
=> me != other
|
=> me != other
|
||||||
&& other.Season == me.Unit.Season
|
&& world.Seasons[other.Season] == me.Unit.Season
|
||||||
&& other.Province == world.Map.GetLocation(me.Unit).Province;
|
&& other.Province == world.Map.GetLocation(me.Unit).Province;
|
||||||
|
|
||||||
bool AreOpposing(MoveOrder one, MoveOrder two)
|
bool AreOpposing(MoveOrder one, MoveOrder two)
|
||||||
=> one.Season == two.Unit.Season
|
=> one.Season == two.Unit.Season.Designation
|
||||||
&& two.Season == one.Unit.Season
|
&& two.Season == one.Unit.Season.Designation
|
||||||
&& one.Province == world.Map.GetLocation(two.Unit).Province
|
&& one.Province == world.Map.GetLocation(two.Unit).Province
|
||||||
&& two.Province == world.Map.GetLocation(one.Unit).Province;
|
&& two.Province == world.Map.GetLocation(one.Unit).Province;
|
||||||
|
|
||||||
|
@ -148,7 +150,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(move.Point, () => new(move.Point));
|
HoldStrength.Ensure(MovePoint(move), () => new(MovePoint(move)));
|
||||||
}
|
}
|
||||||
else if (order is SupportOrder support)
|
else if (order is SupportOrder support)
|
||||||
{
|
{
|
||||||
|
@ -156,11 +158,11 @@ 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(Point(support.Target), () => new(Point(support.Target)));
|
HoldStrength.Ensure(UnitPoint(support.Target), () => new(UnitPoint(support.Target)));
|
||||||
|
|
||||||
if (support is SupportHoldOrder supportHold)
|
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)
|
else if (support is SupportMoveOrder supportMove)
|
||||||
{
|
{
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
|
|
||||||
// Trivial check: a unit cannot move to where it already is.
|
// Trivial check: a unit cannot move to where it already is.
|
||||||
AdjudicatorHelpers.InvalidateIfNotMatching(
|
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,
|
ValidationReason.DestinationMatchesOrigin,
|
||||||
ref moveOrders,
|
ref moveOrders,
|
||||||
ref validationResults);
|
ref validationResults);
|
||||||
|
@ -92,9 +92,9 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
// Map adjacency
|
// Map adjacency
|
||||||
world.Map.GetLocation(order.Unit).Adjacents.Contains(order.Location)
|
world.Map.GetLocation(order.Unit).Adjacents.Contains(order.Location)
|
||||||
// Turn adjacency
|
// 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
|
// 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> adjacentMoveOrders = moveOrdersByAdjacency[true].ToList();
|
||||||
List<MoveOrder> nonAdjacentMoveOrders = moveOrdersByAdjacency[false].ToList();
|
List<MoveOrder> nonAdjacentMoveOrders = moveOrdersByAdjacency[false].ToList();
|
||||||
|
|
||||||
|
@ -334,10 +334,10 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
foreach (DoesMove doesMove in moves.Values)
|
foreach (DoesMove doesMove in moves.Values)
|
||||||
{
|
{
|
||||||
logger.Log(2, "{0} = {1}", doesMove, doesMove.Outcome?.ToString() ?? "?");
|
logger.Log(2, "{0} = {1}", doesMove, doesMove.Outcome?.ToString() ?? "?");
|
||||||
Season moveSeason = doesMove.Order.Season;
|
Season moveSeason = world.Seasons[doesMove.Order.Season];
|
||||||
if (doesMove.Outcome == true && createdFutures.ContainsKey(moveSeason))
|
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);
|
logger.Log(3, "Advancing unit to {0}", next);
|
||||||
createdUnits.Add(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.
|
// The season target of a new (i.e. not previously adjudicated) and successful move always advances.
|
||||||
IEnumerable<MoveOrder> newIncomingMoves = decision.Orders
|
IEnumerable<MoveOrder> newIncomingMoves = decision.Orders
|
||||||
.OfType<MoveOrder>()
|
.OfType<MoveOrder>()
|
||||||
.Where(order => order.Season == decision.Season
|
.Where(order => order.Season == decision.Season.Designation
|
||||||
&& !world.OrderHistory[order.Season.Designation].DoesMoveOutcomes.ContainsKey(order.Unit.Designation));
|
&& !world.OrderHistory[order.Season].DoesMoveOutcomes.ContainsKey(order.Unit.Designation));
|
||||||
foreach (MoveOrder moveOrder in newIncomingMoves)
|
foreach (MoveOrder moveOrder in newIncomingMoves)
|
||||||
{
|
{
|
||||||
DoesMove doesMove = decisions.DoesMove[moveOrder];
|
DoesMove doesMove = decisions.DoesMove[moveOrder];
|
||||||
|
@ -635,9 +635,9 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
if (// Map adjacency
|
if (// Map adjacency
|
||||||
world.Map.GetLocation(decision.Order.Unit).Adjacents.Contains(decision.Order.Location)
|
world.Map.GetLocation(decision.Order.Unit).Adjacents.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 - world.Seasons[decision.Order.Season].Turn) <= 1
|
||||||
// Timeline adjacency
|
// 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");
|
bool update = LoggedUpdate(decision, true, depth, "Adjacent move");
|
||||||
return progress | update;
|
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
|
// 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.Point].Order;
|
UnitOrder? destOrder = decisions.HoldStrength[(decision.Order.Province, world.Seasons[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.Point];
|
: decisions.HoldStrength[(decision.Order.Province, world.Seasons[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.
|
||||||
|
|
|
@ -18,7 +18,7 @@ public static class PathFinder
|
||||||
/// Determines if a convoy path exists for a move order.
|
/// Determines if a convoy path exists for a move order.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static bool ConvoyPathExists(World world, MoveOrder order)
|
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(
|
private static bool ConvoyPathExists(
|
||||||
World world,
|
World world,
|
||||||
|
|
|
@ -9,8 +9,9 @@ public class MoveOrder : UnitOrder
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The destination season to which the unit should move.
|
/// 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>
|
/// </summary>
|
||||||
public Season Season { get; }
|
public string Season { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The destination location to which the unit should move.
|
/// The destination location to which the unit should move.
|
||||||
|
@ -22,12 +23,7 @@ public class MoveOrder : UnitOrder
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Province Province => this.Location.Province;
|
public Province Province => this.Location.Province;
|
||||||
|
|
||||||
/// <summary>
|
public MoveOrder(Power power, Unit unit, string season, Location location)
|
||||||
/// 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)
|
|
||||||
: base (power, unit)
|
: base (power, unit)
|
||||||
{
|
{
|
||||||
this.Season = season;
|
this.Season = season;
|
||||||
|
@ -36,7 +32,7 @@ public class MoveOrder : UnitOrder
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{this.Unit} -> {(this.Province, this.Season).ToShort()}";
|
return $"{this.Unit} -> {this.Season} {this.Province}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -41,6 +41,6 @@ public class SupportMoveOrder : SupportOrder
|
||||||
|
|
||||||
public bool IsSupportFor(MoveOrder move)
|
public bool IsSupportFor(MoveOrder move)
|
||||||
=> this.Target == move.Unit
|
=> this.Target == move.Unit
|
||||||
&& this.Season == move.Season
|
&& this.Season.Designation == move.Season
|
||||||
&& this.Location == move.Location;
|
&& this.Location == move.Location;
|
||||||
}
|
}
|
|
@ -419,7 +419,7 @@ public class TestCaseBuilder
|
||||||
MoveOrder moveOrder = new MoveOrder(
|
MoveOrder moveOrder = new MoveOrder(
|
||||||
this.PowerContext.Power,
|
this.PowerContext.Power,
|
||||||
this.Unit,
|
this.Unit,
|
||||||
destSeason,
|
destSeason.Designation,
|
||||||
destination);
|
destination);
|
||||||
this.Builder.OrderList.Add(moveOrder);
|
this.Builder.OrderList.Add(moveOrder);
|
||||||
return new OrderDefinedContext<MoveOrder>(this, moveOrder);
|
return new OrderDefinedContext<MoveOrder>(this, moveOrder);
|
||||||
|
|
Loading…
Reference in New Issue