StationDeckTests: the deal's kinds outside the entrance, every card seated, the gradient, purity across a save, an ordered entrance

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-28 22:53:18 +01:00
commit 93fb5c7030

View file

@ -0,0 +1,140 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
// StationDeck (aetheria-living-world, cut region-chain-deck; ruling demo-chain-spans-the-region): the deal owns which stations every zone of a
// run holds, per region, and ZoneGenerator seats every card of it.
public sealed partial class RunStartTests
{
private static readonly uint[] DeckSeeds = Enumerable.Range(1, 40).Select(seed => (uint) seed).ToArray();
private string KeyOf(Faction faction) => faction == null ? "" : _cache.RefOf(faction).Key.Value;
// A deal as a person reads it: each zone's (faction, kind) cards.
private string[][] Read(StationCard[][] deal) => deal.Select(cards => cards.Select(card => KeyOf(card.Faction) + "/" + card.Kind.Key.Value).ToArray()).ToArray();
// The stations a pack holds in the order it holds them, turrets and ships left out: (faction, kind).
private string[] StationCardsOf(ZonePack pack) => pack.Entities.OfType<OrbitalEntityPack>().Where(entity => entity.Kind.IsSet())
.Select(entity => entity.Faction.Key.Value + "/" + entity.Kind.Key.Value).ToArray();
// The card an order seats, as StationCardsOf reads it.
private string OrderCard(Galaxy galaxy, EntranceStationOrder order) => KeyOf(galaxy.ResolveFaction(order.Faction)) + "/" + StationKindData.KeyOf(order.Kind).Value;
// The ambient cards of a zone: its dealt cards after its story stations'.
private static StationCard[] Ambient(StationCard[] cards, GalaxyZone zone) => cards.Skip(zone.Locations.Count(story => story.Type == LocationType.Station)).ToArray();
[Fact]
public void EveryKindEachFactionFieldsStandsOutsideTheEntrance()
{
var checkedFactions = 0;
foreach (var seed in DeckSeeds)
{
var galaxy = DemoGalaxy(seed);
var deal = StationDeck.Deal(galaxy, _cache);
foreach (var region in Enumerable.Range(0, galaxy.Zones.Length).GroupBy(z => galaxy.Zones[z].Province.Region))
{
var outside = region.Where(z => galaxy.Zones[z] != galaxy.Entrance).ToArray();
foreach (var faction in outside.Select(z => StationDeck.StructureFaction(galaxy, galaxy.Zones[z])).Distinct())
{
var dealt = outside.SelectMany(z => Ambient(deal[z], galaxy.Zones[z])).Where(card => card.Faction == faction)
.Select(card => card.Kind.Key.Value).ToHashSet();
foreach (var kind in StationKinds.PoolOf(_cache, faction))
Assert.True(dealt.Contains(kind.Key.Value), $"seed {seed}: {faction.Name} fields {kind.Key.Value}, none dealt outside the entrance of region {region.Key}");
checkedFactions++;
}
}
}
Assert.True(checkedFactions >= 40 * 4, $"the sweep covered {checkedFactions} faction regions");
}
[Fact]
public void EveryDealtCardIsSeated()
{
foreach (var seed in RegionSeeds)
{
var (galaxy, arena, _) = RegionRun(seed);
var deal = StationDeck.Deal(galaxy, _cache);
var seated = 0;
for (var z = 0; z < galaxy.Zones.Length; z++)
{
var zone = galaxy.Zones[z];
if (zone == galaxy.Entrance) continue;
Assert.Equal(Read(new[] { deal[z] })[0], StationCardsOf(zone.Contents.PackZone()));
seated += deal[z].Length;
}
Assert.True(seated > 0, $"seed {seed}: the region dealt no station outside the entrance");
Assert.Equal(new DemoTerminus().EntranceStations.Select(order => OrderCard(galaxy, order)).ToArray(), StationCardsOf(arena.PackZone()));
}
}
[Fact]
public void ChainRunsUpEachFactionsGradient()
{
foreach (var seed in DeckSeeds)
{
var galaxy = DemoGalaxy(seed);
var deal = StationDeck.Deal(galaxy, _cache);
foreach (var region in Enumerable.Range(0, galaxy.Zones.Length).GroupBy(z => galaxy.Zones[z].Province.Region))
foreach (var faction in region.Where(z => galaxy.Zones[z] != galaxy.Entrance).Select(z => StationDeck.StructureFaction(galaxy, galaxy.Zones[z])).Distinct())
{
// (home distance, ring) of the faction's non-entrance ambient cards in the region
var hand = region.Where(z => galaxy.Zones[z] != galaxy.Entrance && StationDeck.StructureFaction(galaxy, galaxy.Zones[z]) == faction)
.SelectMany(z => Ambient(deal[z], galaxy.Zones[z]).Select(card => (distance: galaxy.HomeZones[faction].Distance[galaxy.Zones[z]], ring: _cache.Get(card.Kind).Ring)))
.ToArray();
foreach (var near in hand)
foreach (var far in hand.Where(other => other.distance > near.distance))
Assert.True(far.ring <= near.ring, $"seed {seed}: {faction.Name} has a ring-{far.ring} card at distance {far.distance} beyond a ring-{near.ring} card at {near.distance}");
if (faction == galaxy.Antagonist)
foreach (var home in hand.Where(card => card.ring == 3))
foreach (var frontier in hand.Where(card => card.ring == 0))
Assert.True(home.distance <= frontier.distance, $"seed {seed}: Zhestokost holds a ring-3 card at distance {home.distance} beyond a ring-0 card at {frontier.distance}");
}
}
}
[Fact]
public void DealIsPureAndSurvivesSave()
{
var (galaxy, arena, staged) = RegionRun(1);
var deal = Read(StationDeck.Deal(galaxy, _cache));
Assert.Equal(deal, Read(StationDeck.Deal(galaxy, _cache)));
var (game, zones) = RunSave.Capture(_cache, galaxy, arena, staged.Player, new SavedActionBarBinding[0], 0);
RunSave.Commit(_cache, game, zones, _items.Lots);
var restored = new Galaxy(_cache, _cache.GetGlobal<SavedGame>(), _ => { });
Assert.Equal(deal, Read(StationDeck.Deal(restored, _cache)));
// Generating zones last first moves no card: each zone seats what the deal gave it, whatever was generated before it.
for (var z = galaxy.Zones.Length - 1; z >= 0; z--)
{
if (galaxy.Zones[z] == galaxy.Entrance) continue;
var pack = ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, galaxy, galaxy.Zones[z]);
Assert.Equal(deal[z], StationCardsOf(pack));
}
Assert.Equal(deal, Read(StationDeck.Deal(galaxy, _cache)));
}
[Fact]
public void AnOrderedEntranceHoldsExactlyItsOrders()
{
var orders = new DemoTerminus().EntranceStations;
foreach (var seed in DeckSeeds)
{
var galaxy = DemoGalaxy(seed);
var pack = ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, galaxy, galaxy.Entrance, orders, ambient: false);
Assert.Equal(orders.Select(order => OrderCard(galaxy, order)).ToArray(), StationCardsOf(pack));
}
// An Any order seats one station of the zone's structure faction and nothing the deal dealt; no order seats the dealt cards.
var one = ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, _galaxy, _galaxy.Entrance, EntranceStationOrder.Any, ambient: false);
Assert.Single(StationCardsOf(one));
var dealt = StationDeck.Deal(_galaxy, _cache)[Array.IndexOf(_galaxy.Zones, _galaxy.Entrance)];
var none = ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, _galaxy, _galaxy.Entrance, EntranceStationOrder.None, ambient: false);
Assert.Equal(Read(new[] { dealt })[0], StationCardsOf(none));
}
}