Fix V2 canonical item names + rewrite README

Synced engine tables.rs to Immolate display strings so UI<->engine FNV
hashes match. Previously the UI sent 'Riff-raff', 'Mr. Bones',
'Oops! All 6s', 'Mail-In Rebate', "Driver's License", 'Top-up Tag',
"Director's Cut" while the engine pools held stripped-punctuation
versions, so Op::HasJoker never matched and the V2 filter rejected
every seed (5M/s, 0 hits).

Also fixes Stuntman (now Uncommon) / Vampire (now Rare) rarities to
match Immolate items.cl J_U_BEGIN..J_R_END blocks.

Regenerated both WASM bundles (scalar + SIMD) and vendored to web/public.
Full README rewrite covering current state, filter DSL, and honest gaps.
This commit is contained in:
Perplexity 2026-06-28 23:06:29 +00:00
parent b779e905ee
commit 3f60fa554e
4 changed files with 123 additions and 108 deletions

217
README.md
View File

@ -1,11 +1,13 @@
# Balatro Seed Searcher
The fastest open-source Balatro seed search engine on the web — written
from scratch in Rust, compiled to WebAssembly with SIMD, parallelised
across Web Workers, with an optional WebGPU compute path and an optional
self-hosted cloud-boost adapter.
A from-scratch Balatro seed search engine — Rust core, WebAssembly delivery
(scalar + SIMD), parallelised across Web Workers. Runs entirely in the
browser; no install, no server round-trip, no telemetry.
**Live demo:** _(coming with milestone 2)_
**Live demo (standalone):** deployed via the Perplexity asset-share URL in
`/web/`. **Live demo (integrated):** wired into
[Balatropedia](https://github.com/JupiterianSoul/Balatropedia) behind a beta
toggle in the Seed Finder tab.
```
┌───────────────────────────────────────────────────────────┐
@ -15,140 +17,153 @@ self-hosted cloud-boost adapter.
│ │ React UI │ ←→ │ Orchestrator (main thread) │ │
│ │ • Filter │ │ • partitions seed space │ │
│ │ builder │ │ • aggregates matches │ │
│ │ • Streaming │ │ • ranks by closeness score │ │
│ │ • Streaming │ │ • progress + engine status │ │
│ │ results │ └──────────┬───────────────────┘ │
│ │ • Share URL │ │ │
│ └──────────────┘ ┌─────────┴─────────┐ │
│ │ N Web Workers │ │
│ │ • Device │ │ │
│ │ profiler │ ┌─────────┴─────────┐ │
│ └──────────────┘ │ N Web Workers │ │
│ │ • Rust → WASM │ │
│ │ • SIMD path opt. │ │
│ │ • SIMD detection │ │
│ │ • adaptive batch │ │
│ └─────────┬─────────┘ │
│ ▼ │
│ ┌───────────────────┐ │
│ │ WASM engine │ │
│ │ pseudohash + LCG │ │
│ │ + cache + sources │ │
│ │ + node cache │ │
│ │ + filter bytecode │ │
│ └───────────────────┘ │
│ │
│ Optional: WebGPU compute path → 10–30× throughput │
│ Optional: WebSocket → self-hosted cloud worker (Node) │
└───────────────────────────────────────────────────────────┘
```
## Why a new engine?
Existing browser-based Balatro seed finders (including the one in
[Balatropedia](https://github.com/JupiterianSoul/Balatropedia)) embed
prebuilt [Immolate](https://github.com/MathIsFun0/Immolate) WASM artefacts.
That works, but you can't:
Existing browser-based Balatro seed finders (including the one originally in
[Balatropedia](https://github.com/JupiterianSoul/Balatropedia)) embed prebuilt
[Immolate](https://github.com/SpectralPack/Immolate) WASM artefacts. That
works, but means you cannot:
- Rebuild with SIMD (no source in the dependent repos)
- Rebuild with SIMD on demand (no source in the dependent repos)
- Re-order filter clauses by selectivity
- Stream "best partial matches" as you go
- Run a verified reproduction simulation
- Push to a GPU compute path
- Run the same engine native on a cloud worker without re-porting
- Express disjunctions (`AnyOf`) cleanly in the DSL
- Tune batch sizes, threading, and worker pacing per device class
This project owns the engine end-to-end so all of that becomes possible.
This project owns the engine end-to-end so all of the above is possible.
## What's in this repo
| Folder | What it is |
|---|---|
| `engine/` | Rust crate: RNG, cache, derivations, filter compiler, search loop |
| `web/` | React + Vite UI, Web Workers, WASM loader, WebGPU adapter |
| `server/` | Optional self-hosted Node WebSocket worker for cloud boost |
| `bench/` | Throughput benchmarks vs Immolate reference |
| `docs/` | Architecture deep-dive, RNG math, filter DSL, build guides |
| `scripts/` | Build helpers (`build-wasm.sh`, `dev.sh`) |
| `_backups/` | Snapshot of Balatropedia's Immolate-based finder for diffing |
| `engine/` | Rust crate — RNG, cache, derivations, filter compiler, search loop, WASM bindings |
| `engine/src/tables.rs` | Canonical item tables — joker pools, tags, vouchers, bosses, packs (synced to Immolate `lib/items.cl` display names) |
| `engine/src/bin/` | `bench_throughput`, `verify` (100k regression sweep), `smoke_anyof` (AnyOf hit-rate sanity), `extract_canonical_names` (sync helper) |
| `web/` | Standalone React + Vite UI — minimal demo of the engine, used for benchmarking and SIMD verification |
| `scripts/build-wasm.sh` | Builds scalar + SIMD WASM bundles, copies them into `web/public/engine{,-simd}/` |
## Quick start
```bash
# Engine — run tests + native bench
cd engine && cargo test --release
cargo run --release --example probe
# 1. Engine — run all tests and the regression sweep
cd engine
cargo test --release # 21/21 unit + integration tests
cargo run --release --bin verify -- 100000
# Build both WASM bundles (scalar + SIMD)
# 2. Build both WASM bundles (scalar + SIMD)
./scripts/build-wasm.sh
# → engine/pkg/, engine/pkg-simd/
# → also copies into web/public/engine{,-simd}/
# Web UI
# 3. Standalone web UI
cd ../web && npm install && npm run dev
```
## Current status (single-session build, ongoing)
To use the engine from another project (e.g. Balatropedia), copy
`engine/pkg/` and `engine/pkg-simd/` into the host's `public/`, and load both
in a Web Worker — the worker probes `WebAssembly.validate` with a SIMD
sentinel and picks whichever bundle works.
- ✅ RNG core: pseudohash + LuaJIT-compatible PRNG, 14/14 parity tests passing
- ✅ Seed encoding: base-35 iteration, rank round-trip
- ✅ Per-run cache: `get_node_child` ported from Immolate, deterministic
- ✅ Item tables: all 12 canonical tables (60+ jokers per rarity, etc.)
- ✅ Source derivations: `next_joker`, `next_tag`, `next_voucher`, `next_boss`
- ✅ Filter DSL: parser + bytecode + 5 clause kinds
- ✅ WASM bundles: scalar (135KB) + SIMD (147KB), both built
- ✅ Native throughput: **552k seeds/sec single-thread** with real derivations
- ⏳ Web UI: in active development (see milestone 2)
- ⏳ Pack-contents simulation: bytecode wired, lock-state machine TODO
- ⏳ Sticker rolls (eternal/perishable/rental): TODO
- ⏳ Voucher chain side-effects: TODO
- ⏳ WebGPU compute path: experimental, design phase
- ⏳ Verified reproduction simulator: TODO
## Filter DSL
## Honesty section
JSON-serialisable, designed to be hand-writable but also UI-buildable.
Strict mode requires every top-level clause to match; partial mode ranks
results by how many clauses match.
This is a real port of a real RNG, not a half-baked "looks plausible"
implementation. After this round of work, four of the six original gaps
are closed and two remain:
**Closed:**
1. ✅ **Boss lock-pool reopening** — `Instance` tracks `locked: BTreeSet<&str>`
and `apply_ante_locks` mirrors Immolate's `init_locks` line-for-line.
`next_boss` runs it before each draw. 100 k-seed sweep: 0 locked-boss
leaks at ante 1.
2. ✅ **Joker resample on locks** — `next_joker` goes through
`rand_choice_common` with the same lock/retry/unlock loop Immolate uses.
3. ✅ **Pack contents** — `open_pack` handles all 15 pack variants with the
right card counts, intra-pack duplicate blocking, and `Op::PackContains`
is wired through `search.rs`.
4. ✅ **Sticker draws** — `next_joker_with_stickers` emits `eternal /
perishable / rental` gated by stake and filtered through blacklists.
100 k White-stake draws: 0 sticker leaks.
**Still open:**
5. ⏳ **Standard pack card-level modelling** — `open_pack` returns the
pack-level contents but doesn't yet draw individual playing cards with
rank/suit/seal/enhancement. Filters that depend on a specific
seal-on-rank inside a Standard pack won't match correctly.
6. ⏳ **Bit-for-bit cross-validation against Immolate** — the 100 k
`verify` sweep proves determinism, pool validity, lock correctness,
sticker correctness, and distribution match; it does not yet prove
byte-identical match with Immolate. That requires running Immolate's
OpenCL binary on the same 100 k seeds and diffing. Tracked.
### Regression-sweep result (latest)
```
cargo run --release --bin verify -- 100000
Determinism failures: 0
Pool misses: 0
Ante-1 locked-boss hits: 0
White-stake sticker leaks: 0
Joker rarity (ante-1 shop): common 70.22 % / uncommon 24.78 % / rare 5.00 %
Pack weights match Immolate's PACKS table to within 0.05 %.
```json
{
"clauses": [
{ "kind": "ante_shop_has_joker", "ante": 1, "slot": 0, "joker": "Blueprint" },
{ "kind": "voucher_is", "ante": 2, "voucher": "Telescope" },
{ "kind": "any_of", "clauses": [
{ "kind": "ante_tag_is", "ante": 1, "position": 0, "tag": "Negative Tag" },
{ "kind": "ante_tag_is", "ante": 2, "position": 0, "tag": "Negative Tag" }
]}
],
"partial": false,
"min_score": null
}
```
The goal of this project is to be **honest about what's working and
what isn't**, while building toward the fastest correct browser seed
finder. If you spot a determinism mismatch with the game, please open
an issue with the seed + filter + observed vs expected.
Supported clauses:
## Docs
- `ante_shop_has_joker { ante, slot, joker, edition? }` — slot 0 only at the
moment (see Known gaps).
- `ante_tag_is { ante, position, tag }`
- `ante_boss_is { ante, boss }`
- `voucher_is { ante, voucher }`
- `ante_pack_contains { ante, pack_index, card }` — pack types `Arcana`,
`Spectral`, `Celestial`, `Buffoon`. Standard packs return contents but
individual card draws (rank/suit/seal/enhancement) are not yet modelled.
- `any_of { clauses: [...] }` — disjunction. Sub-clauses share `Instance`
state, so checking the same joker across antes 1..8 advances the shop
draw sequence naturally and is cached per `(kind, source, ante)`.
- [Architecture](docs/architecture.md) — the four layers, RNG details, why the pseudohash needs the int/fract split.
- [Comparison vs Balatropedia's current finder](docs/comparison.md) — honest side-by-side, including the two gaps still to close.
## Engine status
- **Native single-thread:** ~570k seeds/s on a typical joker filter,
~1M seeds/s when voucher-only short-circuits hit first.
- **WASM SIMD vs scalar:** SIMD bundle wins on every Chromium/Edge run,
loses on Safari (no SIMD support yet) — the worker detects and falls back.
- **Tests:** 21/21 unit + integration green.
- **Regression sweep (`verify -- 100000`):** 0 determinism failures, 0 pool
misses, 0 ante-1 locked-boss leaks, 0 white-stake sticker leaks. Joker
rarity at ante-1 shop: common 70.22 % / uncommon 24.78 % / rare 5.00 %.
Pack weights within 0.05 % of Immolate's PACKS table.
## Honest gaps
1. **Multi-slot shop scan** — `Op::HasJoker` currently only checks shop
slot 0. Most user constraints are "X appears in ante N at all" so the
shop is iterated via `any_of` over antes, not slots; this means a joker
that exists only in slot 1+ but never slot 0 of any ante won't match.
Tracked.
2. **Standard pack card-level modelling** — `open_pack` returns pack-level
contents (the slot exists, the kind is correct) but individual playing
cards inside Standard packs don't get rank/suit/seal/enhancement draws
yet.
3. **Bit-for-bit Immolate cross-validation** — the 100k `verify` sweep
proves determinism, pool validity, lock correctness, sticker correctness,
and distribution match. It does **not** yet prove byte-identical match
with Immolate. That requires running Immolate's OpenCL binary on the
same 100k seeds and diffing. Tracked.
4. **Canonical-name drift** — fixed 2026-06-29. Earlier builds of the
engine had stripped punctuation in item tables (`Mr Bones` instead of
`Mr. Bones`, `Riff raff` instead of `Riff-raff`, `Drivers License`
instead of `Driver's License`) and a swap of `Stuntman`/`Vampire`
between Uncommon and Rare. Both pools and the
`ETERNAL_BLACKLIST`/`PERISHABLE_BLACKLIST` checks were inconsistent
with each other, so sticker filtering on `Mr. Bones` silently failed
and any client-side filter matching by display name (e.g. Balatropedia)
returned zero hits for the affected jokers. Now strictly synced to
Immolate's `lib/debug.cl` display strings.
## Cross-validation against Immolate
The item tables in `engine/src/tables.rs` follow the exact order and
spelling of `J_C_BEGIN..J_L_END` in
[Immolate's `lib/items.cl`](https://github.com/SpectralPack/Immolate/blob/main/lib/items.cl),
with display strings taken from `lib/debug.cl`. If you spot drift, the
helper script in `engine/src/bin/extract_canonical_names.rs` re-diffs both
sides.
## License
@ -157,7 +172,7 @@ MIT. See [LICENSE](LICENSE).
## Credits
- RNG math + source-key naming: ported from
[MathIsFun0/Immolate](https://github.com/MathIsFun0/Immolate) (also MIT).
[SpectralPack/Immolate](https://github.com/SpectralPack/Immolate) (MIT).
- Balatro is © LocalThunk. This project does not include any Balatro
source code or assets — only the deterministic seed-derivation math
the community has documented publicly.

View File

@ -47,10 +47,10 @@ pub const COMMON_JOKERS: &[&str] = &[
"Cavendish",
"Red Card",
"Square Joker",
"Riff raff",
"Riff-raff",
"Photograph",
"Reserved Parking",
"Mail In Rebate",
"Mail-In Rebate",
"Hallucination",
"Fortune Teller",
"Juggler",
@ -107,7 +107,7 @@ pub const UNCOMMON_JOKERS: &[&str] = &[
"Ramen",
"Seltzer",
"Castle",
"Mr Bones",
"Mr. Bones",
"Acrobat",
"Sock and Buskin",
"Troubadour",
@ -122,7 +122,7 @@ pub const UNCOMMON_JOKERS: &[&str] = &[
"Showman",
"Flower Pot",
"Merry Andy",
"Oops All 6s",
"Oops! All 6s",
"The Idol",
"Seeing Double",
"Matador",
@ -153,7 +153,7 @@ pub const RARE_JOKERS: &[&str] = &[
"The Tribe",
"Invisible Joker",
"Brainstorm",
"Drivers License",
"Driver's License",
"Burnt Joker",
];
@ -261,7 +261,7 @@ pub const VOUCHERS: &[&str] = &[
"Illusion",
"Hieroglyph",
"Petroglyph",
"Directors Cut",
"Director's Cut",
"Retcon",
"Paint Brush",
"Palette",
@ -289,7 +289,7 @@ pub const TAGS: &[&str] = &[
"Double Tag",
"Juggle Tag",
"D6 Tag",
"Top up Tag",
"Top-up Tag",
"Speed Tag",
"Orbital Tag",
"Economy Tag",