A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
GDD 0.3: allocate starting farmer tiers 1:2:1 by largest remainder (Fixes #2465) (#2891)
Beri2a8c7e217cc4
diff --git a/changelog.d/2465-farmer-tier-split.md b/changelog.d/2465-farmer-tier-split.mdnew file mode 100644index 000000000..400efb4f0--- /dev/null+++ b/changelog.d/2465-farmer-tier-split.md@@ -0,0 +1,2 @@+### Added+- GDD 0.3 starting farmer split (Refs #2465): a helper that splits a farmer count into novice, trained and veteran at 1:2:1 by largest remainder, ties to trained (5 farmers: 1 / 3 / 1; 6 farmers: 1 / 4 / 1, owner, 6 November 2026). Nothing in the game calls it yet, so nothing changes for players and saves are unaffected.diff --git a/sim/Statecraft.Sim.Tests/Gdd03FarmerTierSplitTests.cs b/sim/Statecraft.Sim.Tests/Gdd03FarmerTierSplitTests.csnew file mode 100644index 000000000..c00bfd923--- /dev/null+++ b/sim/Statecraft.Sim.Tests/Gdd03FarmerTierSplitTests.cs@@ -0,0 +1,51 @@+using Statecraft.Sim;++// #2465: R-POP-004 and the Historical starting farmer-tier rule (docs/GDD.md, "Historical starting farmer tiers"):+// 1:2:1 novice : trained : veteran, largest remainder, ties to trained.+public class Gdd03FarmerTierSplitTests+{+ // Counts 0-8 (then 10, 11, 1001) written out by hand from the rule. Five farmers are 1/3/1 (docs/GDD.md). Counts of 2 mod 4 follow the+ // owner's ruling of 6 November 2026 on #2465, "Trained: 1/4/1 (Recommended)": 6 farmers are novice 1, trained 4, veteran 1.+ [Theory]+ [InlineData(0, 0, 0, 0)]+ [InlineData(1, 0, 1, 0)]+ [InlineData(2, 0, 2, 0)]+ [InlineData(3, 1, 1, 1)]+ [InlineData(4, 1, 2, 1)]+ [InlineData(5, 1, 3, 1)]+ [InlineData(6, 1, 4, 1)]+ [InlineData(7, 2, 3, 2)]+ [InlineData(8, 2, 4, 2)]+ [InlineData(10, 2, 6, 2)]+ [InlineData(11, 3, 5, 3)]+ [InlineData(1001, 250, 501, 250)]+ public void SplitsOneTwoOneByLargestRemainderWithTiesToTrained(int farmers, int novice, int trained, int veteran)+ => Assert.Equal((novice, trained, veteran), Gdd03FarmerTierSplit.Split(farmers));++ [Fact]+ public void TwoModFourGivesTheLeftoverToTrained()+ {+ // The owner's ruling of 6 November 2026 on #2465: "Trained: 1/4/1 (Recommended)".+ Assert.Equal((1, 4, 1), Gdd03FarmerTierSplit.Split(6));+ for (var n = 2; n <= 402; n += 4)+ {+ var (nov, tra, vet) = Gdd03FarmerTierSplit.Split(n);+ Assert.Equal((n - 2) / 4, nov); Assert.Equal((n - 2) / 4, vet); Assert.Equal((n + 2) / 2, tra);+ }+ }++ [Fact]+ public void EveryCountKeepsItsTotalAndMultiplesOfFourSplitExactly()+ {+ for (var n = 0; n <= 2000; n++)+ {+ var (nov, tra, vet) = Gdd03FarmerTierSplit.Split(n);+ Assert.Equal(n, nov + tra + vet);+ if (n % 4 == 0) Assert.Equal((n / 4, n / 2, n / 4), (nov, tra, vet));+ }+ Assert.Equal((int.MaxValue / 4 + 1, int.MaxValue / 2, int.MaxValue / 4 + 1), Gdd03FarmerTierSplit.Split(int.MaxValue));+ }++ [Fact]+ public void NegativeCountIsRefused() => Assert.Throws<System.ArgumentOutOfRangeException>(() => Gdd03FarmerTierSplit.Split(-1));+}diff --git a/sim/Statecraft.Sim/Gdd03FarmerTierSplit.cs b/sim/Statecraft.Sim/Gdd03FarmerTierSplit.csnew file mode 100644index 000000000..f4822b7c5--- /dev/null+++ b/sim/Statecraft.Sim/Gdd03FarmerTierSplit.cs@@ -0,0 +1,35 @@+using System;++namespace Statecraft.Sim+{+ /// <summary>#2465: the Historical starting farmer split, a quarter novice, half trained and a quarter veteran+ /// (R-POP-004, docs/GDD.md "Historical starting farmer tiers"). Pure integer arithmetic on a count: no city,+ /// population id, census record or field is chosen here, and nothing in the game calls it yet.</summary>+ internal static class Gdd03FarmerTierSplit+ {+ // Largest remainder over quarters (shares 1/4, 2/4, 1/4). Ties go to trained (#1717 rounding ruling). The 2 mod 4+ // case is the owner's ruling of 6 November 2026 on #2465, "Trained: 1/4/1 (Recommended)": the leftover unit is+ // tied between novice and veteran with trained at remainder 0, and it goes to trained, so 6 farmers are 1 / 4 / 1.+ internal static (int Novice, int Trained, int Veteran) Split(int farmers)+ {+ if (farmers < 0) throw new ArgumentOutOfRangeException(nameof(farmers), "Requires a nonnegative count.");+ // Quarters as longs: farmers * 2 would overflow an int at the top of the range.+ long n = farmers;+ long novice = n / 4, trained = n * 2 / 4, veteran = n / 4;+ long leftover = n - novice - trained - veteran;+ long novRem = n % 4, traRem = n * 2 % 4, vetRem = n % 4;+ // Hand out the leftover units one at a time to the largest remaining remainder; trained wins every tie.+ // A single leftover that novice and veteran tie for (2 mod 4, trained at remainder 0) cannot be split between+ // them, so the owner's ruling gives it to trained.+ while (leftover > 0)+ {+ var oneUnitTie = leftover == 1 && novRem == vetRem && novRem > traRem;+ if (oneUnitTie || (traRem >= novRem && traRem >= vetRem)) { trained++; traRem = -1; }+ else if (novRem >= vetRem) { novice++; novRem = -1; }+ else { veteran++; vetRem = -1; }+ leftover--;+ }+ return ((int)novice, (int)trained, (int)veteran);+ }+ }+}