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

@ -38,6 +38,11 @@ node tools/bot.js --help
fields level together (`balanced`, a lower bound). A bot that has been raided trains defence up to 1.25 x the strongest attack fields level together (`balanced`, a lower bound). A bot that has been raided trains defence up to 1.25 x the strongest attack
it saw, for 5 days (`--no-adapt` turns that off, an upper bound on how badly defenders can do). A bot that sees every store full it saw, for 5 days (`--no-adapt` turns that off, an upper bound on how badly defenders can do). A bot that sees every store full
upgrades the Rack hall first. Several of these were bot bugs before they were fixed, and each moved the results: see section 7. upgrades the Rack hall first. Several of these were bot bugs before they were fixed, and each moved the results: see section 7.
- **First hours** (`stats.early`, printed as "first hours after signing up"): builds completed at the capital, and the Core router level,
1 h, 6 h and 24 h after an operator joined (only operators at least that old at the end of the run). It is read from the `buildDone` events,
so it needs no extra sampling: `node tools/bot.js --players 50 --days 4 --join-days 1 --sessions-per-day 4 --quiet --json out.json` takes under a
second. Two cadence facts to read it by: the first sitting is 20 minutes (`--first-session-min`), and `--always-on` is a tick every 10 minutes that
starts at most one build per tick, not a player who never leaves (so it shows 5.7 builds at 1 h, less than a 20-minute sitting does).
- **`--set PATH=VALUE`** changes `data.js` in place for one run and restores it afterwards. It reaches every value the code reads at call time - **`--set PATH=VALUE`** changes `data.js` in place for one run and restores it afterwards. It reaches every value the code reads at call time
(all the ones used here); a primitive copied when a module is loaded, e.g. `ENDGAME.scanStrength` in `server/military/landing.js`, is (all the ones used here); a primitive copied when a module is loaded, e.g. `ENDGAME.scanStrength` in `server/military/landing.js`, is
not overridable and the run would silently ignore it. not overridable and the run would silently ignore it.
@ -230,6 +235,102 @@ restore the scaling (a 10x world with a final push finished 8.5 days after openi
(trade form limits, send dialog), so it was left to the owner of that code. (trade form limits, send dialog), so it was left to the owner of that code.
### B4. Early-level build discount (the first hour and first day)
| parameter | old | new | file |
|---|---|---|---|
| `FORMULAS.earlyLevels` | (did not exist) | 3 | `public/js/data.js` |
| `FORMULAS.earlyTimeFactor` | (did not exist) | 0.5 | `public/js/data.js` |
Rule (`rules.earlyTimeFactor`, used by `rules.buildTimeMs`, so by `buildPlan`, the server command and the client's "Time" line alike): building up
to level L takes `earlyTimeFactor + (1 - earlyTimeFactor) * (L - 1) / earlyLevels` times the normal time for L up to `earlyLevels`, i.e. 0.5 at level 1,
0.667 at level 2, 0.833 at level 3, and exactly 1 from level 4 on. `earlyLevels = 0` (or a factor of 1) switches it off. It composes with the Core
router and the world speed and the 5 s floor; the Backbone node (own formula) and research are untouched. It applies to every POP, so a newly founded
POP's first levels are quick too. Fields start at level 1, so a field's first upgrade (to level 2) is the one the player meets first: the first
Cable yard upgrade takes 90 s instead of 134 s, the second level 129 s instead of 155 s.
**What was wrong, measured** (50 bots, seeds 1+2 averaged, builds at the capital N hours after joining; `--players 50 --days 4 --join-days 1`
with `--sessions-per-day 2|4|8`, `--always-on`, and `--sessions-per-day 4 --first-session-min 60` for "a player who plays one full hour"):
- A new POP has 750 of each resource and makes ~30 per hour of each. Upgrading a field to level 2 costs 51/32/19 to 64/38/13 (~110 in all)
and a level 3 about 1.28 times that, so the starting stock pays for **about 12 builds** and income (~90 per hour in all) for roughly one more build an
hour after that. At 134 to 167 s a build, one slot reaches that point after about 30 minutes of chaining. So for a player who plays the first hour
properly the hour is: build for half an hour, then wait for income. The bots show it: a 60-minute first sitting gets 12.1 builds in the first hour,
and so does every variant tried below (the cap is the stock, not the clock).
- A player who only plays the first sitting (20 minutes, then a few short sittings) is limited by build time: 8.9 builds at 1 h, at any cadence.
That is the case the discount helps, and the one that was "a bit slow".
- Over the first day the bots are sitting-limited (2 a day: 12.5 builds at 24 h; 4 a day: 16.5; 8 a day: 22.7) except `--always-on`, which hits the
resource limit by hour 6 (15.6 builds at 6 h, 25.9 at 24 h) and is therefore not helped at all by any time change.
**Before / after** (before = `--set FORMULAS.earlyLevels=0`; chosen = the new default; builds at the capital, mean of 2 seeds, [Core router at 24 h in brackets]):
| operator cadence | 1 h before | 1 h after | 6 h before | 6 h after | 24 h before | 24 h after |
|---|---|---|---|---|---|---|
| 2 sittings a day | 8.9 | 11.3 | 9.5 | 12.2 | 12.5 [1.16] | 16.4 [1.20] |
| 4 sittings a day | 8.9 | 11.4 | 10.6 | 13.2 | 16.5 [1.18] | 20.4 [2.02] |
| 8 sittings a day | 9.1 | 11.4 | 12.3 | 13.9 | 22.7 [2.11] | 23.7 [2.09] |
| 4 a day, first sitting 60 min | 12.1 | 12.1 | 13.4 | 13.5 | 18.9 [1.77] | 20.7 [2.02] |
| always-on (10-minute tick) | 5.7 | 5.8 | 15.6 | 15.6 | 25.9 [2.09] | 25.9 [2.09] |
Mid and late game (default mix, 50 players, seeds 1+2 averaged; `node tools/bot.js --players 50 --days 60 --seed N [--sessions-per-day 2|4] --set FORMULAS.earlyLevels=0`
for "before"). Field = mean field level at the capital, Core = median Core router level, fp = median footprint:
| cadence | day | before: field / Core / fp | after: field / Core / fp | field level |
|---|---|---|---|---|
| default (3 to 5 a day) | 14 | 7.28 / 7.0 / 2056 | 7.67 / 8.0 / 2381 | +5 % |
| | 30 | 13.28 / 13.0 / 10324 | 13.60 / 14.0 / 11289 | +2 % |
| | 60 | 18.78 / 19.0 / 43529 | 18.80 / 19.0 / 44643 | +0.1 % |
| 4 a day | 14 | 7.05 / 7.0 / 1883 | 7.55 / 7.0 / 2198 | +7 % |
| | 30 | 12.81 / 12.5 / 9664 | 13.19 / 13.0 / 10642 | +3 % |
| | 60 | 18.94 / 19.0 / 42146 | 19.00 / 19.0 / 44250 | +0.3 % |
| 2 a day | 14 | 4.15 / 4.0 / 1045 | 5.13 / 5.0 / 1343 | +24 % |
| | 30 | 8.38 / 8.0 / 4974 | 9.13 / 9.0 / 6051 | +9 % |
| | 60 | 13.91 / 13.0 / 21628 | 14.59 / 14.0 / 24213 | +5 % |
Longer, one seed (`--days 120 --sessions-per-day 2|4`, seed 1, before = `--set FORMULAS.earlyLevels=0`): 2 a day: field 18.60 on day 90 and 18.97 on day 120
before, 18.88 and 19.00 after; footprint median 89.7k against 94.4k on day 120. 4 a day: saturated from day 60 in both (19.0), footprint 116.1k against 117.9k on
day 120. Core router 10 (median day, 60-day runs): default mix 17.3 -> 16.2, 4 a day 20.0 -> 18.5, 2 a day 35.7 -> 32.6.
Always-on and 8 a day, 30 days, seed 1: field 15.18 -> 15.07 and 15.57 -> 15.56 on day 30, footprint within 1 %: unchanged.
How to read the mid-game numbers: the change is a **head start, not a slope**. Measured as "on which day did the old game reach the level the new game has on day 30":
1.2 days (4 a day), 0.9 (default mix), 3.6 (2 a day); by day 60 the default-mix and 4-a-day curves are on top of each other and the 2-a-day one is
5 % higher in level and 12 % in footprint (it is still climbing; the gap closes as it saturates around day 90 to 120). The percentage on day 14 for the
casual player looks large (+24 %) only because the base is 4 levels; it is about one level. A casual player gets the biggest head start because
a sitting-limited player is the one who gains most builds per sitting from shorter builds (2 a day: 12.5 -> 16.4 builds in the first day, +31 %).
Net worth on day 60: default mix +1 %, 4 a day +1.4 %, 2 a day +17 % (366k -> 430k, still compounding then).
**Alternatives measured, not taken** (same two seeds; "head start" = days at day 30 as above, for 4 a day / 2 a day; 1 h and 24 h are the 4-a-day cadence;
mid = default-mix field level on days 14 / 30 / 60; before: 8.9 / 16.5 builds, field 7.28 / 13.28 / 18.78):
| variant | 1 h | 24 h | head start 4/day, 2/day | mid, default mix |
|---|---|---|---|---|
| **taken: levels 1..3, factor 0.5** | 11.4 | 20.4 | 1.2 / 3.6 d | 7.67 / 13.60 / 18.80 |
| levels 1..2, factor 0 (level 2 takes half) | 11.6 | 20.4 | 1.3 / 4.4 d | 7.70 / 13.68 / 18.78 |
| levels 1..2, factor 0.4 | 10.6 | 19.9 | 1.0 / 3.1 d | 7.63 / 13.56 / 18.82 |
| levels 1..3, factor 0.25 | 12.1 | 21.2 | 1.6 / 5.0 d | 7.76 / 13.70 / 18.81 |
| levels 1..4, factor 0.6 | 11.4 | 20.6 | 1.2 / 3.8 d | 7.71 / 13.61 / 18.81 |
| levels 1..6, factor 0.25 | 12.0 | 22.5 | 2.3 / 7.7 d | 7.89 / 13.97 / 18.85 |
| levels 1..8, factor 0.5 | 12.1 | 21.6 | 2.5 / 7.1 d | 7.87 / 13.97 / 18.84 |
| levels 1..10, factor 0.33 | 12.0 | 22.5 | 3.3 / 10.8 d | 8.01 / 14.26 / 18.85 |
| `timeGrowth` 1.16 -> 1.12 (all levels) | 9.0 | 17.8 | 2.8 / 3.2 d | 7.52 / 14.02 / 18.76 |
Reading it: every variant that reaches the stock limit in the first sitting gets the same ~12 builds at 1 h, so a stronger discount buys nothing there and costs a bigger
head start; reaching further up the levels (6, 8, 10) multiplies the head start (up to 10.8 days for a casual player) without improving the first hour. Taking the first three
levels at 0.5 to 0.83 is the mildest of the family that still gets the first sitting to the stock limit (11.4 of 12) and gives the best first-hour gain per day of head start.
Lowering `timeGrowth` does nothing for the first hour (9.0 builds) and shifts the mid game by 2 to 3 days: the wrong shape. Lowering base times would likewise act on
every level, not on the part that is slow.
**Not changed, and the bigger lever for a player who plays the whole first hour:** the starting stock. 750 of each is gone after about 12 builds, so the *quiet* part of the
first hour comes from resources, not time. Measured as information only (`--set START.resources.fiber=1000` and the same for hardware and capital, no discount, seeds 1+2):
a 60-minute first sitting gets 15.4 builds at 1 h (against 12.1) and 22.0 at 24 h (18.9), `--always-on` gets 18.6 at 6 h and 29.3 at 24 h (15.6 and 25.9), and the mid game does not
move at all (head start 0.0 to 0.1 days at 2 and 4 sittings a day, default mix field level 7.26 / 13.23 / 18.71 against 7.28 / 13.28 / 18.78) because a sitting-limited player never runs
out of stock. The same bots at 4 a day with the standard 20-minute first sitting get *fewer* builds at 1 h (7.9 against 8.9) because with more stock they pick dearer infrastructure first.
That is a cheap lever for engaged players, but it is a different number than the one asked about, so it was not adopted; it is the next thing to try if the owner still finds
the first hour slow after B4.
Side effects: a Core router level 2 or 3 now takes 0.67 / 0.83 of its time (the Core router counts like any building: Core router 2 and 3 are among the levels covered), so the second build slot opens a little earlier
(Core router 10 median day 17.3 -> 16.2); new POPs' early levels are quicker as well. Everything is data; `rules.js` only reads the two constants.
## 4. Found, not changed ## 4. Found, not changed
Each item: what the runs show, the run to reproduce it, and why nothing was tuned. Each item: what the runs show, the run to reproduce it, and why nothing was tuned.
@ -417,3 +518,9 @@ against the full static defence, so attacks cannot be added up); once the allian
- `--always-on` is an upper bound on attention, not a model of a person. - `--always-on` is an upper bound on attention, not a model of a person.
## B5. Start stock 750 -> 1000 of each (owner playtest, 2026-10-11)
After B4 the owner's first hour on the live world was still described as "a bit slow". B4's own measurement (variant "START.resources 1000", no discount) showed
the mid game unchanged (head start 0 to 0.1 days) and a 60-minute first sitting going from 12.1 to 15.4 builds at 1 h, so `START.resources` is now 1000 per
resource. Not re-measured in combination with B4 beyond a 50 x 30-day bot run that ended INVARIANTS OK. No human data.

View file

@ -252,3 +252,15 @@ client reads the constant. See BALANCE.md section 5.
`events/return.js` stayed silent for empty-carrier return legs AND for shipments that came home with cargo; cargo above the Rack hall cap is `events/return.js` stayed silent for empty-carrier return legs AND for shipments that came home with cargo; cargo above the Rack hall cap is
dropped on arrival, so that loss was invisible. Link legs that carry cargo now send `movement_returned` with `cargoLost` dropped on arrival, so that loss was invisible. Link legs that carry cargo now send `movement_returned` with `cargoLost`
(`test/bot-server-fixes.test.js`). Found by the harness's conservation ledger (BALANCE.md section 6, S1). (`test/bot-server-fixes.test.js`). Found by the harness's conservation ledger (BALANCE.md section 6, S1).
## B4 — Early-level build discount (`FORMULAS.earlyLevels` 3, `earlyTimeFactor` 0.5), first hour and first day
Owner playtest at speed 1: "a bit slow for the first hour". The harness (new `stats.early`: builds and Core router 1/6/24 h after joining, from the `buildDone` events)
showed two separate things. A player who plays only the 20-minute first sitting is limited by build time (8.9 builds at 1 h at any cadence); a player who plays the whole
first hour is limited by the starting stock (750 each pays for about 12 builds, income is ~90 an hour in all). A time change can only help the first group and moves the stall
earlier for the second. Chosen: building up to level L takes `f + (1 - f) * (L - 1) / n` of the normal time for L <= n (0.5, 0.67, 0.83 for levels 1 to 3, full from 4), read by
`rules.buildTimeMs` only, so `buildPlan`, the server and the client's time line agree and the balance stays in `data.js`. It is a ramp, not a flat factor, so there is no cliff at level n + 1.
Result (BALANCE.md B4): builds at 1 h 8.9 -> 11.4, at 24 h 16.5 -> 20.4 at 4 sittings a day; mid game is a head start of ~1 day (4 a day) to ~3.6 days (2 a day), not a
different slope (default mix field level +2 % on day 30, +0.1 % on day 60; 2 a day +9 % and +5 %). Lowering `timeGrowth` (1.12) and reaching further up the levels (6 to 10)
were measured and dropped: the first does nothing for the first hour and shifts the mid game, the second multiplies the head start (up to ~11 days) for no first-hour gain.
Not done, and probably the bigger lever for an engaged player: a higher starting stock (1000 of each moved the mid game by 0 days and gave a 60-minute first sitting 15.4 builds at 1 h
instead of 12.1). Left for the owner to call.

View file

@ -79,8 +79,8 @@ One build slot per POP, a second from Core router 3 (`FORMULAS.secondQueueCoreLe
| Rollout depot | Trains Rollout crews (settlers) and M&A teams. Requires Core router 10. | | Rollout depot | Trains Rollout crews (settlers) and M&A teams. Requires Core router 10. |
| Backbone node | Only on backbone landing sites. The end-game building (see below). | | Backbone node | Only on backbone landing sites. The end-game building (see below). |
Costs: `cost(L) = base_cost * 1.28^(L-1)` per resource. Times: `time(L) = base_time * 1.16^(L-1) / corerouter / Costs: `cost(L) = base_cost * 1.28^(L-1)` per resource. Times: `time(L) = base_time * 1.16^(L-1) * early(L) / corerouter /
speed`. Base costs/times per building in `data.js`. Every building level adds 1 power draw per level speed`, where `early(L)` is 0.5, 0.67, 0.83 for levels 1 to 3 and 1 from level 4 (`FORMULAS.earlyLevels` / `earlyTimeFactor`, BALANCE.md B4: the first levels are quick so the first hour is not a wait). Base costs/times per building in `data.js`. Every building level adds 1 power draw per level
(resource producers 0, so expansion is never power-negative on its own). (resource producers 0, so expansion is never power-negative on its own).
**Footprint:** every building level produces footprint points per day (1 + L/5). Founding or taking over a POP **Footprint:** every building level produces footprint points per day (1 + L/5). Founding or taking over a POP

View file

@ -8,21 +8,21 @@ WebSocket push); stage 7 is partly done (bot harness + first balance pass, admin
playtested by humans, and has never run on the real target (Debian LXC + systemd + nginx Proxy Manager).** playtested by humans, and has never run on the real target (Debian LXC + systemd + nginx Proxy Manager).**
Runnable and checked just now: Runnable and checked just now:
- `npm test`: 207 tests pass in about 7 s (rules as pure functions, commands/events/scheduler with a fake clock, REST over HTTP with every - `npm test`: 208 tests pass in about 7 s (rules as pure functions, commands/events/scheduler with a fake clock, REST over HTTP with every
response checked against its schema, push with a real `ws` client, client logic, bot harness, admin CLI). `npm run openapi` leaves response checked against its schema, push with a real `ws` client, client logic, bot harness, admin CLI). `npm run openapi` leaves
`docs/openapi.json` unchanged (it is in sync with the route table: 68 paths). `docs/openapi.json` unchanged (it is in sync with the route table: 68 paths).
- `node tools/bot.js --players 50 --days 14 --speed 1`: about 3 s, `INVARIANTS OK`. `node tools/admin.js help` works. - `node tools/bot.js --players 50 --days 14 --speed 1`: about 3 s, `INVARIANTS OK`. `node tools/admin.js help` works.
- The deploy path from DEPLOY.md in a scratch directory, without systemd: first boot (migrations, world), `/healthz`, signup, a build, - The deploy path from DEPLOY.md in a scratch directory, without systemd: first boot (migrations, world), `/healthz`, signup, a build,
`admin.js` status/worlds/users/inspect/events/replay/backup/verify-backup/ban/grant, SIGTERM + restart (state kept), SIGKILL + restart `admin.js` status/worlds/users/inspect/events/replay/backup/verify-backup/ban/grant, SIGTERM + restart (state kept), SIGKILL + restart
after a build fell due (caught up in order), restore of a snapshot into a fresh `DB_PATH`. after a build fell due (caught up in order), restore of a snapshot into a fresh `DB_PATH`.
- `npm run e2e` (`e2e/run.js`, Playwright): see the e2e section of this file, if present; not re-run for this status. - `npm run e2e` (`e2e/run.js`, Playwright): 61 checks pass (re-run after B4, 54 s).
Never run: real devices, Safari/iOS, a Proxmox LXC, a unit under systemd, the backup timer firing, nginx Proxy Manager (WebSocket upgrade, Never run: real devices, Safari/iOS, a Proxmox LXC, a unit under systemd, the backup timer firing, nginx Proxy Manager (WebSocket upgrade,
idle timeouts, real client IPs), Let's Encrypt, a restore on the real box, load with many real sockets, any human player. Node 22.13 (the idle timeouts, real client IPs), Let's Encrypt, a restore on the real box, load with many real sockets, any human player. Node 22.13 (the
stated minimum) was not run, only 24.21. stated minimum) was not run, only 24.21.
Known gaps, consolidated (the sections below have the detail and the reasoning): Known gaps, consolidated (the sections below have the detail and the reasoning):
- **Balance:** nothing is tuned beyond B1/B2 (BALANCE.md). Open: a 3x world's end game is as long as a 1x world's; after the opening days - **Balance:** the first hour of a player who plays it all is limited by the 750 starting stock (about 12 builds), not by build time; a bigger stock was measured and not adopted (B4). nothing is tuned beyond B1, B2 and the B4 early-level build discount (BALANCE.md). Open: a 3x world's end game is as long as a 1x world's; after the opening days
nobody can contest a built-up landing site (no garrisons, E1); raid loot is split evenly and destroyed on overflow (S4); trade escrow nobody can contest a built-up landing site (no garrisons, E1); raid loot is split evenly and destroyed on overflow (S4); trade escrow
refunds are clipped at the Rack hall cap without a notice (S2); the capital runs out of things to build long before the backbone opens; refunds are clipped at the Rack hall cap without a notice (S2); the capital runs out of things to build long before the backbone opens;
the bots are not humans. the bots are not humans.
@ -222,7 +222,7 @@ one tick are merged. Small edits outside the new files: `scheduler.js` (outbox,
Tests: `test/push-ws.test.js` (auth ok/bad/timeout, origin, path, per-IP cap and its release, rate limit, bad budget, oversize frame, dead Tests: `test/push-ws.test.js` (auth ok/bad/timeout, origin, path, per-IP cap and its release, rate limit, bad budget, oversize frame, dead
socket, revoked token, banned user, shutdown, REST with no socket) and `test/push-game.test.js` (build/train done, incoming only to the socket, revoked token, banned user, shutdown, REST with no socket) and `test/push-game.test.js` (build/train done, incoming only to the
defender, report/message/alliance invite hints, recall, coalescing, rollback). Real `ws` client, fake clock, port 0. `npm test`: 113 pass defender, report/message/alliance invite hints, recall, coalescing, rollback). Real `ws` client, fake clock, port 0. `npm test`: 113 pass
when this was written (207 on 2026-10-11, whole suite). when this was written (208 on 2026-10-11, whole suite).
Not done / not claimed: Not done / not claimed:
- The client now exists (`public/js/ws.js`, see "Client: military, expansion, WebSocket") and was run against this server in a headless browser; not through a proxy. - The client now exists (`public/js/ws.js`, see "Client: military, expansion, WebSocket") and was run against this server in a headless browser; not through a proxy.
- Revocation closes the socket at the next ping tick (default 30 s), not instantly: `POST /auth/logout` and token deletion do not call push. - Revocation closes the socket at the next ping tick (default 30 s), not instantly: `POST /auth/logout` and token deletion do not call push.
@ -286,5 +286,5 @@ Not done / not claimed: nothing of it has run under systemd or on Debian 13 (DEP
world lifecycle through the CLI is partial (above); no scheduled "create next world". world lifecycle through the CLI is partial (above); no scheduled "create next world".
## Not done ## Not done
- Stage 7 remainder: balance passes beyond B1/B2 with the open items above, a real world lifecycle (start, natural end, reset) driven from the CLI, - Stage 7 remainder: balance passes beyond B1, B2 and B4 with the open items above, a real world lifecycle (start, natural end, reset) driven from the CLI,
load test over HTTP/WebSocket, the full e2e suite and a human playtest. Everything else in CLAUDE.md "Working in stages" is built. load test over HTTP/WebSocket, the full e2e suite and a human playtest. Everything else in CLAUDE.md "Working in stages" is built.

View file

@ -21,6 +21,8 @@
productionGrowth: 1.25, productionGrowth: 1.25,
costGrowth: 1.28, costGrowth: 1.28,
timeGrowth: 1.16, timeGrowth: 1.16,
earlyLevels: 3, // early-level build discount (docs/BALANCE.md B4): levels 1..earlyLevels are quicker; 0 = off
earlyTimeFactor: 0.5, // build time of level 1 = this x the formula time, rising evenly to x1 at level earlyLevels + 1 (was 1, i.e. none)
storageBase: 1000, // Rack hall level 1 storageBase: 1000, // Rack hall level 1
storageGrowth: 1.22, storageGrowth: 1.22,
batteryBase: 200, // Battery bank level 1, in power points batteryBase: 200, // Battery bank level 1, in power points
@ -74,7 +76,7 @@
const START = { const START = {
fieldLevel: 1, fieldLevel: 1,
infra: { core_router: 1, rack_hall: 1, battery_bank: 1 }, infra: { core_router: 1, rack_hall: 1, battery_bank: 1 },
resources: { fiber: 750, hardware: 750, capital: 750 }, resources: { fiber: 1000, hardware: 1000, capital: 1000 },
battery: 100, battery: 100,
loyalty: 100, loyalty: 100,
// Wild slots: the two wild fields get these types unless the signup picks (stage 1: fixed, stage 4 lets you choose) // Wild slots: the two wild fields get these types unless the signup picks (stage 1: fixed, stage 4 lets you choose)

View file

@ -197,10 +197,19 @@
function coreLevel(town) { const c = town.buildings.core_router; return c ? c.level : 0; } function coreLevel(town) { const c = town.buildings.core_router; return c ? c.level : 0; }
// Build time in ms to reach `level`. Core router shortens it; world speed divides it. // Early-level discount on build time (data: F.earlyLevels, F.earlyTimeFactor; docs/BALANCE.md B4). Building up to level L takes
// earlyTimeFactor x the normal time for L = 1, rising evenly to the full time at level earlyLevels + 1; from there on nothing changes.
// earlyLevels 0 (or a factor of 1) switches it off.
function earlyTimeFactor(level) {
const n = F.earlyLevels || 0, f = F.earlyTimeFactor == null ? 1 : F.earlyTimeFactor;
if (!(n > 0) || level > n) return 1;
return f + (1 - f) * (level - 1) / n;
}
// Build time in ms to reach `level`. Core router shortens it; world speed divides it; the first levels get the early discount.
function buildTimeMs(type, level, core, speed) { function buildTimeMs(type, level, core, speed) {
const def = buildingDef(type); const def = buildingDef(type);
const secs = def.time * Math.pow(F.timeGrowth, level - 1) / (1 + F.coreSpeedPerLevel * core) / (speed || 1); const secs = def.time * Math.pow(F.timeGrowth, level - 1) * earlyTimeFactor(level) / (1 + F.coreSpeedPerLevel * core) / (speed || 1);
return Math.max(F.minBuildMs, Math.round(secs * 1000)); return Math.max(F.minBuildMs, Math.round(secs * 1000));
} }
@ -778,7 +787,7 @@
unitDef, unitCount, costValue, unitValue, researchKey, researchLevel, researchMult, unitStat, unitCost, trainTimeMs, unitMissing, trainPlan, researchCost, researchTimeMs, researchSpeedBonus, researchPlan, slowestSpeed, movementMs, transportMs, checkUnitsForType, isProtected, firewallMult, effectiveFirewall, attackPower, defencePower, applyLoss, resolveBattle, battlePoints, cacheFraction, lootSplit, carryOf, siegeLevels, loyaltyDrop, takeoverBlock, footprintGate, settleCheck, cleanWild, newTownBuildings, scanStrength, resolveScan, incumbentDefence, decommissionMs, decommissionPlan, transportLinks, transportPlan, rng, hash, distance, tileAt, ruralNear, ruralBonus, pickSpawn, unitDef, unitCount, costValue, unitValue, researchKey, researchLevel, researchMult, unitStat, unitCost, trainTimeMs, unitMissing, trainPlan, researchCost, researchTimeMs, researchSpeedBonus, researchPlan, slowestSpeed, movementMs, transportMs, checkUnitsForType, isProtected, firewallMult, effectiveFirewall, attackPower, defencePower, applyLoss, resolveBattle, battlePoints, cacheFraction, lootSplit, carryOf, siegeLevels, loyaltyDrop, takeoverBlock, footprintGate, settleCheck, cleanWild, newTownBuildings, scanStrength, resolveScan, incumbentDefence, decommissionMs, decommissionPlan, transportLinks, transportPlan, rng, hash, distance, tileAt, ruralNear, ruralBonus, pickSpawn,
terrainAt, backboneSites, backboneSiteAt, isBackboneSite, worldAgeDays, worldPhase, tradeReach, tradeRatioOk, tradeTermsCheck, tradeInRange, terrainAt, backboneSites, backboneSiteAt, isBackboneSite, worldAgeDays, worldPhase, tradeReach, tradeRatioOk, tradeTermsCheck, tradeInRange,
backboneDefence, backboneCost, backboneTimeMs, backbonePlan, backboneDefence, backboneCost, backboneTimeMs, backbonePlan,
buildingDef, isFieldKey, fieldLayout, buildingCost, coreLevel, buildTimeMs, queueSlots, storageCap, batteryCap, buildingDef, isFieldKey, fieldLayout, buildingCost, coreLevel, buildTimeMs, earlyTimeFactor, queueSlots, storageCap, batteryCap,
fieldOutputPerHour, ratesPerHour, resourcesAt, batteryEmptyAt, unitsOnline, footprintPerDay, footprintAt, fieldOutputPerHour, ratesPerHour, resourcesAt, batteryEmptyAt, unitsOnline, footprintPerDay, footprintAt,
allianceCap, allianceCan, roleRank, outranks, diplomacyMove, pactCancelMs, allianceCap, allianceCan, roleRank, outranks, diplomacyMove, pactCancelMs,
footprintNeeded, loyaltyAt, buildPlan, initialBuildings, latencyMs, footprintNeeded, loyaltyAt, buildPlan, initialBuildings, latencyMs,

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.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.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.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 }); 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.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)'); 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); 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', () => { 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.deepEqual(R.tileAt(7, 50, 10, 10), R.tileAt(7, 50, 10, 10));
assert.equal(R.tileAt(7, 50, 51, 0).type, 'void'); assert.equal(R.tileAt(7, 50, 51, 0).type, 'void');

View file

@ -47,6 +47,7 @@ function render(s, opts) {
Object.keys(u).sort().map((k) => k.replace(/_.*/, '') + ':' + fmt(u[k], 0)).join(' ')]); Object.keys(u).sort().map((k) => k.replace(/_.*/, '') + ':' + fmt(u[k], 0)).join(' ')]);
} }
out.push(table(prow, ['day', 'field avg', 'core p10/50/90', 'footprint p10/50/90', 'operators >=2 POPs', 'over gate', 'units alive'])); out.push(table(prow, ['day', 'field avg', 'core p10/50/90', 'footprint p10/50/90', 'operators >=2 POPs', 'over gate', 'units alive']));
if (s.early) out.push('first hours after signing up, capital, mean (p10/50/90) over operators at least that old: ' + Object.keys(s.early).map((k) => { const e = s.early[k]; return k + ': ' + e.builds + ' builds (' + e.buildsP.p10 + '/' + e.buildsP.p50 + '/' + e.buildsP.p90 + '), Core router ' + e.core + ' (n=' + e.n + ')'; }).join('; '));
const f = s.final; const f = s.final;
out.push('time to Core router 10 (days after joining): ' + pc(f.core10Days, 'p10') + '/' + pc(f.core10Days, 'p50') + '/' + pc(f.core10Days, 'p90') + ' (reached by ' + f.core10Reached + ' of ' + m.players + ')'); out.push('time to Core router 10 (days after joining): ' + pc(f.core10Days, 'p10') + '/' + pc(f.core10Days, 'p50') + '/' + pc(f.core10Days, 'p90') + ' (reached by ' + f.core10Reached + ' of ' + m.players + ')');
out.push('time to first expansion (days after joining): ' + pc(f.firstExpansionDays, 'p10') + '/' + pc(f.firstExpansionDays, 'p50') + '/' + pc(f.firstExpansionDays, 'p90') + ' (reached by ' + f.firstExpansionReached + ' of ' + m.players + ')'); out.push('time to first expansion (days after joining): ' + pc(f.firstExpansionDays, 'p10') + '/' + pc(f.firstExpansionDays, 'p50') + '/' + pc(f.firstExpansionDays, 'p90') + ' (reached by ' + f.firstExpansionReached + ' of ' + m.players + ')');

View file

@ -76,6 +76,26 @@ function build(x) {
}; };
} }
// ---- first hours: what an operator had built N hours after signing up (only operators that are at least that old at the end).
// Counted from the buildDone events of the capital, so it needs no extra sampling. Builds = levels gained (one level per build).
const early = {};
const capOf = new Map(db.all('SELECT owner_id AS oid, MIN(id) AS tid FROM towns GROUP BY owner_id').map((r) => [r.oid, r.tid]));
const doneByTown = new Map();
for (const r of db.all("SELECT town_id AS tid, due_at AS at, json_extract(payload, '$.type') AS type, json_extract(payload, '$.toLevel') AS lvl FROM events WHERE type = 'buildDone' AND status = 'done' ORDER BY due_at, id")) {
(doneByTown.get(r.tid) || doneByTown.set(r.tid, []).get(r.tid)).push(r);
}
for (const h of [1, 6, 24]) {
const builds = [], cores = [], fieldBuilds = [];
for (const op of ops) {
if (op.created_at + h * 3600000 > now || !capOf.has(op.id)) continue;
const list = (doneByTown.get(capOf.get(op.id)) || []).filter((e) => e.at <= op.created_at + h * 3600000);
builds.push(list.length);
fieldBuilds.push(list.filter((e) => D.BUILDINGS[e.type] && D.BUILDINGS[e.type].kind === 'field').length);
cores.push(Math.max(D.START.infra.core_router || 1, ...list.filter((e) => e.type === 'core_router').map((e) => e.lvl)));
}
early[h + 'h'] = { n: builds.length, builds: round(mean(builds), 1), buildsP: percentiles(builds, [10, 50, 90]), fieldBuilds: round(mean(fieldBuilds), 1), core: round(mean(cores), 2), coreP: percentiles(cores, [10, 50, 90]) };
}
// ---- combat summary // ---- combat summary
const raid = col.battles.raid; const raid = col.battles.raid;
const samples = col.raidSamples; const samples = col.raidSamples;
@ -157,7 +177,7 @@ function build(x) {
}; };
return { return {
meta, invariants, days, meta, invariants, days, early,
final: { levels: Object.fromEntries(Object.keys(levels).map((k) => [k, { mean: round(mean(levels[k]), 2), hist: histogram(levels[k], 20) }])), fieldMin: percentiles(fieldMins, [10, 50, 90]), final: { levels: Object.fromEntries(Object.keys(levels).map((k) => [k, { mean: round(mean(levels[k]), 2), hist: histogram(levels[k], 20) }])), fieldMin: percentiles(fieldMins, [10, 50, 90]),
pops: popsDist, footprint: percentiles(footprints, [10, 50, 90]), core10Days: percentiles(core10, [10, 50, 90]), core10Reached: core10.length, firstExpansionDays: percentiles(expand1, [10, 50, 90]), firstExpansionReached: expand1.length, pops: popsDist, footprint: percentiles(footprints, [10, 50, 90]), core10Days: percentiles(core10, [10, 50, 90]), core10Reached: core10.length, firstExpansionDays: percentiles(expand1, [10, 50, 90]), firstExpansionReached: expand1.length,
milestones: Object.fromEntries(Object.entries(milestones).map(([k, v]) => [k, { core10Days: percentiles(v.core10, [10, 50, 90]), firstExpansionDays: percentiles(v.exp1, [10, 50, 90]) }])), milestones: Object.fromEntries(Object.entries(milestones).map(([k, v]) => [k, { core10Days: percentiles(v.core10, [10, 50, 90]), firstExpansionDays: percentiles(v.exp1, [10, 50, 90]) }])),