Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ down**, and after `npm run fixtures` **read the diff**. See

## State layer (`src/lib/state/`, Svelte 5 runes)

Six singleton classes, each exported as a ready-made instance, split by what the
Seven singleton classes, each exported as a ready-made instance, split by what the
state **is** rather than by which component reads it. They reference each other
directly rather than through events/props — this is a small enough app that
singletons + direct calls are the whole store layer. What keeps that from
Expand All @@ -228,7 +228,8 @@ becoming a knot is that the references form a **strict DAG**:
```
layout -> (nothing) config -> (nothing)
viewport -> (nothing) editor -> layout
solver -> config, layout ui -> config, layout, solver, viewport
solver -> config, layout timeline -> config, layout
ui -> config, layout, solver, timeline, viewport
```

## Assets and the deployed base
Expand Down
29 changes: 24 additions & 5 deletions docs/SOLVER.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,18 @@ the unchanged search across three seeds, because `powerPerTile` orders a greedy
later stages rewrite, so skewing it toward the coast mostly changes which tiles are claimed first.
Don't re-attempt either without a wider measurement.

**What did pay is a second seed with the top reactor one tier down** (`TIER_STEP`, the ×1.25 every
reactor steps by), rewritten in the real roster's buildings and kept when it stabilizes higher —
the move an upgrade plan already makes with today's tiers, and how it was found: a player's plan
run beat their plain one. On their board (Tidal legacy plus research) that seed stabilizes at
15.39AD against 13.95AD and wins every attempt; over 48 attempts at 20s the median rose from
19.58–19.63AD to 19.69–19.74AD and the worst from 19.32–19.41AD to 19.42–19.53AD, the best
unchanged. On the shipped maps it wins the seed comparison on every main island and moves nothing at the end:
maps 3, 5–8 under both Tidal variants, 30 attempts each, medians within ±0.04AD in both directions;
under the base rules the same, and on the player's board with the anomaly off the runs were
identical. So it is gated to a terrain bonus, where it was measured to help, and costs one seed
construction there; a plan run already has its own second seed and skips it.

`role_isolation` is resolved in `simulateIsland`, the one place a whole layout is in hand. It
copies the placement into `ctx.ratedLayout` — held by the island, not allocated per call — re-rates
the affected role's tiles and reads every figure through that. Two details are load-bearing: the
Expand Down Expand Up @@ -857,10 +869,10 @@ Import dialog to see the board.
code writer all three paths go through and it always passes `blueprintRules`, so the app's preview
rates a CLI layout the way the run did rather than under the reader's own timeline — a
coast-hugging Tidal board would otherwise come back at roughly its baseline figure with nothing
saying why. The research table it writes is **empty rather than absent**, which is a different
claim and a true one: the CLI solves at full unlocks and no Time Lab, and there is no flag for one,
so "the author had no research" is exactly what it knows, where an absent section would mean "rules
unknown". `--anomaly` also tags the filename (`test_4_tidal_ascendancy.txt`) and every header names
saying why. The research table it writes is the run's: a `--code` board's own, otherwise **empty
rather than absent**, which is a different claim and a true one — a shipped map is solved with no
Time Lab, so "the author had no research" is exactly what it knows, where an absent section would
mean "rules unknown". `--anomaly` also tags the filename (`test_4_tidal_ascendancy.txt`) and every header names
the timeline, because a `solves/` directory or a session scrollback holding three timelines is
otherwise unreadable from the outside — the same argument `formatNumberForFilename` makes about the
power figure. The tag is the full id, so a filename pastes straight back into the flag that
Expand All @@ -869,7 +881,14 @@ matches the optional tail, since that regex is what finds the previous ids: a ta
could not see would restart numbering at 1 and overwrite an untagged run.

`--attempts` runs a batch session: N whole solves through a worker pool, with a leaderboard of
distinct layouts at the end. Ctrl-C stops it and still prints the report.
distinct layouts at the end and the worst, median and best of every attempt — the spread is what
tells two settings apart when both reach the same best. Ctrl-C stops it and still prints the report.

Three flags reproduce a player's setup rather than a shipped one. `--code BLUEPRINT` solves a
pasted board, taking its anomaly (unless `--anomaly` is given) and its Time Lab research from the
code's rules section. `--tier ID=LEVEL` holds a building below its last tier, and `--plan
ID=LEVEL` adds an upgrade-plan step, in buying order and resolved by `resolveUpgradePlan` exactly
as the app does; both count levels from 1, like the app's tier buttons.

Cores are spent on two axes and the flags pick which. A **run** farms its islands out to the pool,
each with its own slice (`islandBudgetsS`) of the budget. When every island has a worker of its
Expand Down
80 changes: 79 additions & 1 deletion docs/game-export.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,12 @@ Primitive encodings (what .NET's `BinaryWriter` writes, UTF-8):
| `int16` | 2, little-endian, signed |
| `uint16` | 2, little-endian |
| `int32` | 4, little-endian, signed |
| `int64` | 8, little-endian, signed |
| `double` | 8, IEEE 754, little-endian |
| `string` | 7-bit-encoded length (LEB128), then that many UTF-8 bytes |

Six sections, always present, always in this order:
Seven sections, always present, always in this order (section 7 since game
1.1.11; an older code ends after section 6):

| # | Section | Contents |
| --- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------- |
Expand All @@ -140,6 +143,7 @@ Six sections, always present, always in this order:
| 4 | Research | `uint16` count · per `ResearchSO`, all domains: `string` research id · `uint16` level |
| 5 | Research in progress | `uint16` count · per entry: `string` research id · `uint16` level it will reach · `int32` seconds left |
| 6 | Obstacles being cleared | `uint16` count · per entry: `int16` x · `int16` y · `int32` seconds left |
| 7 | Timeline | see 4.5 |

Rules:

Expand Down Expand Up @@ -197,6 +201,46 @@ y = minY + 1 : grass cooler2 generator7

has the cell bytes `00 01 02 01 07 08`.

### 4.5 Timeline

Where the player's timeline stands, for the optimizer's Chronon tools. In this
order:

| Field | Type | Meaning |
| ------------------- | --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| Exported at | `int64` | Moment of export, Unix seconds, UTC: server time once the game has synced, the device clock otherwise |
| Chronon balance | `int64` | Chronons held, unspent |
| Timeline energy | `double` | `TimelineEnergyProduced`, online + offline: the `E` of the award |
| Timeline elapsed | `int64` | Seconds since the timeline began, on the game's internal clock |
| Jump award now | `int64` | The game's own award for a jump now, **without** the first-entry bonus; 0 at zero energy |
| Anomalies entered | `uint16` count · count × `string` | Anomalies whose first-entry bonus is spent. Always `tidal_ascendancy`, never `tidal_ascendancy_legacy`: the bonus belongs to the anomaly |
| Timeline generation | `int32` | Time Jumps completed, 0 before the first |
| Cash | `double` | The raw signed balance: negative while building on credit |
| Research points | `double` | Research points held |
| Stamp source | `byte` | Which clock wrote "Exported at": 0 server time, 1 the device clock (the game had not synced) |

Cash and research points were appended after the first samples, and the stamp
source after them, so a code that ends at any of those fields is a valid, older
section 7. Cash goes **below zero** on
build credit: a purchase is allowed while `cash − cost ≥ −limit`, the limit set by
the Build Credit research in section 4. The caps on both balances also come from
research, and are multiplied while Rush Hour runs.

The award, as the developer gave it:

```
Chronons = max(1, floor(97.34 × (E / 2.82e16)^0.135 × M)) + B
```

`M` is the Chronon Reactor multiplier (its level is in section 4), `B` is 88
on the first entry into an anomaly and 0 otherwise. A jump is allowed once the
award without `B` reaches `min(5000, round(88 × 1.15^generation))`, midpoint
rounded away from zero.

For a save older than the Time Jump feature that has not jumped yet, timeline
energy and elapsed are counted from its first launch after that update; the
two still agree, so energy per second is right.

## 5. Versioning

- The format version is the digit in the `R2X1.` prefix.
Expand Down Expand Up @@ -235,6 +279,40 @@ first three real exports came to 2,347–2,460 characters.
The roster also lists `research_building_tidal_plant`, a building the
optimizer does not carry yet. The reader matches ids exactly and skips unknown
ones.
- **The 1.1.11 timeline samples** are in `tests/gameExports/` as
`gen<jumps>_<anomaly>_city<level>.txt`, the third round, ending with the
clock byte. A `_server` file is the same save stamped by server time (the
editor's sync fed from an NTP clock), the rest by the device clock.
`owner_editor_save` is kept from the second round as the one real code that
ends at research points. Each one's jump award matches the formula in 4.5.
One of them, `gen1_cryo_city41`, has a building on the transformer cell of
areas 6, 7 and 8; the importer drops those three.
- **The power is right to under 100 parts per million.** `gen2_city52_9c43e4b7`
is a player's save, exported repeatedly with the same boards. The energy the
game added between two exports, over the time between, is its real rate, and
the simulator's power for those boards, as energy per 3-second tick, lands
within 25–66 ppm of it whenever the gap was offline. `editor_current_save`,
the same save after some play in the editor, comes out 229 ppm slower: the
online tick drift below, measured.
- **An editor export runs about 10 s ahead.** On that same save the projected
next Chronon arrived 10–11 s before the game's, with the browser's clock
correct. The code came from the developer's Unity editor, which loaded the
save and credited its offline income by its own game clock — and the game's
anti-tampering can hold that clock off real time. So the editor's copy was 10
s ahead of the player's phone, and the projection was right for the copy it
was given. A player's own export has energy and stamp from one copy, so the
stamp should stay **server time**: that is the real moment the energy
describes, where a game-clock stamp would carry the anti-tampering offset into
every projection. The weak spot is the unsynced fallback to the device clock.
- **The game runs slow while it is open (a game bug, being fixed).** Its
production tick waits 3 s after the previous one and the wait ends on the next
frame, so each tick runs a few milliseconds long: about 0.3% slow at 60 fps
(~10 s an hour), 0.5% at 30 fps, and more on frame hitches. Offline time is
counted in real time. So a projection on the real clock pulls ahead of the game
by that fraction of the time it has been open since the export — the
projection is right and the game drifts. The developer also suspects a short
focus loss credits the gap since the last autosave (every 15 s) rather than
since the pause. Neither is modelled here: both are the game's to fix.
- **A code can pick up stray characters when pasted.** One sample ended in a
stray `ś`. The reader drops anything outside the base64url alphabet before
decoding; a code damaged in the middle still fails, at the inflate.
Expand Down
26 changes: 23 additions & 3 deletions docs/game-logic.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,33 @@ apply them, and the cooling network. The in-game description text is not the
authority: several of its lines have more than one consistent reading, and where
it and the code differ, what is written here is the code.

### What a Time Jump pays

A jump pays Chronons for the energy the timeline produced, online and offline:

```
Chronons = max(1, floor(97.34 × (E / 2.82e16)^0.135 × M)) + B
```

`M` is the Chronon Reactor research's multiplier (×1.05 to ×1.25), and `B` is
88 the first time a timeline runs under a given anomaly, otherwise 0 — added
after the multiplier, not through it. At zero energy the award is 0. A jump is
allowed once the award without `B` reaches
`min(5000, round(88 × 1.15^jumps completed))`: 88, 101, 116, 134 …

**Layout power barely moves the count.** At an exponent of 0.135, doubling a
whole timeline's energy pays about 9.8% more Chronons; what layout power buys is
_when_ the next one arrives. The board's power is energy per 3-second tick.
`packages/solver/src/data/chronons.ts` holds the formula.

---

## Time Lab Research

Eleven researches exist; **three** of them change a building's figures, and the
other eight move research income, research time, Chronons, obstacle-removal
cost, energy sale price and building prices — all decided before a board is
Twelve researches exist; **three** of them change a building's figures, and the
other nine move research income, research time, Chronons, obstacle-removal
cost, energy sale price, building prices and the City level a timeline starts
at — all decided before a board is
laid out, so none can change which layout is best.

| research | scales | levels (×) |
Expand Down
43 changes: 38 additions & 5 deletions packages/solver/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ The app-side half — how `layoutState`, `configState`, `AnomalySelector` and

### Time Lab research

`PRESTIGE_UPGRADES` (`data/prestige.ts`) carries **three** of the game's eleven
`PRESTIGE_UPGRADES` (`data/prestige.ts`) carries **three** of the game's twelve
researches: Absolute Zero (cooler cooling), Infinite Grid (generator and wind
turbine stats) and Stellar Forge (reactor heat). The other eight move research
income, research time, chronons, obstacle-removal, energy sale price and
building prices — all
turbine stats) and Stellar Forge (reactor heat). The other nine move research
income, research time, chronons, obstacle-removal, energy sale price,
building prices and the City level a timeline starts at — all
decided _before_ the solver is handed a board, so none can change which layout
is best. The file names them so it is clear they were read and dismissed.

Expand Down Expand Up @@ -79,6 +79,39 @@ by `HeatProducerBuildingSO`. That is why Infinite Grid goes out of its way to
name turbines. The rule is "every heat producer", and a reactor is the only one
the game ships, so it is modelled as reactors.

### Building prices

`data/buildingPrices.ts` is what a building costs in the game: `base ×
scaler^copies × (1 − Construction Permits) × (1 − Quantum Replicator)`, the
copies counted across all islands and the scaler 1.14 until Standardized Builds
lowers it, and a sale refunds Salvage Protocols' share of the **current** price.
The research tables are hand-transcribed from `tools/data/progression.json`;
the base prices are the catalogue's `price`. Salvage Protocols' level 0 (50%) is
an assumption — the record starts at level 1 — and says so. The rules were
confirmed by the player; moves are free.

### The Time Lab table

`data/timeLab.ts` carries all twelve Time Lab researches with each level's
Chronon cost — the planner's price list — where `PRESTIGE_UPGRADES` carries only
the three a layout feels. Hand-transcribed from the extractor's record like that
table; where the two overlap they must agree, which `tests/timeLab.test.ts`
enforces, and Chronon Reactor's values must match `chronons.ts`'s multiplier
(kept apart there to avoid an import cycle). `gameId` is the key a game export
files a research under — the extractor's id for all but Chrono Seed, which
exports as `TimeLabSkipCityResearchSO`.

### Chronons

`data/chronons.ts` is the one place the game's Chronon award lives: the formula,
its inverse (`energyForAward`), the jump threshold by generation, the first-entry
bonus and `projectTimeline`, which runs a game export's section 7 forward from its
`exportedAt`. Chronon Reactor's multiplier is carried there rather than in
`PRESTIGE_UPGRADES`, which holds only research a layout can feel. Island power is
energy **per tick** (`TICK_SECONDS` = 3). `tests/chronons.test.ts` holds the
formula to the award the game wrote into every 1.1.11 sample, and the projection
to a live reading taken on a player's save.

### Anomalies

Prestiging also picks an **anomaly** that changes the rules for the whole next
Expand Down Expand Up @@ -423,7 +456,7 @@ CoolingPerSec` — it is what a cooler is worth and what the game shows for it,
they are bought with Chronons, survive a Time Jump, and stack with whatever
anomaly is running — **multiplicatively**, so a generator under Singularity
Isolation with Infinite Grid maxed is rated x8. The extractor's record covers
all eleven Time Lab upgrades; the three a layout can see are **Stellar Forge**
all twelve Time Lab upgrades; the three a layout can see are **Stellar Forge**
(every heat producer, so reactors), **Infinite Grid** (generators _and_ wind
turbines), and **Absolute Zero** (every cooler), each ten levels of
`BonusPercentage`. Absolute Zero and Infinite Grid share one curve, 0.1 to 1.0
Expand Down
12 changes: 12 additions & 0 deletions packages/solver/bin/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,18 @@ export function printSessionReport(report: SessionReport): void {
if (rules) console.log(rules);
console.log(rule);
console.log(`Estimated max: ${formatNumberPair(report.estimatedMaxPower)}`);
// The spread, not only the best: the top layouts say what a session *can*
// find, and two settings that both reach the same best can still differ in
// how often they get there.
if (report.powers.length) {
const sorted = [...report.powers].sort((a, b) => a - b);
const median = sorted[Math.floor((sorted.length - 1) / 2)];
console.log(
`Attempts: ${sorted.length} | worst ${formatNumberPair(sorted[0])}` +
` | median ${formatNumberPair(median)}` +
` | best ${formatNumberPair(sorted[sorted.length - 1])}`,
);
}

if (!report.top.length) {
console.log("\nNo attempts completed.\n");
Expand Down
Loading
Loading