Compare commits
No commits in common. "9a646096055e7568f26ed9c69b84a0144eca97f3" and "25d903d91aaac638292ca11bd5db7bdc13e571d3" have entirely different histories.
9a64609605
...
25d903d91a
|
@ -1,8 +1,6 @@
|
||||||
using MultiversalDiplomacy.Model;
|
using MultiversalDiplomacy.Model;
|
||||||
using MultiversalDiplomacy.Orders;
|
using MultiversalDiplomacy.Orders;
|
||||||
|
|
||||||
using static MultiversalDiplomacy.Model.Location;
|
|
||||||
|
|
||||||
namespace MultiversalDiplomacy.Adjudicate.Decision;
|
namespace MultiversalDiplomacy.Adjudicate.Decision;
|
||||||
|
|
||||||
public class MovementDecisions
|
public class MovementDecisions
|
||||||
|
@ -10,7 +8,7 @@ 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<(string, string), 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; }
|
||||||
|
@ -93,10 +91,10 @@ public class MovementDecisions
|
||||||
.Distinct()
|
.Distinct()
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
(string province, string season) UnitPoint(Unit unit)
|
(Province province, string season) UnitPoint(Unit unit)
|
||||||
=> (world.Map.GetLocation(unit.Location).Province.Name, unit.Season.Key);
|
=> (world.Map.GetLocation(unit.Location).Province, unit.Season.Key);
|
||||||
(string province, string season) MovePoint(MoveOrder move)
|
(Province province, string season) MovePoint(MoveOrder move)
|
||||||
=> (SplitKey(move.Location).province, move.Season.Key);
|
=> (move.Province, move.Season.Key);
|
||||||
|
|
||||||
// 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)
|
||||||
|
@ -110,23 +108,13 @@ public class MovementDecisions
|
||||||
bool IsIncoming(UnitOrder me, MoveOrder other)
|
bool IsIncoming(UnitOrder me, MoveOrder other)
|
||||||
=> me != other
|
=> me != other
|
||||||
&& other.Season == me.Unit.Season
|
&& other.Season == me.Unit.Season
|
||||||
&& SplitKey(other.Location).province == world.Map.GetLocation(me.Unit).Province.Name;
|
&& other.Province == world.Map.GetLocation(me.Unit).Province;
|
||||||
|
|
||||||
bool IsSupportFor(SupportMoveOrder me, MoveOrder move)
|
|
||||||
=> me.Target == move.Unit
|
|
||||||
&& me.Season == move.Season
|
|
||||||
&& me.Location.Key == move.Location;
|
|
||||||
|
|
||||||
bool AreOpposing(MoveOrder one, MoveOrder two)
|
bool AreOpposing(MoveOrder one, MoveOrder two)
|
||||||
=> one.Season == two.Unit.Season
|
=> one.Season == two.Unit.Season
|
||||||
&& two.Season == one.Unit.Season
|
&& two.Season == one.Unit.Season
|
||||||
&& SplitKey(one.Location).province == world.Map.GetLocation(two.Unit).Province.Name
|
&& one.Province == world.Map.GetLocation(two.Unit).Province
|
||||||
&& SplitKey(two.Location).province == world.Map.GetLocation(one.Unit).Province.Name;
|
&& two.Province == world.Map.GetLocation(one.Unit).Province;
|
||||||
|
|
||||||
bool AreCompeting(MoveOrder one, MoveOrder two)
|
|
||||||
=> one != two
|
|
||||||
&& one.Season == two.Season
|
|
||||||
&& SplitKey(one.Location).province == SplitKey(two.Location).province;
|
|
||||||
|
|
||||||
// Create all other relevant decisions for each order in the affected timelines.
|
// Create all other relevant decisions for each order in the affected timelines.
|
||||||
foreach (UnitOrder order in relevantOrders)
|
foreach (UnitOrder order in relevantOrders)
|
||||||
|
@ -143,7 +131,7 @@ public class MovementDecisions
|
||||||
// Find supports corresponding to this move.
|
// Find supports corresponding to this move.
|
||||||
List<SupportMoveOrder> supports = relevantOrders
|
List<SupportMoveOrder> supports = relevantOrders
|
||||||
.OfType<SupportMoveOrder>()
|
.OfType<SupportMoveOrder>()
|
||||||
.Where(support => IsSupportFor(support, move))
|
.Where(support => support.IsSupportFor(move))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
// Determine if this move is a head-to-head battle.
|
// Determine if this move is a head-to-head battle.
|
||||||
|
@ -154,7 +142,7 @@ public class MovementDecisions
|
||||||
// Find competing moves.
|
// Find competing moves.
|
||||||
List<MoveOrder> competing = relevantOrders
|
List<MoveOrder> competing = relevantOrders
|
||||||
.OfType<MoveOrder>()
|
.OfType<MoveOrder>()
|
||||||
.Where(other => AreCompeting(move, other))
|
.Where(move.IsCompeting)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
// Create the move-related decisions.
|
// Create the move-related decisions.
|
||||||
|
@ -165,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(world.Map.GetLocation(move.Location).Province, move.Season));
|
HoldStrength.Ensure(MovePoint(move), () => new(move.Province, move.Season));
|
||||||
}
|
}
|
||||||
else if (order is SupportOrder support)
|
else if (order is SupportOrder support)
|
||||||
{
|
{
|
||||||
|
@ -185,7 +173,7 @@ public class MovementDecisions
|
||||||
{
|
{
|
||||||
// Ensure a hold strength decision exists for the target's destination.
|
// Ensure a hold strength decision exists for the target's destination.
|
||||||
HoldStrength.Ensure(
|
HoldStrength.Ensure(
|
||||||
(supportMove.Province.Name, supportMove.Season.Key),
|
(supportMove.Province, supportMove.Season.Key),
|
||||||
() => new(supportMove.Province, supportMove.Season));
|
() => new(supportMove.Province, supportMove.Season));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,6 @@ using MultiversalDiplomacy.Adjudicate.Logging;
|
||||||
using MultiversalDiplomacy.Model;
|
using MultiversalDiplomacy.Model;
|
||||||
using MultiversalDiplomacy.Orders;
|
using MultiversalDiplomacy.Orders;
|
||||||
|
|
||||||
using static MultiversalDiplomacy.Model.Location;
|
|
||||||
|
|
||||||
namespace MultiversalDiplomacy.Adjudicate;
|
namespace MultiversalDiplomacy.Adjudicate;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -71,15 +69,15 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
|
|
||||||
// Trivial check: armies cannot move to water and fleets cannot move to land.
|
// Trivial check: armies cannot move to water and fleets cannot move to land.
|
||||||
AdjudicatorHelpers.InvalidateIfNotMatching(
|
AdjudicatorHelpers.InvalidateIfNotMatching(
|
||||||
order => (order.Unit.Type == UnitType.Army && world.Map.GetLocation(order.Location).Type == LocationType.Land)
|
order => (order.Unit.Type == UnitType.Army && order.Location.Type == LocationType.Land)
|
||||||
|| (order.Unit.Type == UnitType.Fleet && world.Map.GetLocation(order.Location).Type == LocationType.Water),
|
|| (order.Unit.Type == UnitType.Fleet && order.Location.Type == LocationType.Water),
|
||||||
ValidationReason.IllegalDestinationType,
|
ValidationReason.IllegalDestinationType,
|
||||||
ref moveOrders,
|
ref moveOrders,
|
||||||
ref validationResults);
|
ref validationResults);
|
||||||
|
|
||||||
// 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 == order.Unit.Location && order.Season == order.Unit.Season),
|
order => !(order.Location.Key == order.Unit.Location && order.Season == order.Unit.Season),
|
||||||
ValidationReason.DestinationMatchesOrigin,
|
ValidationReason.DestinationMatchesOrigin,
|
||||||
ref moveOrders,
|
ref moveOrders,
|
||||||
ref validationResults);
|
ref validationResults);
|
||||||
|
@ -92,7 +90,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
ILookup<bool, MoveOrder> moveOrdersByAdjacency = moveOrders
|
ILookup<bool, MoveOrder> moveOrdersByAdjacency = moveOrders
|
||||||
.ToLookup(order =>
|
.ToLookup(order =>
|
||||||
// Map adjacency
|
// Map adjacency
|
||||||
world.Map.GetLocation(order.Unit).Adjacents.Select(loc => loc.Key).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 - order.Season.Turn) <= 1
|
||||||
// Timeline adjacency
|
// Timeline adjacency
|
||||||
|
@ -341,7 +339,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
Season moveSeason = doesMove.Order.Season;
|
Season moveSeason = doesMove.Order.Season;
|
||||||
if (doesMove.Outcome == true && createdFutures.TryGetValue(moveSeason, out Season future))
|
if (doesMove.Outcome == true && createdFutures.TryGetValue(moveSeason, out Season future))
|
||||||
{
|
{
|
||||||
Unit next = doesMove.Order.Unit.Next(doesMove.Order.Location, future);
|
Unit next = doesMove.Order.Unit.Next(doesMove.Order.Location.Key, future);
|
||||||
logger.Log(3, "Advancing unit to {0}", next);
|
logger.Log(3, "Advancing unit to {0}", next);
|
||||||
createdUnits.Add(next);
|
createdUnits.Add(next);
|
||||||
}
|
}
|
||||||
|
@ -620,10 +618,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
|
|
||||||
if (!potentialDislodger)
|
if (!potentialDislodger)
|
||||||
{
|
{
|
||||||
string reason = decision.Incoming.Count == 0
|
progress |= LoggedUpdate(decision, false, depth, "No invader can move");
|
||||||
? "No unit is attacking"
|
|
||||||
: "All attacks failed";
|
|
||||||
progress |= LoggedUpdate(decision, false, depth, reason);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return progress;
|
return progress;
|
||||||
|
@ -640,7 +635,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
|
|
||||||
// If the origin and destination are adjacent, then there is a path.
|
// If the origin and destination are adjacent, then there is a path.
|
||||||
if (// Map adjacency
|
if (// Map adjacency
|
||||||
world.Map.GetLocation(decision.Order.Unit).Adjacents.Select(loc => loc.Key).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 - decision.Order.Season.Turn) <= 1
|
||||||
// Timeline adjacency
|
// Timeline adjacency
|
||||||
|
@ -755,7 +750,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
if (givesSupport.Outcome == true) min += 1;
|
if (givesSupport.Outcome == true) min += 1;
|
||||||
if (givesSupport.Outcome != false) max += 1;
|
if (givesSupport.Outcome != false) max += 1;
|
||||||
}
|
}
|
||||||
progress |= LoggedUpdate(decision, min, max, depth, $"Updated based on {decision.Supports.Count} hold supports");
|
progress |= LoggedUpdate(decision, min, max, depth, "Updated based on unit's supports");
|
||||||
return progress;
|
return progress;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -781,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
|
// 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[(SplitKey(decision.Order.Location).province, decision.Order.Season.Key)].Order;
|
UnitOrder? destOrder = decisions.HoldStrength[(decision.Order.Province, decision.Order.Season.Key)].Order;
|
||||||
DoesMove? destMoveAway = destOrder is MoveOrder moveAway
|
DoesMove? destMoveAway = destOrder is MoveOrder moveAway
|
||||||
? decisions.DoesMove[moveAway]
|
? decisions.DoesMove[moveAway]
|
||||||
: null;
|
: null;
|
||||||
|
@ -791,7 +786,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
}
|
}
|
||||||
if (// In any case here, there will have to be a unit at the destination with an order,
|
if (// In any case here, there will have to be a unit at the destination with an order,
|
||||||
// which means that destOrder will have to be populated. Including this in the if
|
// which means that destOrder will have to be populated. Including this in the if
|
||||||
// condition lets the compiler know it won't be null in the if block.
|
//condition lets the compiler know it won't be null in the if block.
|
||||||
destOrder != null
|
destOrder != null
|
||||||
&& (// Is head to head
|
&& (// Is head to head
|
||||||
decision.OpposingMove != null
|
decision.OpposingMove != null
|
||||||
|
@ -820,7 +815,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
if (givesSupport.Outcome == true) min += 1;
|
if (givesSupport.Outcome == true) min += 1;
|
||||||
if (givesSupport.Outcome != false) max += 1;
|
if (givesSupport.Outcome != false) max += 1;
|
||||||
}
|
}
|
||||||
progress |= LoggedUpdate(decision, min, max, depth, $"Updated with {decision.Supports.Count} (?) move supports from third parties");
|
progress |= LoggedUpdate(decision, min, max, depth, "Updated with supports from other powers");
|
||||||
return progress;
|
return progress;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -842,7 +837,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
}
|
}
|
||||||
// Force min to zero in case of an attempt to disloge a unit of the same power.
|
// Force min to zero in case of an attempt to disloge a unit of the same power.
|
||||||
if (decision.Order.Unit.Power == destPower) min = 0;
|
if (decision.Order.Unit.Power == destPower) min = 0;
|
||||||
progress |= LoggedUpdate(decision, min, max, depth, $"Updated with {decision.Supports.Count} (?) move supports");
|
progress |= LoggedUpdate(decision, min, max, depth, "Updated with supports");
|
||||||
return progress;
|
return progress;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -858,7 +853,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
if (givesSupport.Outcome == true) min += 1;
|
if (givesSupport.Outcome == true) min += 1;
|
||||||
if (givesSupport.Outcome != false) max += 1;
|
if (givesSupport.Outcome != false) max += 1;
|
||||||
}
|
}
|
||||||
progress |= LoggedUpdate(decision, min, max, depth, $"Updated with {decision.Supports.Count} move supports from all powers");
|
progress |= LoggedUpdate(decision, min, max, depth, "Updated with supports from all powers");
|
||||||
return progress;
|
return progress;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -883,7 +878,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
if (givesSupport.Outcome == true) min += 1;
|
if (givesSupport.Outcome == true) min += 1;
|
||||||
if (givesSupport.Outcome != false) max += 1;
|
if (givesSupport.Outcome != false) max += 1;
|
||||||
}
|
}
|
||||||
progress |= LoggedUpdate(decision, min, max, depth, $"Updated based on {decision.Supports.Count} supports");
|
progress |= LoggedUpdate(decision, min, max, depth, "Updated based on unit's supports");
|
||||||
|
|
||||||
return progress;
|
return progress;
|
||||||
}
|
}
|
||||||
|
@ -937,7 +932,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
min = 0;
|
min = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
progress |= LoggedUpdate(decision, min, max, depth, $"Updated based on {decision.Supports.Count} supports");
|
progress |= LoggedUpdate(decision, min, max, depth, "Updated based on unit's supports");
|
||||||
|
|
||||||
return progress;
|
return progress;
|
||||||
}
|
}
|
||||||
|
@ -960,7 +955,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[(SplitKey(decision.Order.Location).province, decision.Order.Season.Key)];
|
: decisions.HoldStrength[(decision.Order.Province, decision.Order.Season.Key)];
|
||||||
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.
|
||||||
|
@ -995,7 +990,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
decision,
|
decision,
|
||||||
attack.MinValue > defense.MaxValue && beatsAllCompetingMoves,
|
attack.MinValue > defense.MaxValue && beatsAllCompetingMoves,
|
||||||
depth,
|
depth,
|
||||||
$"Updated based on {decision.Competing.Count} competing moves");
|
"Updated based on competing moves");
|
||||||
return progress;
|
return progress;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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, world.Map.GetLocation(order.Location), order.Season);
|
=> ConvoyPathExists(world, order.Unit, order.Location, order.Season);
|
||||||
|
|
||||||
private static bool ConvoyPathExists(
|
private static bool ConvoyPathExists(
|
||||||
World world,
|
World world,
|
||||||
|
|
|
@ -53,12 +53,6 @@ public class Location
|
||||||
this.AdjacentList = new List<Location>();
|
this.AdjacentList = new List<Location>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static (string province, string location) SplitKey(string locationKey)
|
|
||||||
{
|
|
||||||
var split = locationKey.Split(['/'], 2);
|
|
||||||
return (split[0], split[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return this.Name == "land" || this.Name == "water"
|
return this.Name == "land" || this.Name == "water"
|
||||||
|
|
|
@ -10,10 +10,9 @@ namespace MultiversalDiplomacy.Model;
|
||||||
public struct Season(string timeline, int turn)
|
public struct Season(string timeline, int turn)
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The root season of every game. This is defined to avoid any confusion about what the first turn or timeline
|
/// The first turn number. This is defined to reduce confusion about whether the first turn is 0 or 1.
|
||||||
/// should be or what season to use to key into a fresh <see cref="Timelines"/>.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly Season First = new(Timelines.IntToString(0), 0);
|
public const int FIRST_TURN = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The timeline to which this season belongs.
|
/// The timeline to which this season belongs.
|
||||||
|
|
|
@ -75,7 +75,10 @@ public class Timelines(int next, Dictionary<string, Season?> pasts)
|
||||||
/// Create a new multiverse with an initial season.
|
/// Create a new multiverse with an initial season.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static Timelines Create()
|
public static Timelines Create()
|
||||||
=> new(StringToInt(Season.First.Timeline) + 1, new() { {Season.First.Key, null} });
|
{
|
||||||
|
Season first = new(IntToString(0), Season.FIRST_TURN);
|
||||||
|
return new Timelines(1, new() { {first.Key, null} });
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a continuation of a season if it has no futures, otherwise create a fork.
|
/// Create a continuation of a season if it has no futures, otherwise create a fork.
|
||||||
|
@ -116,6 +119,7 @@ public class Timelines(int next, Dictionary<string, Season?> pasts)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Season GetTimelineRoot(Season season)
|
public Season GetTimelineRoot(Season season)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine($"GetTimelineRoot({season.Key})");
|
||||||
return Pasts[season.Key] is Season past && season.Timeline == past.Timeline
|
return Pasts[season.Key] is Season past && season.Timeline == past.Timeline
|
||||||
? GetTimelineRoot(past)
|
? GetTimelineRoot(past)
|
||||||
: season;
|
: season;
|
||||||
|
|
|
@ -181,7 +181,7 @@ public class World
|
||||||
: splits.Length == 3
|
: splits.Length == 3
|
||||||
? Map.GetWater(splits[2])
|
? Map.GetWater(splits[2])
|
||||||
: Map.GetWater(splits[2], splits[3]);
|
: Map.GetWater(splits[2], splits[3]);
|
||||||
Unit unit = Unit.Build(location.Key, Season.First, power, type);
|
Unit unit = Unit.Build(location.Key, new("a0"), power, type);
|
||||||
return unit;
|
return unit;
|
||||||
});
|
});
|
||||||
return this.Update(units: units);
|
return this.Update(units: units);
|
||||||
|
@ -229,7 +229,7 @@ public class World
|
||||||
public Unit GetUnitAt(string provinceName, Season? season = null)
|
public Unit GetUnitAt(string provinceName, Season? season = null)
|
||||||
{
|
{
|
||||||
Province province = Map.GetProvince(provinceName);
|
Province province = Map.GetProvince(provinceName);
|
||||||
season ??= Season.First;
|
season ??= new("a0");
|
||||||
Unit? foundUnit = this.Units.SingleOrDefault(
|
Unit? foundUnit = this.Units.SingleOrDefault(
|
||||||
u => Map.GetLocation(u!).Province == province && u!.Season == season,
|
u => Map.GetLocation(u!).Province == province && u!.Season == season,
|
||||||
null)
|
null)
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
using MultiversalDiplomacy.Model;
|
using MultiversalDiplomacy.Model;
|
||||||
|
|
||||||
using static MultiversalDiplomacy.Model.Location;
|
|
||||||
|
|
||||||
namespace MultiversalDiplomacy.Orders;
|
namespace MultiversalDiplomacy.Orders;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -17,9 +15,14 @@ public class MoveOrder : UnitOrder
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The destination location to which the unit should move.
|
/// The destination location to which the unit should move.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Location { get; }
|
public Location Location { get; }
|
||||||
|
|
||||||
public MoveOrder(string power, Unit unit, Season season, string location)
|
/// <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)
|
: base (power, unit)
|
||||||
{
|
{
|
||||||
this.Season = season;
|
this.Season = season;
|
||||||
|
@ -28,6 +31,14 @@ public class MoveOrder : UnitOrder
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{this.Unit} -> {Season.Timeline}-{SplitKey(Location).province}@{Season.Turn}";
|
return $"{this.Unit} -> {Season.Timeline}-{Province}@{Season.Turn}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns whether another move order has the same destination as this order.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsCompeting(MoveOrder other)
|
||||||
|
=> this != other
|
||||||
|
&& this.Season == other.Season
|
||||||
|
&& this.Province == other.Province;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,4 +38,9 @@ public class SupportMoveOrder : SupportOrder
|
||||||
{
|
{
|
||||||
return $"{this.Unit} S {this.Target} -> {(this.Province, this.Season).ToShort()}";
|
return $"{this.Unit} S {this.Target} -> {(this.Province, this.Season).ToShort()}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsSupportFor(MoveOrder move)
|
||||||
|
=> this.Target == move.Unit
|
||||||
|
&& this.Season == move.Season
|
||||||
|
&& this.Location == move.Location;
|
||||||
}
|
}
|
|
@ -2,9 +2,9 @@ using MultiversalDiplomacy.Model;
|
||||||
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace MultiversalDiplomacyTests;
|
namespace MultiversalDiplomacyTests.Model;
|
||||||
|
|
||||||
public class TimelinesTest
|
public class TimelineFactoryTest
|
||||||
{
|
{
|
||||||
[TestCase(0, "a")]
|
[TestCase(0, "a")]
|
||||||
[TestCase(1, "b")]
|
[TestCase(1, "b")]
|
||||||
|
@ -36,12 +36,12 @@ public class TimelinesTest
|
||||||
public void NoSharedFactoryState()
|
public void NoSharedFactoryState()
|
||||||
{
|
{
|
||||||
Timelines one = Timelines.Create()
|
Timelines one = Timelines.Create()
|
||||||
.WithNewSeason(Season.First, out var s1)
|
.WithNewSeason(new Season("a0"), out var s1)
|
||||||
.WithNewSeason(Season.First, out var s2)
|
.WithNewSeason(new Season("a0"), out var s2)
|
||||||
.WithNewSeason(Season.First, out var s3);
|
.WithNewSeason(new Season("a0"), out var s3);
|
||||||
Timelines two = Timelines.Create()
|
Timelines two = Timelines.Create()
|
||||||
.WithNewSeason(Season.First, out var s4)
|
.WithNewSeason(new Season("a0"), out var s4)
|
||||||
.WithNewSeason(Season.First, out var s5);
|
.WithNewSeason(new Season("a0"), out var s5);
|
||||||
|
|
||||||
Assert.That(s1.Timeline, Is.EqualTo("a"));
|
Assert.That(s1.Timeline, Is.EqualTo("a"));
|
||||||
Assert.That(s2.Timeline, Is.EqualTo("b"));
|
Assert.That(s2.Timeline, Is.EqualTo("b"));
|
||||||
|
@ -54,14 +54,14 @@ public class TimelinesTest
|
||||||
public void TimelineForking()
|
public void TimelineForking()
|
||||||
{
|
{
|
||||||
Timelines timelines = Timelines.Create()
|
Timelines timelines = Timelines.Create()
|
||||||
.WithNewSeason(Season.First, out var a1)
|
.WithNewSeason("a0", out var a1)
|
||||||
.WithNewSeason(a1, out var a2)
|
.WithNewSeason(a1, out var a2)
|
||||||
.WithNewSeason(a2, out var a3)
|
.WithNewSeason(a2, out var a3)
|
||||||
.WithNewSeason(a1, out var b2)
|
.WithNewSeason(a1, out var b2)
|
||||||
.WithNewSeason(b2, out var b3)
|
.WithNewSeason(b2, out var b3)
|
||||||
.WithNewSeason(a1, out var c2)
|
.WithNewSeason(a1, out var c2)
|
||||||
.WithNewSeason(a2, out var d3);
|
.WithNewSeason(a2, out var d3);
|
||||||
Season a0 = Season.First;
|
Season a0 = new("a0");
|
||||||
|
|
||||||
Assert.That(
|
Assert.That(
|
||||||
timelines.Pasts.Keys,
|
timelines.Pasts.Keys,
|
||||||
|
@ -76,13 +76,13 @@ public class TimelinesTest
|
||||||
Assert.That(c2.Timeline, Is.EqualTo("c"), "Unexpected second alt");
|
Assert.That(c2.Timeline, Is.EqualTo("c"), "Unexpected second alt");
|
||||||
Assert.That(d3.Timeline, Is.EqualTo("d"), "Unexpected third alt");
|
Assert.That(d3.Timeline, Is.EqualTo("d"), "Unexpected third alt");
|
||||||
|
|
||||||
Assert.That(a1.Turn, Is.EqualTo(Season.First.Turn + 1), "Unexpected a1 turn number");
|
Assert.That(a1.Turn, Is.EqualTo(Season.FIRST_TURN + 1), "Unexpected a1 turn number");
|
||||||
Assert.That(a2.Turn, Is.EqualTo(Season.First.Turn + 2), "Unexpected a2 turn number");
|
Assert.That(a2.Turn, Is.EqualTo(Season.FIRST_TURN + 2), "Unexpected a2 turn number");
|
||||||
Assert.That(a3.Turn, Is.EqualTo(Season.First.Turn + 3), "Unexpected a3 turn number");
|
Assert.That(a3.Turn, Is.EqualTo(Season.FIRST_TURN + 3), "Unexpected a3 turn number");
|
||||||
Assert.That(b2.Turn, Is.EqualTo(Season.First.Turn + 2), "Unexpected b2 turn number");
|
Assert.That(b2.Turn, Is.EqualTo(Season.FIRST_TURN + 2), "Unexpected b2 turn number");
|
||||||
Assert.That(b3.Turn, Is.EqualTo(Season.First.Turn + 3), "Unexpected b3 turn number");
|
Assert.That(b3.Turn, Is.EqualTo(Season.FIRST_TURN + 3), "Unexpected b3 turn number");
|
||||||
Assert.That(c2.Turn, Is.EqualTo(Season.First.Turn + 2), "Unexpected c2 turn number");
|
Assert.That(c2.Turn, Is.EqualTo(Season.FIRST_TURN + 2), "Unexpected c2 turn number");
|
||||||
Assert.That(d3.Turn, Is.EqualTo(Season.First.Turn + 3), "Unexpected d3 turn number");
|
Assert.That(d3.Turn, Is.EqualTo(Season.FIRST_TURN + 3), "Unexpected d3 turn number");
|
||||||
|
|
||||||
Assert.That(timelines.GetTimelineRoot(a0), Is.EqualTo(a0), "Expected timeline root to be reflexive");
|
Assert.That(timelines.GetTimelineRoot(a0), Is.EqualTo(a0), "Expected timeline root to be reflexive");
|
||||||
Assert.That(timelines.GetTimelineRoot(a3), Is.EqualTo(a0), "Expected trunk timeline to have root");
|
Assert.That(timelines.GetTimelineRoot(a3), Is.EqualTo(a0), "Expected trunk timeline to have root");
|
|
@ -14,31 +14,6 @@ public class SerializationTest
|
||||||
WriteIndented = true,
|
WriteIndented = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void SerializeRoundTrip_Timelines()
|
|
||||||
{
|
|
||||||
Timelines one = Timelines.Create();
|
|
||||||
|
|
||||||
string serial1 = JsonSerializer.Serialize(one, Options);
|
|
||||||
Timelines two = JsonSerializer.Deserialize<Timelines>(serial1, Options)
|
|
||||||
?? throw new AssertionException("Failed to deserialize");
|
|
||||||
|
|
||||||
Assert.That(two.Next, Is.EqualTo(one.Next), "Failed to reserialize next timeline");
|
|
||||||
Assert.That(two.Pasts, Is.EquivalentTo(one.Pasts), "Failed to reserialize pasts");
|
|
||||||
|
|
||||||
Timelines three = two
|
|
||||||
.WithNewSeason(Season.First, out var a1)
|
|
||||||
.WithNewSeason(a1, out var a2)
|
|
||||||
.WithNewSeason(a1, out var b2);
|
|
||||||
|
|
||||||
string serial2 = JsonSerializer.Serialize(three, Options);
|
|
||||||
Timelines four = JsonSerializer.Deserialize<Timelines>(serial2, Options)
|
|
||||||
?? throw new AssertionException("Failed to deserialize");
|
|
||||||
|
|
||||||
Assert.That(four.Next, Is.EqualTo(three.Next), "Failed to reserialize next timeline");
|
|
||||||
Assert.That(four.Pasts, Is.EquivalentTo(three.Pasts), "Failed to reserialize pasts");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void SerializeRoundTrip_NewGame()
|
public void SerializeRoundTrip_NewGame()
|
||||||
{
|
{
|
||||||
|
@ -90,42 +65,36 @@ public class SerializationTest
|
||||||
Assert.That(tyr0, Is.NotDislodged);
|
Assert.That(tyr0, Is.NotDislodged);
|
||||||
setup.UpdateWorld();
|
setup.UpdateWorld();
|
||||||
|
|
||||||
Assert.That(setup.World.OrderHistory[s0.Key].Orders.Count, Is.GreaterThan(0), "Missing orders");
|
Assert.That(setup.World.OrderHistory["a0"].Orders.Count, Is.GreaterThan(0), "Missing orders");
|
||||||
Assert.That(setup.World.OrderHistory[s0.Key].DoesMoveOutcomes.Count, Is.GreaterThan(0), "Missing moves");
|
Assert.That(setup.World.OrderHistory["a0"].DoesMoveOutcomes.Count, Is.GreaterThan(0), "Missing moves");
|
||||||
Assert.That(setup.World.OrderHistory[s0.Key].IsDislodgedOutcomes.Count, Is.GreaterThan(0), "Missing dislodges");
|
Assert.That(setup.World.OrderHistory["a0"].IsDislodgedOutcomes.Count, Is.GreaterThan(0), "Missing dislodges");
|
||||||
|
|
||||||
// Assert.Ignore("Serialization doesn't fully work yet");
|
|
||||||
|
|
||||||
// Serialize and deserialize the world
|
// Serialize and deserialize the world
|
||||||
string serialized = JsonSerializer.Serialize(setup.World, Options);
|
string serialized = JsonSerializer.Serialize(setup.World, Options);
|
||||||
Console.WriteLine(serialized);
|
|
||||||
World reserialized = JsonSerializer.Deserialize<World>(serialized, Options)
|
World reserialized = JsonSerializer.Deserialize<World>(serialized, Options)
|
||||||
?? throw new AssertionException("Failed to reserialize world");
|
?? throw new AssertionException("Failed to reserialize world");
|
||||||
|
|
||||||
Assert.Multiple(() => {
|
Assert.Multiple(() => {
|
||||||
Assert.That(reserialized.OrderHistory[s0.Key].Orders.Count, Is.GreaterThan(0), "Missing orders");
|
Assert.That(reserialized.OrderHistory["a0"].Orders.Count, Is.GreaterThan(0), "Missing orders");
|
||||||
Assert.That(reserialized.OrderHistory[s0.Key].DoesMoveOutcomes.Count, Is.GreaterThan(0), "Missing moves");
|
Assert.That(reserialized.OrderHistory["a0"].DoesMoveOutcomes.Count, Is.GreaterThan(0), "Missing moves");
|
||||||
Assert.That(reserialized.OrderHistory[s0.Key].IsDislodgedOutcomes.Count, Is.GreaterThan(0), "Missing dislodges");
|
Assert.That(reserialized.OrderHistory["a0"].IsDislodgedOutcomes.Count, Is.GreaterThan(0), "Missing dislodges");
|
||||||
Assert.That(reserialized.Timelines.Pasts, Is.Not.Empty, "Missing timeline history");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Assert.Ignore("Serialization doesn't fully work yet");
|
||||||
|
|
||||||
// Resume the test case
|
// Resume the test case
|
||||||
setup = new(reserialized, MovementPhaseAdjudicator.Instance);
|
setup = new(reserialized, MovementPhaseAdjudicator.Instance);
|
||||||
setup[("a", 1)]
|
setup[("a", 1)]
|
||||||
["Germany"]
|
["Germany"]
|
||||||
.Army("Mun").Supports.Army("Mun", season: s0).MoveTo("Tyr").GetReference(out var mun1)
|
.Army("Mun").Supports.Army("Mun", season: new("a0")).MoveTo("Tyr").GetReference(out var mun1)
|
||||||
["Austria"]
|
["Austria"]
|
||||||
.Army("Tyr").Holds();
|
.Army("Tyr").Holds();
|
||||||
|
|
||||||
setup.ValidateOrders();
|
setup.ValidateOrders();
|
||||||
Assert.That(mun1, Is.Valid);
|
Assert.That(mun1, Is.Valid);
|
||||||
var adjudications = setup.AdjudicateOrders();
|
var adjudications = setup.AdjudicateOrders();
|
||||||
foreach (var adj in adjudications)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"{adj}");
|
|
||||||
}
|
|
||||||
|
|
||||||
Assert.That(mun1, Is.NotCut);
|
Assert.That(mun1, Is.NotCut);
|
||||||
|
Console.WriteLine(string.Join(", ", adjudications.Select(a => a.ToString())));
|
||||||
DoesMove mun0move = adjudications.OfType<DoesMove>().Single(move => move.Order.Unit.Key == mun0.Order.Unit.Key);
|
DoesMove mun0move = adjudications.OfType<DoesMove>().Single(move => move.Order.Unit.Key == mun0.Order.Unit.Key);
|
||||||
Assert.That(mun0move.Outcome, Is.True);
|
Assert.That(mun0move.Outcome, Is.True);
|
||||||
IsDislodged tyr0dislodge = adjudications.OfType<IsDislodged>().Single(dis => dis.Order.Unit.Key == tyr0.Order.Unit.Key);
|
IsDislodged tyr0dislodge = adjudications.OfType<IsDislodged>().Single(dis => dis.Order.Unit.Key == tyr0.Order.Unit.Key);
|
||||||
|
|
|
@ -423,7 +423,7 @@ public class TestCaseBuilder
|
||||||
this.PowerContext.Power,
|
this.PowerContext.Power,
|
||||||
this.Unit,
|
this.Unit,
|
||||||
destSeason,
|
destSeason,
|
||||||
destination.Key);
|
destination);
|
||||||
this.Builder.OrderList.Add(moveOrder);
|
this.Builder.OrderList.Add(moveOrder);
|
||||||
return new OrderDefinedContext<MoveOrder>(this, moveOrder);
|
return new OrderDefinedContext<MoveOrder>(this, moveOrder);
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ class TestCaseBuilderTest
|
||||||
Assert.That(orderBer, Is.InstanceOf<MoveOrder>(), "Unexpected order type");
|
Assert.That(orderBer, Is.InstanceOf<MoveOrder>(), "Unexpected order type");
|
||||||
Assert.That(
|
Assert.That(
|
||||||
(orderBer as MoveOrder)?.Location,
|
(orderBer as MoveOrder)?.Location,
|
||||||
Is.EqualTo(setup.World.Map.GetLand("Kiel").Key),
|
Is.EqualTo(setup.World.Map.GetLand("Kiel")),
|
||||||
"Unexpected move order destination");
|
"Unexpected move order destination");
|
||||||
|
|
||||||
UnitOrder orderPru = orders.Single(OrderForProvince("Prussia"));
|
UnitOrder orderPru = orders.Single(OrderForProvince("Prussia"));
|
||||||
|
|
|
@ -13,7 +13,7 @@ public class UnitTests
|
||||||
Location Mun = world.Map.GetLand("Mun"),
|
Location Mun = world.Map.GetLand("Mun"),
|
||||||
Boh = world.Map.GetLand("Boh"),
|
Boh = world.Map.GetLand("Boh"),
|
||||||
Tyr = world.Map.GetLand("Tyr");
|
Tyr = world.Map.GetLand("Tyr");
|
||||||
Season a0 = Season.First;
|
Season a0 = new("a0");
|
||||||
Unit u1 = Unit.Build(Mun.Key, a0, "Austria", UnitType.Army);
|
Unit u1 = Unit.Build(Mun.Key, a0, "Austria", UnitType.Army);
|
||||||
|
|
||||||
world = world.WithNewSeason(a0, out Season a1);
|
world = world.WithNewSeason(a0, out Season a1);
|
||||||
|
|
Loading…
Reference in New Issue