Initial commit: Theriapolis baseline at port/godot branch point

Captures the pre-Godot-port state of the codebase. This is the rollback
anchor for the Godot port (M0 of theriapolis-rpg-implementation-plan-godot-port.md).
All Phase 0 through Phase 6.5 work is included; Phase 7 is in flight.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Christopher Wiebe
2026-04-30 20:40:51 -07:00
commit b451f83174
525 changed files with 75786 additions and 0 deletions
@@ -0,0 +1,52 @@
using Theriapolis.Core.World.Generation;
using Xunit;
namespace Theriapolis.Tests.Determinism;
/// <summary>
/// Phase 2+3 determinism contract: same seed → identical settlements and polylines.
/// Uses variant 0 and variant 1 so the fixture returns two independent pipeline
/// runs rather than comparing one cached context to itself.
/// </summary>
public sealed class Phase23DeterminismTests : IClassFixture<WorldCache>
{
private const ulong TestSeed = 0xCAFEBABEUL;
private readonly WorldCache _cache;
public Phase23DeterminismTests(WorldCache cache) => _cache = cache;
[Fact]
public void SameSeed_ProducesIdenticalSettlements()
{
var h1 = _cache.Get(TestSeed, variant: 0).World.HashSettlements();
var h2 = _cache.Get(TestSeed, variant: 1).World.HashSettlements();
Assert.Equal(h1, h2);
}
[Fact]
public void SameSeed_ProducesIdenticalPolylines()
{
var h1 = _cache.Get(TestSeed, variant: 0).World.HashPolylines();
var h2 = _cache.Get(TestSeed, variant: 1).World.HashPolylines();
Assert.Equal(h1, h2);
}
[Fact]
public void DifferentSeeds_ProduceDifferentSettlements()
{
var h1 = _cache.Get(TestSeed).World.HashSettlements();
var h2 = _cache.Get(TestSeed + 7).World.HashSettlements();
Assert.NotEqual(h1, h2);
}
[Theory]
[InlineData(0xABCD1234UL)]
[InlineData(0x00000001UL)]
[InlineData(0xDEADBEEFUL)]
public void MultipleSeeds_SettlementsAreDeterministic(ulong seed)
{
var h1 = _cache.Get(seed, variant: 0).World.HashSettlements();
var h2 = _cache.Get(seed, variant: 1).World.HashSettlements();
Assert.Equal(h1, h2);
}
}
@@ -0,0 +1,77 @@
using Theriapolis.Core.Util;
using Xunit;
namespace Theriapolis.Tests.Determinism;
/// <summary>
/// Phase 0 smoke tests: two SeededRng instances with the same seed must produce
/// identical outputs, and different seeds must diverge.
/// </summary>
public sealed class SeededRngTests
{
[Fact]
public void SameSeed_ProducesSameSequence()
{
var a = new SeededRng(123);
var b = new SeededRng(123);
for (int i = 0; i < 1000; i++)
Assert.Equal(a.NextUInt64(), b.NextUInt64());
}
[Fact]
public void DifferentSeeds_ProduceDifferentSequences()
{
var a = new SeededRng(123);
var b = new SeededRng(456);
bool anyDifferent = false;
for (int i = 0; i < 10; i++)
if (a.NextUInt64() != b.NextUInt64()) { anyDifferent = true; break; }
Assert.True(anyDifferent, "Different seeds should produce different sequences.");
}
[Fact]
public void ZeroSeed_DoesNotGetStuck()
{
var rng = new SeededRng(0);
ulong prev = rng.NextUInt64();
bool moved = false;
for (int i = 0; i < 5; i++)
{
ulong next = rng.NextUInt64();
if (next != prev) { moved = true; break; }
prev = next;
}
Assert.True(moved, "RNG must advance even from seed 0.");
}
[Fact]
public void NextFloat_InRange()
{
var rng = new SeededRng(999);
for (int i = 0; i < 10_000; i++)
{
float f = rng.NextFloat();
Assert.True(f >= 0f && f < 1f, $"float {f} out of [0,1)");
}
}
[Fact]
public void ForSubsystem_DifferentTagsProduceDifferentStreams()
{
var a = SeededRng.ForSubsystem(0xDEADBEEF, Theriapolis.Core.C.RNG_TERRAIN);
var b = SeededRng.ForSubsystem(0xDEADBEEF, Theriapolis.Core.C.RNG_MOISTURE);
Assert.NotEqual(a.NextUInt64(), b.NextUInt64());
}
[Fact]
public void Seed123_FirstValue_IsReproducible()
{
// Two independent instances must produce the exact same first value.
var x = new SeededRng(123).NextUInt64();
var y = new SeededRng(123).NextUInt64();
Assert.Equal(x, y);
}
}
@@ -0,0 +1,61 @@
using Theriapolis.Core.World.Generation;
using Xunit;
namespace Theriapolis.Tests.Determinism;
/// <summary>
/// Phase 1 determinism contract:
/// seed 0xCAFEBABE run twice → byte-identical elevation, moisture, temperature,
/// and biome arrays.
///
/// Uses variant 0 and variant 1 so the WorldCache fixture returns two
/// independent pipeline runs of the same seed (otherwise comparing the cached
/// context against itself would prove nothing).
/// </summary>
public sealed class WorldgenDeterminismTests : IClassFixture<WorldCache>
{
private const ulong TestSeed = 0xCAFEBABEUL;
private readonly WorldCache _cache;
public WorldgenDeterminismTests(WorldCache cache) => _cache = cache;
[Fact]
public void SameSeed_ProducesIdenticalElevation()
{
var h1 = _cache.Get(TestSeed, variant: 0).World.HashElevation();
var h2 = _cache.Get(TestSeed, variant: 1).World.HashElevation();
Assert.Equal(h1, h2);
}
[Fact]
public void SameSeed_ProducesIdenticalMoisture()
{
var h1 = _cache.Get(TestSeed, variant: 0).World.HashMoisture();
var h2 = _cache.Get(TestSeed, variant: 1).World.HashMoisture();
Assert.Equal(h1, h2);
}
[Fact]
public void SameSeed_ProducesIdenticalTemperature()
{
var h1 = _cache.Get(TestSeed, variant: 0).World.HashTemperature();
var h2 = _cache.Get(TestSeed, variant: 1).World.HashTemperature();
Assert.Equal(h1, h2);
}
[Fact]
public void SameSeed_ProducesIdenticalBiomes()
{
var h1 = _cache.Get(TestSeed, variant: 0).World.HashBiomes();
var h2 = _cache.Get(TestSeed, variant: 1).World.HashBiomes();
Assert.Equal(h1, h2);
}
[Fact]
public void DifferentSeeds_ProduceDifferentElevation()
{
var h1 = _cache.Get(TestSeed).World.HashElevation();
var h2 = _cache.Get(TestSeed + 1).World.HashElevation();
Assert.NotEqual(h1, h2);
}
}