The region harness flies the seeded legs through RegionClock.Advance
EconomyRegion no longer parks the haulers or drives zones with its own AdvanceTo loop: each tick calls RegionClock.Advance(galaxy, null, time). The report counts legs and haulers; an idle recipe's missing input reads as a cross-faction leg (region-cross-faction-legs) or a lost hauler, and the 'no cargo moves' line is gone. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c1890739e4
commit
1e94983377
2 changed files with 78 additions and 25 deletions
|
|
@ -90,17 +90,18 @@ public sealed class EconomyRegionTests
|
|||
|
||||
|
||||
// The rigs and skimmers of the region are facilities with recipes of their own: with the ground worked, an idle refinery's cause is the
|
||||
// ore that no haul leg brings it, and the report says extraction runs.
|
||||
// ore only another faction makes or whose leg's hauler is lost, never "no haul leg": legs are seeded and fly. The report says extraction runs.
|
||||
[Fact]
|
||||
public void ExtractionRunsAndTheIdleCauseIsTheHaulLeg()
|
||||
public void ExtractionRunsAndTheIdleCauseIsACrossFactionLegOrALostHauler()
|
||||
{
|
||||
var sample = EconomyRegion.Run(Root, 1, 0.05);
|
||||
var sample = EconomyRegion.Run(Root, 1, EconomyRegion.DefaultHours);
|
||||
Assert.True(sample.Extractors > 0);
|
||||
Assert.True(sample.ExtractorsRunning > 0, "no rig or skimmer started a cycle");
|
||||
Assert.False(sample.NoExtraction);
|
||||
var idle = EconomyRegion.Report(new[] { sample }).Where(fault => fault.Invariant == EconomyRegion.HIdle).Select(fault => fault.Message).ToList();
|
||||
Assert.NotEmpty(idle);
|
||||
Assert.Contains(idle, message => message.Contains("whose recipe ran but whose units are not held where this one is made: no haul leg"));
|
||||
Assert.Contains(idle, message => message.Contains("a cross-faction leg (region-cross-faction-legs)") || message.Contains("leg's hauler is lost"));
|
||||
Assert.All(idle, message => Assert.DoesNotContain("no haul leg", message));
|
||||
Assert.All(idle, message => Assert.DoesNotContain("no extraction runs", message));
|
||||
Assert.All(idle, message => Assert.DoesNotContain("moves no cargo", message));
|
||||
var text = new StringWriter();
|
||||
|
|
@ -156,16 +157,48 @@ public sealed class EconomyRegionTests
|
|||
Assert.DoesNotContain("haul leg", message);
|
||||
}
|
||||
|
||||
// A missing input no recipe makes, with extraction running, is plain: nothing in the region makes it.
|
||||
[Fact]
|
||||
public void RawOreMissingWithExtractionRunningNamesTheHaulLeg()
|
||||
public void RawOreNoRecipeMakesIsNamedWithExtractionRunning()
|
||||
{
|
||||
var sample = Sample(1, Recipe("Iron", Stall.Inputs, 60, "Iron Ore"));
|
||||
Assert.False(sample.NoExtraction);
|
||||
var message = Message(sample, "Iron");
|
||||
Assert.Contains("no haul leg brings from outside", message);
|
||||
Assert.Contains("Iron Ore, which no recipe in the region makes", message);
|
||||
Assert.DoesNotContain("no extraction runs", message);
|
||||
Assert.DoesNotContain("haul leg", message);
|
||||
}
|
||||
|
||||
private static RegionStation Station(string faction, bool starved, params string[] outputs)
|
||||
{
|
||||
var station = new RegionStation { Faction = faction };
|
||||
var facility = new RegionFacility { Name = "Works", Outputs = outputs.ToList() };
|
||||
if (starved) facility.Stalls[Stall.Inputs] = 1;
|
||||
station.Facilities.Add(facility);
|
||||
return station;
|
||||
}
|
||||
|
||||
// A missing input made only by another faction is a cross-faction leg, which waits (region-cross-faction-legs); one made by the
|
||||
// consumer's own faction whose seeded leg lost its hauler says so; one made by its own faction with the hauler flying is just not held yet.
|
||||
[Fact]
|
||||
public void AMissingInputNamesACrossFactionLegOrALostHauler()
|
||||
{
|
||||
RegionSample Built(string makerFaction, bool lost)
|
||||
{
|
||||
var sample = Sample(1, Recipe("Iron", Stall.Inputs, 60, "Iron Ore"), new RegionRecipe { Output = "Iron Ore", Stations = 1, Made = 5 });
|
||||
sample.Stations.Add(Station("Pirates", true, "Iron"));
|
||||
sample.Stations.Add(Station(makerFaction, false, "Iron Ore"));
|
||||
if (lost) sample.LostGoods.Add("Iron Ore");
|
||||
return sample;
|
||||
}
|
||||
var cross = Message(Built("Zhestokost", false), "Iron");
|
||||
Assert.Contains("Iron Ore, made only by Zhestokost: a cross-faction leg (region-cross-faction-legs)", cross);
|
||||
Assert.Contains("hauler is lost", Message(Built("Pirates", true), "Iron"));
|
||||
var flying = Message(Built("Pirates", false), "Iron");
|
||||
Assert.Contains("whose recipe ran but whose units are not held where this one is made", flying);
|
||||
Assert.DoesNotContain("lost", flying);
|
||||
Assert.DoesNotContain("cross-faction", flying);
|
||||
}
|
||||
// A rig stalls as a whole, but a raw recipe the ground under it holds none of is Barren whatever the rig reads (Room once its bays fill):
|
||||
// an ore no belt of the region holds is no fault of the chain.
|
||||
[Fact]
|
||||
|
|
@ -218,7 +251,8 @@ public sealed class EconomyRegionTests
|
|||
Assert.DoesNotContain("extraction", idle);
|
||||
steel.Made = 5;
|
||||
var ran = Message(Sample(0, ammo, steel), "Ammo");
|
||||
Assert.Contains("Steel, whose recipe ran but whose units are not held where this one is made: no haul leg", ran);
|
||||
Assert.Contains("Steel, whose recipe ran but whose units are not held where this one is made", ran);
|
||||
Assert.DoesNotContain("haul leg", ran);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -242,12 +276,15 @@ public sealed class EconomyRegionTests
|
|||
Assert.DoesNotContain("not a multiple", hexamine);
|
||||
}
|
||||
[Fact]
|
||||
public void PrintNamesTheRegionAndWhatItDoesNotMove()
|
||||
public void PrintNamesTheRegionAndItsLegs()
|
||||
{
|
||||
var sample = EconomyRegion.Run(Root, 1, 0.05);
|
||||
var text = new StringWriter();
|
||||
EconomyRegion.Print(sample, text);
|
||||
Assert.Contains("Region, seed 1 (", text.ToString());
|
||||
Assert.Contains("no cargo moves between stations", text.ToString());
|
||||
Assert.Contains($"{sample.Legs} seeded legs, {sample.Haulers} haulers flying an order", text.ToString());
|
||||
Assert.True(sample.Legs > 0 && sample.Haulers >= sample.Legs);
|
||||
Assert.DoesNotContain("no cargo moves", text.ToString());
|
||||
Assert.DoesNotContain("hauler parked", text.ToString());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ using System.Linq;
|
|||
using GameCult.Caching;
|
||||
|
||||
// What the demo's whole region does with simulation time, on the path the game ships (ruling demo-chain-spans-the-region): the demo
|
||||
// region is booted as a run boots it (every zone generated and live), the hauler parked, and every zone, the entrance included, is
|
||||
// advanced with Zone.AdvanceTo at each multiple of RegionClock.Span up to the horizon. No zone steps and no player flies; the harness
|
||||
// drives RegionClock's off-screen step and reads what it left. Measurement only: it reads a booted scratch copy of the catalog and
|
||||
// writes none.
|
||||
// region is booted as a run boots it (every zone generated and live, its haul legs seeded), and RegionClock.Advance brings every zone,
|
||||
// the entrance included, to each multiple of RegionClock.Span up to the horizon: facilities run and the haulers fly their seeded legs. No
|
||||
// zone steps and no player flies; the harness drives RegionClock's off-screen step and reads what it left. Measurement only: it reads a
|
||||
// booted scratch copy of the catalog and writes none.
|
||||
//
|
||||
// The region view moves no cargo between stations (haul legs are region-haul-legs), so a station that needs a good it does not hold
|
||||
// stalls Inputs, and the report says so instead of hiding it.
|
||||
// A good only another faction makes has no leg (region-cross-faction-legs), so a station that needs one stalls Inputs, and the report says
|
||||
// so instead of hiding it.
|
||||
|
||||
// One facility of a station: the Stall it ended each span in, counted.
|
||||
public sealed class RegionFacility
|
||||
|
|
@ -67,7 +67,9 @@ public sealed class RegionSample
|
|||
public uint Seed;
|
||||
public double Hours;
|
||||
public int Zones, Spans;
|
||||
public int Parked;
|
||||
// The haul orders RegionLegs seeded, the ships carrying an order at the horizon, and the goods of seeded orders no ship carries any more.
|
||||
public int Legs, Haulers;
|
||||
public HashSet<string> LostGoods = new HashSet<string>(StringComparer.Ordinal);
|
||||
public List<RegionKind> Kinds = new List<RegionKind>();
|
||||
public List<RegionStation> Stations = new List<RegionStation>();
|
||||
public List<RegionRecipe> Recipes = new List<RegionRecipe>();
|
||||
|
|
@ -91,7 +93,7 @@ public static class EconomyRegion
|
|||
if (!double.IsFinite(hours) || hours <= 0) throw new ArgumentOutOfRangeException(nameof(hours), "the horizon must be a positive, finite number of sim hours");
|
||||
using var demo = EconomyLoop.Boot(root, seed, region: true);
|
||||
var catalog = demo.Cache;
|
||||
var sample = new RegionSample { Seed = seed, Hours = hours, Parked = demo.ParkHaulers() };
|
||||
var sample = new RegionSample { Seed = seed, Hours = hours };
|
||||
beforeRun?.Invoke(demo);
|
||||
var galaxy = demo.Galaxy;
|
||||
var zones = galaxy.Zones.Where(zone => zone.Contents != null).ToArray();
|
||||
|
|
@ -141,7 +143,7 @@ public static class EconomyRegion
|
|||
for (var tick = 1; tick <= ticks; tick++)
|
||||
{
|
||||
var time = tick * RegionClock.Span;
|
||||
foreach (var zone in zones) zone.Contents.AdvanceTo(time);
|
||||
RegionClock.Advance(galaxy, null, time);
|
||||
for (var s = 0; s < tracked.Count; s++)
|
||||
{
|
||||
var (station, entity, facilities, outputs) = tracked[s];
|
||||
|
|
@ -163,6 +165,13 @@ public static class EconomyRegion
|
|||
}
|
||||
}
|
||||
sample.Spans = ticks;
|
||||
var legs = catalog.GetAll<HaulOrderData>().Where(order => order.Commitment == RegionLegs.Commitment).ToArray();
|
||||
var carriers = galaxy.Zones.SelectMany(zone => zone.Contents.Entities.OfType<Ship>()).Where(ship => ship.Haul.Key.IsSet())
|
||||
.Select(ship => HaulRun.OrderOf(demo.Items, ship.Haul.Key)).Where(order => order != null).Select(order => (order.From.Key, order.To.Key)).ToHashSet();
|
||||
sample.Legs = legs.Length;
|
||||
sample.Haulers = carriers.Count;
|
||||
foreach (var leg in legs.Where(order => !carriers.Contains((order.From.Key, order.To.Key))))
|
||||
foreach (var good in leg.Goods) sample.LostGoods.Add(Good(good.Key));
|
||||
for (var s = 0; s < tracked.Count; s++)
|
||||
{
|
||||
var hold = new EntityHold(tracked[s].entity);
|
||||
|
|
@ -253,27 +262,34 @@ public static class EconomyRegion
|
|||
if (recipe.Final.ContainsKey(Stall.Barren)) return ends + ": the ground it sits on holds none of its good.";
|
||||
var missing = recipe.Draws.Where(draw => !draw.Value).Select(draw => draw.Key).ToList();
|
||||
if (missing.Count == 0) return ends + ": it holds some of every input, but not a cycle's quantity of one.";
|
||||
return ends + ": missing " + string.Join("; ", missing.Select(good => Upstream(sample, good))) + ".";
|
||||
return ends + ": missing " + string.Join("; ", missing.Select(good => Upstream(sample, recipe, good))) + ".";
|
||||
}
|
||||
|
||||
// One missing input: what in the region makes it, and why that did not deliver.
|
||||
private static string Upstream(RegionSample sample, string good)
|
||||
// One missing input: what in the region makes it, and why that did not deliver to the faction that needs it.
|
||||
private static string Upstream(RegionSample sample, RegionRecipe consumer, string good)
|
||||
{
|
||||
var maker = sample.Recipes.FirstOrDefault(recipe => recipe.Output == good);
|
||||
if (maker == null)
|
||||
return sample.NoExtraction
|
||||
? $"{good}, which no recipe in the region makes and no extraction runs to supply"
|
||||
: $"{good}, which no recipe in the region makes and no haul leg brings from outside (region-haul-legs)";
|
||||
: $"{good}, which no recipe in the region makes";
|
||||
var makers = FactionsMaking(sample, good);
|
||||
if (makers.Count > 0 && FactionsMaking(sample, consumer.Output, starved: true).Any(faction => !makers.Contains(faction)))
|
||||
return $"{good}, made only by {string.Join(", ", makers)}: a cross-faction leg (region-cross-faction-legs)";
|
||||
if (sample.LostGoods.Contains(good)) return $"{good}, whose leg's hauler is lost";
|
||||
return maker.Ran
|
||||
? $"{good}, whose recipe ran but whose units are not held where this one is made: no haul leg moves them (region-haul-legs)"
|
||||
? $"{good}, whose recipe ran but whose units are not held where this one is made"
|
||||
: $"{good}, whose recipe is itself idle";
|
||||
}
|
||||
|
||||
// The factions of the stations whose facilities make the output (starved: only those that stalled on Inputs at some span).
|
||||
private static SortedSet<string> FactionsMaking(RegionSample sample, string output, bool starved = false) =>
|
||||
new SortedSet<string>(sample.Stations.Where(station => station.Facilities.Any(facility => facility.Outputs.Contains(output) && (!starved || facility.Stalls.ContainsKey(Stall.Inputs)))).Select(station => station.Faction), StringComparer.Ordinal);
|
||||
|
||||
public static void Print(RegionSample sample, TextWriter output)
|
||||
{
|
||||
var inv = CultureInfo.InvariantCulture;
|
||||
output.WriteLine(string.Format(inv, "\nRegion, seed {0} ({1} zones advanced to {2:0.##} sim h in {3} spans of {4:0} s by Zone.AdvanceTo; no zone steps, no player flies; hauler parked: {5})", sample.Seed, sample.Zones, sample.Hours, sample.Spans, RegionClock.Span, sample.Parked));
|
||||
output.WriteLine(" no cargo moves between stations in this view (region-haul-legs)");
|
||||
output.WriteLine(string.Format(inv, "\nRegion, seed {0} ({1} zones advanced to {2:0.##} sim h in {3} spans of {4:0} s by RegionClock.Advance; no zone steps, no player flies; {5} seeded legs, {6} haulers flying an order)", sample.Seed, sample.Zones, sample.Hours, sample.Spans, RegionClock.Span, sample.Legs, sample.Haulers));
|
||||
output.WriteLine(sample.NoExtraction
|
||||
? $" no extraction runs in the region: every downstream recipe starves ({sample.Extractors} extraction facilities, none running)"
|
||||
: $" extraction runs in {sample.ExtractorsRunning} of {sample.Extractors} extraction facilities");
|
||||
|
|
|
|||
Loading…
Reference in a new issue