From c874d60a66a102649351eca69120eed19efcbeec Mon Sep 17 00:00:00 2001 From: soul Date: Sat, 28 Nov 2026 14:33:07 +0100 Subject: [PATCH] Drain: the sortie hold is the median of what a seed's sorties mined, not of the full-hold ones Seeds 2, 3, 69 and 97 stop on a starting stock long before a hold fills, so only seed 1 had a measured sortie. Co-Authored-By: Claude Sonnet 5.5 --- tests/Aetheria.Shared.Tests/EconomyDrainTests.cs | 1 + tools/AetherDb/EconomyCommand.cs | 2 +- tools/AetherDb/EconomyDrain.cs | 10 ++++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/Aetheria.Shared.Tests/EconomyDrainTests.cs b/tests/Aetheria.Shared.Tests/EconomyDrainTests.cs index 0770a073c..060a9688e 100644 --- a/tests/Aetheria.Shared.Tests/EconomyDrainTests.cs +++ b/tests/Aetheria.Shared.Tests/EconomyDrainTests.cs @@ -79,6 +79,7 @@ public sealed class EconomyDrainTests Assert.Equal(Stall.Inputs, roomy.Facilities.Single().HorizonEnd); Assert.DoesNotContain(EconomyDrain.Report(new[] { made }), f => f.Invariant == EconomyDrain.HStall); } +[Fact] public void TheSortieHoldIsTheMedianOfWhatSortiesMined() { LoopSample Mined(int units) => new LoopSample { Units = units, Outcome = LoopOutcome.AmmoOut }; Assert.Equal(15, EconomyDrain.SortieUnits(69, new[] { Mined(6), Mined(18), Mined(2), Mined(15), Mined(0) })); Assert.Equal(8, EconomyDrain.SortieUnits(3, new[] { Mined(25), Mined(8), Mined(3) })); Assert.Throws(() => EconomyDrain.SortieUnits(2, new[] { Mined(0) })); } [Fact] public void DrainRefusesLoopAndStrayOptions() { foreach (var args in new[] { new[] { "balance", "--drain", "--loop" }, new[] { "balance", "--loop", "1", "--window", "5" }, new[] { "balance", "--drain", "--cap", "5" }, new[] { "balance", "--drain", "--horizon", "0" }, new[] { "balance", "--drain", "--window" } }) { var output = new StringWriter(); Assert.Equal(1, EconomyCommand.Run(args, output)); Assert.Contains("balance --drain [...]", output.ToString()); } } [Fact] diff --git a/tools/AetherDb/EconomyCommand.cs b/tools/AetherDb/EconomyCommand.cs index 29cfa605f..94527f3ef 100644 --- a/tools/AetherDb/EconomyCommand.cs +++ b/tools/AetherDb/EconomyCommand.cs @@ -129,7 +129,7 @@ public static class EconomyCommand loop = EconomyLoop.Report(db.Cache, settings, seedList.SelectMany(seed => EconomyLoop.Sorties(db.Root, seed, (float) cap)).ToList()); List drain = null; if (drainAt >= 0) - drain = seedList.Select(seed => EconomyDrain.Run(db.Root, seed, window, horizon, EconomyDrain.SortieUnits(EconomyLoop.Sorties(db.Root, seed, EconomyLoop.DefaultCap)))).ToList(); + drain = seedList.Select(seed => EconomyDrain.Run(db.Root, seed, window, horizon, EconomyDrain.SortieUnits(seed, EconomyLoop.Sorties(db.Root, seed, EconomyLoop.DefaultCap)))).ToList(); return Balance(db.Cache, settings.EconomyWageSpread, output, loop, drain); } if (args.Length > 0 && args[0] == "author") diff --git a/tools/AetherDb/EconomyDrain.cs b/tools/AetherDb/EconomyDrain.cs index 6c32f9793..98158c305 100644 --- a/tools/AetherDb/EconomyDrain.cs +++ b/tools/AetherDb/EconomyDrain.cs @@ -93,11 +93,13 @@ public static class EconomyDrain public const double Span = 60; private const int MaxSorties = 500; - // The seed's median sortie hold, in units: the median over the sorties that mined to a full hold or the cap. - public static int SortieUnits(IReadOnlyList samples) + // The seed's median sortie hold, in units: the middle of the holds of the sorties that mined something (the upper one of an + // even count), whatever stopped them. Most seeds' sorties stop on a starting stock long before the hold fills. + public static int SortieUnits(uint seed, IReadOnlyList samples) { - var units = samples.Where(s => s.Measured).Select(s => s.Units).OrderBy(u => u).ToList(); - return units.Count == 0 ? 0 : units[units.Count / 2]; + var units = samples.Where(s => s.Units > 0).Select(s => s.Units).OrderBy(u => u).ToList(); + if (units.Count == 0) throw new InvalidOperationException($"seed {seed}: no sortie mined anything, so there is no hold to sell"); + return units[units.Count / 2]; } // beforeFill sees the booted arena before any sale (a test empties a bay there); beforeWindow sees it after the fill and before