feat: New theme + wire price adjustement

This commit is contained in:
gauvainboiche
2026-10-08 12:25:45 +02:00
parent aa9721ac2a
commit 1734487f1e
19 changed files with 348 additions and 88 deletions
+53
View File
@@ -138,6 +138,59 @@ test('auto-buy restocks material when funds allow', () => {
assert.ok(s.material > 50);
});
test('material is costly at first and cheaper relative to the sale price as production grows', () => {
const { fairPrice } = ctx.rules.market;
const costShare = (totalProduced) => {
const s = fresh();
s.totalProduced = totalProduced;
const d = derive(s, ctx);
return d.batchCost / d.batchSize / fairPrice;
};
assert.ok(costShare(0) > 0.25, 'expensive at the start');
assert.ok(costShare(1e4) < costShare(0));
assert.ok(costShare(1e6) < costShare(1e4));
assert.ok(costShare(1e9) < 0.1, 'a small share of revenue late in the game');
});
test('material lots grow with the operation, in doublings', () => {
const sizeAt = (total) => {
const s = fresh();
s.totalProduced = total;
return derive(s, ctx).batchSize;
};
assert.equal(sizeAt(0), ctx.rules.materialMarket.minBatch);
assert.ok(sizeAt(1e6) > sizeAt(1e4));
assert.equal(Math.log2(sizeAt(1e6) / ctx.rules.materialMarket.minBatch) % 1, 0);
});
test('the material market is erratic but stays within its bounds', () => {
const m = ctx.rules.materialMarket;
const s = fresh();
let seed = 7;
const rng = () => (seed = (seed * 16807) % 2147483647) / 2147483647;
const seen = [];
for (let i = 0; i < 2000; i++) {
advance(s, ctx, m.updateEverySeconds, rng);
seen.push(s.materialFactor);
}
assert.ok(Math.min(...seen) >= m.minFactor && Math.max(...seen) <= m.maxFactor);
assert.ok(Math.max(...seen) > 1.6 && Math.min(...seen) < 0.6, 'swings widely');
assert.ok(new Set(seen.map((f) => f.toFixed(2))).size > 100, 'does not sit still');
});
test('auto-buy waits for a fair price unless stock is nearly gone', () => {
const s = fresh();
s.upgrades = ['auto_buy'];
s.funds = 1e6;
s.materialFactor = 2.5; // expensive
s.material = 40; // low but not desperate (< lot/2, > lot/10)
advance(s, ctx, 0.1, () => 0.5);
assert.equal(s.material, 40, 'did not buy at a high price');
s.material = 5; // desperate
advance(s, ctx, 0.1, () => 0.5);
assert.ok(s.material > 50, 'buys when nearly out');
});
test('offline progress is capped, discounted, and ignored when short', () => {
const s = fresh();
s.generators.gen1 = 5;