ProductWeight is the one weight of every design-only draw; a line's bin shares are read once per pass
The all-weights-zero branch of ChooseProduct and the required-item fallback of RandomProducts weighed every product 1, so a bin doubled its maker's presence there. Both now weigh by Share alone (the preference drops out, the bins' shares do not). The sum of a line's bins' pass fractions is computed once per weighting pass instead of scanning the product table per candidate. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9457e4c8f9
commit
129e5ff4dc
2 changed files with 62 additions and 9 deletions
|
|
@ -300,6 +300,48 @@ public sealed class ProductChoiceTests : IDisposable
|
|||
Assert.Equal(0f, three.Outfitter(three.OutEven, 1, 0).ProductWeight(three.Product("lamp-a")));
|
||||
}
|
||||
|
||||
// Ruling bin-share-by-floor holds on every draw of a design, not only the preference-weighted one. When every reachable maker
|
||||
// weighs 0 the ChooseProduct draw is by share alone, and Alpha's line and bin together keep the half they held as one product.
|
||||
[Fact]
|
||||
public void ABinLeavesItsMakersShareOfTheAllZeroWeightDrawUnchanged()
|
||||
{
|
||||
int AlphaDraws(Rig rig)
|
||||
{
|
||||
var lamp = rig.Cache.GetByName<GearData>("Lamp");
|
||||
var zero = rig.Cache.GetByName<Faction>("OutZero");
|
||||
return Enumerable.Range(1, 1000).Count(i => rig.Cache.Get(rig.Outfitter(zero, Seed(i), 0).ChooseProduct(lamp).Manufacturer).Name == "Alpha");
|
||||
}
|
||||
|
||||
Assert.InRange(AlphaDraws(Build("lamp-z", "lamp-a")), 440, 560);
|
||||
Assert.InRange(AlphaDraws(Build(new[] { .67f }, new[] { "lamp-z", "lamp-a" })), 440, 560);
|
||||
Assert.InRange(AlphaDraws(Build(new[] { 0f }, new[] { "lamp-z", "lamp-a" })), 440, 560);
|
||||
}
|
||||
|
||||
// The same for a required item that has fallen back to any manufacturer (OutNone is allied to nobody, so no product is on offer
|
||||
// and the fallback weighs every product alike, but for the bins' shares).
|
||||
[Fact]
|
||||
public void ABinLeavesItsMakersShareOfTheRequiredFallbackDrawUnchanged()
|
||||
{
|
||||
int AlphaDraws(Rig rig)
|
||||
{
|
||||
var log = new List<string>();
|
||||
var items = new ItemManager(rig.Cache, new ProvenanceLedger(), RunSaveTests.TestSettings(), log.Add);
|
||||
var lamp = rig.Cache.GetByName<GearData>("Lamp");
|
||||
var alpha = Enumerable.Range(1, 1000).Count(i =>
|
||||
{
|
||||
var random = new Random(Seed(i));
|
||||
var generator = new LoadoutGenerator(ref random, items, rig.Galaxy, null, rig.OutNone, .5f);
|
||||
return rig.Cache.Get(generator.RandomProduct<EquippableItemData>(0, design => design == lamp, required: true).product.Manufacturer).Name == "Alpha";
|
||||
});
|
||||
Assert.NotEmpty(log);
|
||||
return alpha;
|
||||
}
|
||||
|
||||
Assert.InRange(AlphaDraws(Build("lamp-z", "lamp-a")), 440, 560);
|
||||
Assert.InRange(AlphaDraws(Build(new[] { .67f }, new[] { "lamp-z", "lamp-a" })), 440, 560);
|
||||
Assert.InRange(AlphaDraws(Build(new[] { 0f }, new[] { "lamp-z", "lamp-a" })), 440, 560);
|
||||
}
|
||||
|
||||
// A weight that read the allegiance alone would give 1 : .25 here, an 80% draw; the zone and allegiance together
|
||||
// give 1 : .125 for alpha at its own zone, 89%.
|
||||
[Fact]
|
||||
|
|
|
|||
Loading…
Reference in a new issue