Tests: belts keep a spacing from their neighbours; story turrets at 3, 5 and 9; a station never sits on a binary's bodyless node

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-17 05:56:58 +02:00
commit b305c66c6c
2 changed files with 46 additions and 11 deletions

View file

@ -302,6 +302,13 @@ public sealed class ChildrenWithinReachTests : IClassFixture<ChildrenWithinReach
Assert.True(inner > 0f, $"seed {seed}: an asteroid sits at {inner}");
if (mass.TryGetValue(parent, out var m))
Assert.True(inner >= RocheMargin * Roche(zone, m) * (1 - Tolerance), $"seed {seed}: a belt's inner edge {inner} is inside its parent's Roche margin");
// The belt keeps clear of its neighbours' rails by a sibling spacing (rule 3), inner and outer.
var sibling = ChildrenOf(zone, parent, Placed(zone));
var at = sibling.IndexOf(orbit);
if (at > 0)
Assert.True(inner >= DistanceOf(zone, sibling[at - 1]) * (1 / (1 - GravityField.Reach / 2)) * (1 - Tolerance), $"seed {seed}: a belt reaches in to {inner}, within a spacing of its inner neighbour");
if (at < sibling.Count - 1)
Assert.True(outermost <= DistanceOf(zone, sibling[at + 1]) * (1 - GravityField.Reach / 2) * (1 + Tolerance), $"seed {seed}: a belt reaches out to {outermost}, within a spacing of its outer neighbour");
if (zone.Orbits[parent].Data.Parent.IsSet())
Assert.True(outermost <= GravityField.Gamma * GravityField.Reach * DistanceOf(zone, parent) / Math.Max(GravityField.Beta, 1 + GravityField.Reach) * (1 + Tolerance),
$"seed {seed}: a belt reaches {outermost}, past its parent's window");

View file

@ -29,7 +29,8 @@ public sealed class StationPlacementTests : IDisposable
// stock may rearrange the catalog before a galaxy is generated; storyTurrets > 0 gives every zone a story station that
// authors that many turrets (the '#turrets' tag), the way a narrative does.
private IEnumerable<Built> GeneratedZones(Action<ItemManager> stock = null, int storyTurrets = 0, uint seeds = 6, int zonesPerSeed = int.MaxValue)
private IEnumerable<Built> GeneratedZones(Action<ItemManager> stock = null, int storyTurrets = 0, uint seeds = 6, int zonesPerSeed = int.MaxValue,
Action<ZoneGenerationSettings> tune = null)
{
for (uint seed = 1; seed <= seeds; seed++)
{
@ -53,7 +54,9 @@ public sealed class StationPlacementTests : IDisposable
{
if (storyTurrets > 0)
galaxyZone.Locations.Add(new LocationStory { Zone = galaxyZone, Name = "Test station", Faction = galaxy.Factions[0], Type = LocationType.Station, Turrets = storyTurrets });
var pack = ZoneGenerator.GenerateZone(items, authored.Read<ZoneGenerationSettings>("ZoneSettings"), authored.Read<PlanetSettings>("PlanetSettings"), galaxy, galaxyZone,
var zoneSettings = authored.Read<ZoneGenerationSettings>("ZoneSettings");
tune?.Invoke(zoneSettings);
var pack = ZoneGenerator.GenerateZone(items, zoneSettings, authored.Read<PlanetSettings>("PlanetSettings"), galaxy, galaxyZone,
galaxyZone == galaxy.Entrance && galaxy.IsPrelude, true);
var zone = new Zone(items, authored.Read<PlanetSettings>("PlanetSettings"), pack, galaxyZone, galaxy);
zone.Update(.02f);
@ -122,7 +125,31 @@ public sealed class StationPlacementTests : IDisposable
Assert.True(ahead > 0 && behind > 0, $"the seeds put stations on one side only (ahead {ahead}, behind {behind})");
}
// How far a body keeps others out: its family's support, or 1.5 Roche limits (tail-taming-law-r3-band-loose-cusp) if more.
// A binary is a bodyless node under its parent; the station's source is never such a node, however many binaries there are.
[Fact]
public void AStationNeverSitsOnABinarysBodylessNode()
{
var binaries = 0;
var stations = 0;
foreach (var built in GeneratedZones(null, 0, 4, int.MaxValue, z => { z.SatelliteCreationProbability = 1; z.BinaryCreationProbability = 1; }))
{
var zone = built.Zone;
var bodyOrbits = zone.Planets.Values.Select(b => b.Orbit.Key).ToHashSet();
binaries += zone.Orbits.Count(o => o.Value.Data.Parent.IsSet() && !bodyOrbits.Contains(o.Key) && zone.Wells.Reach(o.Key) > 0f);
var ridden = zone.Entities.OfType<OrbitalEntity>().Select(e => e.OrbitData).ToHashSet();
foreach (var station in Orbitals(built).Where(e => TypeOf(built.Items, e) == HullType.Station))
{
var orbit = zone.Orbits[station.OrbitData];
var sources = zone.Orbits.Where(o => !ridden.Contains(o.Key) && SameRing(o.Value, orbit)).ToList();
if (sources.Count == 0) continue; // the tutorial entrance's own orbit round a root
stations++;
Assert.Contains(bodyOrbits, key => key.Equals(sources[0].Key));
}
}
Assert.True(binaries > 5 && stations > 5, $"{binaries} bodyless nodes and {stations} stations: the seeds do not exercise the rule");
}
// How far a body keeps others out: its family's support, or 1.5 Roche limits (tail-taming-law-r3-band-loose-cusp) if more.
private static float BaseExtent(Zone zone, CultRecordKey orbit)
{
var body = zone.Planets.Values.FirstOrDefault(b => b.Orbit.Key.Equals(orbit) && !(b is AsteroidBeltData));
@ -202,8 +229,7 @@ public sealed class StationPlacementTests : IDisposable
var behind = arcs.Where(a => a.arc < 0).OrderByDescending(a => a.arc).ToList();
var ahead = arcs.Where(a => a.arc > 0).OrderBy(a => a.arc).ToList();
// Turrets alternate behind then ahead, so behind holds the extra one when the count is odd.
Assert.Equal((mine.Count + 1) / 2, behind.Count);
Assert.Equal(mine.Count / 2, ahead.Count);
// (A side whose next turret would reach the base body stops, so the sides need not stay level.)
if (mine.Select(Contacts.Radius).Distinct().Count() > 1) mixedReach++;
foreach (var (side, sign) in new[] { (behind, -1f), (ahead, 1f) })
@ -267,13 +293,15 @@ public sealed class StationPlacementTests : IDisposable
[Fact]
public void ANarrativeStationsTurretsKeepFlankingAndClearEachOtherWhateverTheirReach()
{
const int authored = 5;
var flanked = 0;
var flanked = 0;
var mixed = 0;
var most = 0;
foreach (var built in GeneratedZones(WithALargerTurretHull, authored, 3, 3))
most = Math.Max(most, AssertFlanks(built, ref flanked, ref mixed));
Assert.True(most == authored, $"no story station carried its {authored} authored turrets (most {most})");
foreach (var authored in new[] { 3, 5, 9 })
{
var most = 0;
foreach (var built in GeneratedZones(WithALargerTurretHull, authored, 6, 6))
most = Math.Max(most, AssertFlanks(built, ref flanked, ref mixed));
Assert.True(most > 0 && most <= authored, $"the most turrets a station carried is {most} of {authored} authored");
}
Assert.True(mixed > 0, "no station carried turrets of differing reach");
}