FieldKinds.Assign: a kind needs a positive kind weight and a positive province factor; two negatives no longer draw
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1db250fb10
commit
4b7e5476c0
2 changed files with 22 additions and 2 deletions
|
|
@ -226,8 +226,9 @@ public static class FieldKinds
|
|||
.Select(kind =>
|
||||
{
|
||||
var key = catalog.RefOf(kind).Key;
|
||||
return (Key: key, Weight: kind.GenerationWeight * Factor(
|
||||
type?.Kinds.Where(entry => entry.Kind.Key.Equals(key)).Select(entry => (double) entry.Weight), 1.0));
|
||||
var factor = Factor(type?.Kinds.Where(entry => entry.Kind.Key.Equals(key)).Select(entry => (double) entry.Weight), 1.0);
|
||||
// Both must be positive: two negatives do not multiply into a weight.
|
||||
return (Key: key, Weight: kind.GenerationWeight > 0f && factor > 0.0 ? kind.GenerationWeight * factor : 0.0);
|
||||
})
|
||||
.Where(kind => kind.Weight > 0.0)
|
||||
.OrderBy(kind => kind.Key.Value, StringComparer.Ordinal)
|
||||
|
|
|
|||
|
|
@ -238,6 +238,25 @@ public sealed class OreGeographyTests : IDisposable
|
|||
Assert.False(FieldKinds.Assign("belt-0", Empty(), default).IsSet());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AKindWhoseCombinedWeightIsNotPositiveIsNeverDrawn()
|
||||
{
|
||||
var cache = Empty();
|
||||
var negative = Kind(cache, "negative", -1f);
|
||||
Kind(cache, "positive", 1f);
|
||||
var flipped = Province(cache, "flipped", 1, new[] {KindFactor(negative, -1f)});
|
||||
for (var i = 0; i < 500; i++)
|
||||
{
|
||||
Assert.Equal("field-kind:positive", FieldKinds.Assign($"belt-{i}", cache, default).Key.Value);
|
||||
Assert.Equal("field-kind:positive", FieldKinds.Assign($"belt-{i}", cache, flipped).Key.Value);
|
||||
}
|
||||
|
||||
// With nothing positive left the belt has no kind, rather than the negative one.
|
||||
var only = Empty();
|
||||
var lone = Kind(only, "negative", -1f);
|
||||
Assert.False(FieldKinds.Assign("belt-0", only, Province(only, "flipped", 1, new[] {KindFactor(lone, -1f)})).IsSet());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProvinceWeightsTheKindDraw()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue