Early-level build discount (B4) and start stock 1000 (B5)

Playtest on the live world: first hour feels a bit slow. B4: levels 1-3 of any building take x0.5/x0.67/x0.83 of the time (FORMULAS.earlyLevels/earlyTimeFactor, off at earlyLevels 0). Builds at 1 h (4 sittings/day) 8.9 -> 11.4, at 24 h 16.5 -> 20.4; mid game moves ~1 day head start (default mix), more for 2 sittings/day. B5: start stock 750 -> 1000 (measured separately: mid game unchanged, 60-min first sitting 12.1 -> 15.4 builds at 1 h). Numbers in docs/BALANCE.md.

Tested: npm test 208/208, openapi check, npm run e2e 61/61 (before B5), 50x30-day bot run INVARIANTS OK after B5. NOT tested: humans (bots only, 2 seeds), B4+B5 combined beyond one run, e2e does not exercise the discount (runs at 4000x speed). Not claimed: balanced.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
This commit is contained in:
jvanvik 2026-10-11 22:38:37 +02:00
parent cc0524de5e
commit bf7af0679c
10 changed files with 194 additions and 12 deletions

View file

@ -24,6 +24,7 @@ test('bot run: invariants hold and the same seed gives identical stats', async (
assert.ok(a.perf.commands > 50 && a.botLogs.builds > 20 && a.botLogs.trains > 0, 'the bots built and trained');
assert.ok(a.days.length === 6 && a.meta.players === 12);
assert.ok(a.combat.scans.n > 0, 'and scouted (the military paths ran, so determinism covers them)');
assert.ok(a.early && a.early['1h'].n > 0 && a.early['1h'].builds > 0 && a.early['24h'].builds >= a.early['1h'].builds && a.early['1h'].core >= 1, 'the first-hours view (builds and Core router at 1/6/24 h) is filled');
const c = await runBot({ players: 12, days: 6, seed: 8 });
assert.notDeepStrictEqual(strip(a).days, strip(c).days, 'a different seed should change the world');
assert.ok(Date.now() - t0 < 15000, 'the harness must stay fast (took ' + (Date.now() - t0) + ' ms)');

View file

@ -45,6 +45,36 @@ test('rules: lazy resources are exact between settles and capped', () => {
assert.ok(Math.abs(R.resourcesAt(t2, 5 * h).amounts.fiber - R.resourcesAt(town, 5 * h).amounts.fiber) < 1e-9);
});
test('rules: early-level build discount ramps from earlyTimeFactor up to 1 and leaves later levels alone (BALANCE.md B4)', () => {
const F = D.FORMULAS, saved = { n: F.earlyLevels, f: F.earlyTimeFactor };
const full = (type, level, core, speed) => D.BUILDINGS[type].time * Math.pow(F.timeGrowth, level - 1) / (1 + F.coreSpeedPerLevel * core) / (speed || 1) * 1000;
try {
F.earlyLevels = 3; F.earlyTimeFactor = 0.5;
assert.deepEqual([1, 2, 3, 4, 5, 20].map(R.earlyTimeFactor).map((x) => Math.round(x * 1000) / 1000), [0.5, 0.667, 0.833, 1, 1, 1]);
for (const level of [1, 2, 3]) assert.equal(R.buildTimeMs('cable_yard', level, 1, 1), Math.round(full('cable_yard', level, 1, 1) * R.earlyTimeFactor(level)));
for (const level of [4, 5, 12, 20]) assert.equal(R.buildTimeMs('cable_yard', level, 1, 1), Math.round(full('cable_yard', level, 1, 1)), 'level ' + level + ' is untouched');
assert.ok(R.buildTimeMs('cable_yard', 3, 1, 1) < R.buildTimeMs('cable_yard', 4, 1, 1), 'never a cliff downwards: level 3 is not slower than level 4');
// composes with the Core router and the world speed, and the floor still applies
assert.equal(R.buildTimeMs('rack_hall', 2, 5, 2), Math.round(full('rack_hall', 2, 5, 2) * R.earlyTimeFactor(2)));
assert.equal(R.buildTimeMs('cable_yard', 2, 1, 1e6), F.minBuildMs);
// the plan both client and server use carries it
const town = { speed: 1, updatedAt: 0, res: { fiber: 750, hardware: 750, capital: 750, battery: 0 }, footprint: 0, unitDraw: 0, bonus: {}, buildings: R.initialBuildings() };
const plan = R.buildPlan(town, 'f1', 0, []);
assert.ok(plan.ok, plan.code);
assert.equal(plan.durationMs, R.buildTimeMs(plan.type, 2, 1, 1));
assert.ok(plan.durationMs < full(plan.type, 2, 1, 1));
// off switches
F.earlyLevels = 0;
assert.equal(R.earlyTimeFactor(1), 1);
assert.equal(R.buildTimeMs('cable_yard', 2, 1, 1), Math.round(full('cable_yard', 2, 1, 1)));
F.earlyLevels = 3; F.earlyTimeFactor = 1;
assert.equal(R.buildTimeMs('cable_yard', 2, 1, 1), Math.round(full('cable_yard', 2, 1, 1)));
} finally { F.earlyLevels = saved.n; F.earlyTimeFactor = saved.f; }
// the shipped default: the first Cable yard upgrade takes about 90 s (was 134 s), mid levels are unchanged
assert.ok(F.earlyLevels > 0 && F.earlyTimeFactor < 1 && F.earlyTimeFactor > 0);
assert.ok(R.buildTimeMs('cable_yard', 2, 1, 1) < 100 * 1000 && R.buildTimeMs('cable_yard', 2, 1, 1) > 80 * 1000);
});
test('rules: map generation is deterministic and spawn respects spacing', () => {
assert.deepEqual(R.tileAt(7, 50, 10, 10), R.tileAt(7, 50, 10, 10));
assert.equal(R.tileAt(7, 50, 51, 0).type, 'void');