AGENT SKILL

level-generation-and-solvers

Generates and proves levels - level plans, BFS/IDA* solvers and par, star rules, packs and unlocking, daily level boards, pack tables, level metrics. Use when adding levels, a solver, par, stars, packs or the daily level. Not for rules (game-rules-engine) or dates and streaks (daily-and-statistics).

License 许可
MIT
最近更新
2026-11-05
Stars
★ 0
Forks
0

01 前言 Front Matter

name
level-generation-and-solvers
description
Generates and proves levels - level plans, BFS/IDA* solvers and par, star rules, packs and unlocking, daily level boards, pack tables, level metrics. Use when adding levels, a solver, par, stars, packs or the daily level. Not for rules (game-rules-engine) or dates and streaks (daily-and-statistics).

02 资源文件 127

03 SKILL.md 正文

Level generation and solvers

Gives every Pocket Arcade game a shipped level table that is generated from seeds, proven winnable (by an exact solver at a recorded par, or, for score games that draw their future at random, by a witness bot), laid out in packs that unlock by stars, pinned by data goldens, and a daily level that is the same on every phone. A script regenerates the table from the game's plan and fails on any difference in values or bytes, a bad curve, an import outside the levels zone or a missing golden.

Rules that must hold

  1. Levels are generated, never drawn: a level is { level, seed, difficulty, stars } and the board is create(seed, difficulty), with level and daily difficulties on 0..99 (100 is the endless run). Why: spec 8.1 (same seed, same level); tables stay tiny and saves replay exactly.
  2. pack-<n>.json files are written only by packages/tooling/src/levels/generate-levels.ts from the game's LevelPlan, formatted by the repo's Prettier, and the committed bytes equal what the plan generates. Never copy a pack from a template or an example: the pilot copies the Line Siege example's levels/ code without its pack-*.json files, then generates the packs with node --disable-warning=MODULE_TYPELESS_PACKAGE_JSON packages/tooling/src/levels/generate-levels.ts --app line-siege (the output is byte-identical to the example's packs). Why: a hand-edited or copied table drifts from the generator; the checker regenerates and compares values and bytes.
  3. Every shipped level is proven winnable and its proof line is replayed through the real engine (verifyLine): par games by the exact solver at the recorded par; score games that draw during play (Line Siege) by the witness solver, the game's greedy bot from a fixed bot seed. Why: spec 8.1 and 15 item 7, "no level is impossible"; a solver is never trusted on its own.
  4. Stars follow spec 8.1 through starsFor: par games 3 at or under par, 2 up to par + 2, 1 for finishing; score games [win, two, three], where thresholds[0] is the lowest score a win can have (0 when the win is not score-based) and a witness game's two stars sit at the witness score. Why: the result screen and the Levels grid show these stars to every player; one formula everywhere.
  5. The difficulty curve never falls, later packs are never easier, and no level after the third is a one-mover (a witness game rejects levels its witness wins in fewer than its minimum, Line Siege 8). Why: players expect the game to rise; the owner approves the bands, rate() enforces them.
  6. The daily seed contract never changes: dailySeed('2026-09-26', 17) = 2599028541, dailySeed('2026-09-27', 17) = 2582250922; each game's salt, daily difficulty and the daily boards of pinned dates stay fixed once shipped. Why: spec 8.3, every player gets the same daily level with no server.
  7. Data goldens pin the level table and at least three daily dates, with committed snapshots; they change only with -u on one file and a Gate-Change: trailer. Why: a silent generator or tuning change would give players different boards under the same level numbers.
  8. Packs match game.config.ts (packCount, levelsPerPack), open with 0 stars and unlock by half the earlier stars (0, 45, 90 by default); levels.endless is { kind: 'endless', difficulty: ENDLESS_DIFFICULTY } exactly when modes.endless is true. Why: spec S8, no player stuck on one level; the config and the table can never disagree.
  9. Level code imports only @e07/game-kit/**, @e07/<id>/rules/** and @e07/<id>/levels/**, and follows the rules' determinism policy (no Math.random, clocks, ** or transcendental Math). A witness's evaluation lives in rules/<id>-evaluate.ts, never in testing/. Why: tooling, tests and phones must generate bit-identical levels, and check-boundaries enforces the same zone.

Workflow

  1. Settle the tuning first, then read references/levels-model.md (types, the curve and the tuning rows, packs, stars, daily, endless). The game's balance sims (game-balance-and-bots) must pass before the packs are generated, because every level is create(seed, difficulty) on the current tuning; a tuning change after the packs exist regenerates them (step 5) and their goldens, committed with a Gate-Change: trailer. Get the owner's bands from the design notes: packs and levels per pack, minimum par per pack, star rule (par or score), daily difficulty; defaults are 3 x 30, minimum par 2/3/4, par stars, a daily difficulty of 40 to 50.
  2. Install the level kit once per repo. First make sure fast-check is installed, because the kit's tests and the solver template import it and the bootstrap leaves it out (without it tsc and eslint fail with TS2307): when the root devDependencies do not pin it yet, run npm install -D -E fast-check@4.10.2 at the repo root, then npm approve-scripts --allow-scripts-pending and, if it lists fsevents (the macOS file watcher of jest-haste-map), npm approve-scripts fsevents. Then run node ${CLAUDE_SKILL_DIR}/scripts/check-levels.mjs .; for each kit-file-missing copy templates/packages/<path> to packages/<path> with its test (solver, levels with witness-solver.ts, testing/render-cells.ts, tooling/src/levels/generate-levels.ts). dates/date-key.ts and dates/daily-seed.ts are shared with the daily-and-statistics skill: copy them only when missing. The game's rules (with contract/difficulty.ts) must exist first (game-rules-engine).
  3. Write the solver test-first. Read references/solvers.md. A game whose whole future is fixed by create gets an exact search: copy templates/apps/__GAME_ID__/src/levels/__GAME_ID__-solver.ts and its test to apps/<game-id>/src/levels/ (replace __GAME_ID__, __GAME_PASCAL__, __GAME_CONST__), choose the search state, move order and key, BFS or IDA*, and prove it with examples, the verifyLine property and a budget test. A game that draws during play uses createWitnessSolver with its greedy bot on rules/<id>-evaluate.ts and a fixed bot seed: imitate examples/line-siege/levels/line-siege-solver.ts and its test.
  4. Write the level plan test-first. Read references/generators-and-plans.md. Copy __GAME_ID__-level-plan.ts and its test: packs, curve (difficultyFor from 0 at level 1 to its cap, 99 unless the solver can only prove easier levels), budget, and rate({ start, par, line, final }) with the owner's bands (a witness game: examples/line-siege/levels/line-siege-level-plan.ts, score thresholds from final.score).
  5. Generate the tables (copy the generator and the plan, never packs): node --disable-warning=MODULE_TYPELESS_PACKAGE_JSON packages/tooling/src/levels/generate-levels.ts --app <game-id> writes pack-<n>.json through the repo's Prettier; fix any level N: no candidate by loosening the band or the curve there, then rerun until 0 failures. Then node --disable-warning=MODULE_TYPELESS_PACKAGE_JSON packages/tooling/src/levels/generate-levels.ts --app <game-id> --check and npx prettier --check apps/<game-id>/src/levels both exit 0. Commit exactly what it wrote.
  6. Assemble and prove the table. Copy __GAME_ID__-levels.ts (the LevelsSpec: plan, packs, toLevelEntries, solver, daily salt and difficulty, endless; replace the template's salt 0x5446 with the game's own) and __GAME_ID__-levels.test.ts (runs levelsContractProblems); make game.config.ts levels and modes agree, and set endless: { kind: 'endless', difficulty: ENDLESS_DIFFICULTY } only when modes.endless is true. If the game has hints, wire hints: { kind: 'solver', suggest } in the rules (never for a witness); that makes the game fact hasHints true, so the Game screen (S5) shows its Hint key (lead decision L8; hints: { kind: 'none' }, as in Line Siege, shows none).
  7. Pin the goldens. Read references/goldens-and-quality.md. Copy __GAME_ID__-describe.ts (with its test) and write describeLevel(state) for the game: the template's grid renderer suits a grid game; a game with lanes, pieces or a tray renders those too (examples/line-siege/levels/line-siege-describe.ts). Copy __GAME_ID__-levels.golden.test.ts, run npx jest apps/<game-id>/src/levels/<game-id>-levels.golden.test.ts --selectProjects golden -u once, open the .snap.ios and read the boards (compare with examples/tap-flip-levels.golden.test.ts.snap.ios), then npx jest apps/<game-id>/src/levels --ci --selectProjects golden passes.
  8. Format, lint, type-check, test: npx eslint --fix apps/<game-id>/src/levels, npx prettier --write apps/<game-id>/src/levels/*.ts, npx tsc --noEmit -p apps/<game-id>, npx tsc --noEmit -p packages/tooling, then npx jest apps/<game-id>/src/levels packages/game-kit/src/levels packages/game-kit/src/solver --ci --selectProjects unit --coverage --collectCoverageFrom='apps/<game-id>/src/levels/**/*.ts' --collectCoverageFrom='packages/game-kit/src/levels/**/*.ts' --collectCoverageFrom='packages/game-kit/src/solver/**/*.ts' --coverageThreshold='{}' and read the table (95/95/95/90 for game-kit; paths first, --selectProjects reads every later word as a project name; only npm run test:coverage judges the thresholds), then npx jest apps/<game-id>/src/levels --ci --selectProjects golden.
  9. Run the check node ${CLAUDE_SKILL_DIR}/scripts/check-levels.mjs . --game <game-id> --report; fix every FAIL line (each names the file, the rule and the fix) and rerun until it prints RESULT: PASS. Put the --report pack lines in the owner report and commit tables and goldens with a Gate-Change: trailer.

Definition of done

  • [ ] The game's balance sims passed before the packs were generated (or the packs were regenerated after the last tuning change).
  • [ ] The root package.json pins fast-check exactly in devDependencies (no kit-test-dependency line); packages/game-kit/src/solver/, levels/ (with witness-solver.ts), testing/render-cells.ts and dates/ are installed with their tests; packages/tooling/src/levels/generate-levels.ts exists.
  • [ ] apps/<game-id>/src/levels/ has the solver, the level plan, describeLevel, the LevelsSpec, one generated pack-<n>.json per pack, and their tests; generate-levels.ts --app <game-id> --check and npx prettier --check apps/<game-id>/src/levels exit 0.
  • [ ] <game-id>-levels.test.ts runs levelsContractProblems with the solver and returns [] (every level proven by a replayed line, at its par for par levels; packs matching game.config.ts; endless at difficulty 100 exactly when modes.endless is on).
  • [ ] The golden test pins the pack boundary levels and three daily dates, and its .snap.ios was read and committed with a Gate-Change: trailer.
  • [ ] npx tsc --noEmit, npx eslint --max-warnings 0, npx prettier --check and npx jest <paths> --ci --selectProjects unit and --selectProjects golden pass for the touched workspaces.
  • [ ] node ${CLAUDE_SKILL_DIR}/scripts/check-levels.mjs . --game <game-id> prints RESULT: PASS

Anti-patterns

  • Editing a pack file to "fix" one level. The next regeneration undoes it and the checker fails pack-stale; change the plan or create and regenerate.
  • Raising a test's node budget until a level passes. A level the solver cannot prove within the plan's budget should never have been accepted; regenerate or improve the solver's key and move order.
  • Treating budget-exceeded as unsolvable (or the reverse). Only unsolvable means the whole space was searched.
  • A heuristic that overestimates "to be faster". IDA* then returns a longer line than par and players can beat par; keep it admissible, or use 0.
  • Changing a game's daily salt, the daily difficulty or dailySeed. Every player's daily level changes between versions; ask the owner first.
  • jest -u over a whole folder or in a script. Goldens change one file at a time, after reading the new boards.
  • Using Math.random or the clock to pick candidate seeds. Tables must regenerate identically everywhere; seeds come from candidateSeed(gameId, level, attempt).
  • Rating stars in the Shell with ad-hoc numbers. Stars come from the table's StarRule through starsFor.
  • Copying pack-*.json from an example, or formatting packs by hand or adding them to .prettierignore. Their seeds belong to another plan, and prettier --check and generate-levels --check then disagree; copy the plan and the generator and run it.
  • solver: null or bot sims instead of a proof for a score game. A game that draws at random proves each level with createWitnessSolver; a lost witness is budget-exceeded, a retry with the next candidate seed, never unsolvable.
  • Importing the bot from testing/ into a level file. It breaks the levels import zone (pure-import, and check-boundaries' rules-pure); keep the evaluation in rules/<id>-evaluate.ts.
  • Generating the packs before the tuning is settled. Every later tuning change regenerates the packs and their goldens; run the balance sims first.

Files in this skill

File What it is Read/run when
references/levels-model.md Spec rules for levels, the types, the difficulty scale (curve, tuning rows, daily, endless), packs and unlocking, stars, daily, endless, who uses what Workflow step 1
references/solvers.md Search kit, custom problems and keys, BFS or IDA*, heuristics, budgets, the witness solver, verifyLine, hints, solver tests Step 3
references/generators-and-plans.md The pipeline, tuning first, generator strategies, curve, LevelPlan, candidate seeds, rate(), score games with a witness, running the generator (Prettier bytes), changing tables Steps 1, 4 and 5
references/goldens-and-quality.md Data goldens and describeLevel, -u policy, the daily contract, the levels contract test, every quality rule Steps 6, 7 and 9
templates/packages/game-kit/src/solver/ search-problem, bfs-solve, ida-star-solve, engine-solver, verify-line, with tests Step 2
templates/packages/game-kit/src/levels/ level-table, levels-contract (replays every proof line), pack-progress, star-rating, daily-start, level-plan (rate sees start, par, line, final), plan-level-table, witness-solver (createWitnessSolver), with tests Step 2
templates/packages/game-kit/src/testing/ render-cells.ts (ASCII boards for goldens) with its test Step 2
templates/packages/game-kit/src/dates/ date-key.ts (+ test) and daily-seed.ts: shared with daily-and-statistics, copy only when missing Step 2
templates/packages/tooling/src/levels/ generate-levels.ts: writes pack-<n>.json from the plan through the repo's Prettier, or with --check compares the bytes Steps 2 and 5
templates/apps/__GAME_ID__/src/levels/ The template game (Tap Flip): exact solver, level plan, describeLevel (grid renderer), LevelsSpec, unit, contract and golden tests. No packs: step 5 generates them Steps 3 to 7
examples/line-siege/levels/ Line Siege v1, a score game that draws at random: the witness solver (WITNESS_BOT_SEED, 60,000 nodes), the plan with score thresholds and the 8-placement minimum, describeLevel for lanes, board and tray, the LevelsSpec with the daily (salt 0xe8c0, difficulty 45) and endless (100), the 90 generated levels in Prettier's bytes, and the tests and golden snapshot Steps 3 to 7, for a game that draws during play
examples/tap-flip-levels.golden.test.ts.snap.ios What a committed level golden snapshot looks like (the template game) Step 7
scripts/check-levels.mjs Checker: kit (with the exact fast-check pin its tests need), daily seed goldens and the spec 8.1 star rule (run for real), pack tables, curve and quality metrics, modes, goldens, contract test, the levels import zone, regeneration from the plan compared by value (pack-stale) and by byte (pack-format) Steps 2 and 9, and at the end
scripts/lib/ level-checks.mjs, level-run.mjs, pack-format.mjs (the repo's Prettier, or Prettier's JSON style when it is not installed), app-modules.mjs (loads the repo's TypeScript), ts-scan.mjs, assemble-fixtures.mjs When changing the checker
scripts/selftest.mjs Proves the checker: the templates installed as a game (packs generated) must pass and 21 planted bugs must fail; the same game made score-rated must pass and 2 planted pack bugs must fail After changing the checker or a template
scripts/check-lib.mjs Shared script helper, synced from the library (do not edit here) Never by hand
assets/shared.json Declares the shared files this skill copies in When adding a shared file
tests/fixtures/ check-levels/base/ (rules, RNG, difficulty and config the good repo needs), check-levels/bad-*/ and check-levels-score/ (score.json, bad-*/), one mutation.json and EXPECT.txt each, READMEs When adding a rule to the checker

Related skills

  • game-rules-engine - create, listMoves, applyMove, outcome and the sfc32 RNG the levels are built on.
  • game-host-integration - starting level, daily and endless runs, stars at run end and "Next level".
  • daily-and-statistics - the daily model, streaks and the calendar on top of dailySeed.
  • game-balance-and-bots - the tuning and bot sims that must pass before the packs are generated, and the greedy bot a witness plays.
  • golden-tests - the golden project, -u policy and gated paths in general.
  • toybox-screens - the S8 Levels grid and S7 Result screen that show packs and stars.
  • new-game-scaffold - game.config.ts levels and modes for a new app.

04 同仓库更多 Skills

zakariaf
zakariaf/pocket-arcade

unit-and-component-tests

Sets up Jest and writes Pocket Arcade test code - three projects, RNTL 14 async via renderWithShell, root SDK mocks, fakes, fast-check, coverage, Stryker. Use when a test needs the Shell wrapper, a mock or a fake, or Jest fails. Not for the red-green loop (tdd-workflow) or goldens (golden-tests).

★ 0
zakariaf
zakariaf/pocket-arcade

typescript-and-lint-rules

Enforces Pocket Arcade's strict TypeScript 6 tsconfigs, ESLint 9 flat config, Prettier and size limits. Use when writing or splitting .ts/.tsx or fixing a tsc or lint error. Not for gate wiring (quality-gates), names (naming-conventions) or import zones (architecture-and-boundaries).

★ 0
zakariaf
zakariaf/pocket-arcade

demo-skill

Builds a demo. Use when testing the pitfall checker.

★ 0
zakariaf
zakariaf/pocket-arcade

demo-skill

Builds a demo. Use when testing the pitfall checker.

★ 0
zakariaf
zakariaf/pocket-arcade

troubleshooting-playbook

Diagnoses and fixes Pocket Arcade failures with a catalogue of 300+ known ones (symptom, cause, fix). Use when something errors, crashes, hangs or renders wrong, or an error or log needs explaining. Not for gate setup (quality-gates) or running builds (ios-simulator-build, ios-release-testflight).

★ 0
zakariaf
zakariaf/pocket-arcade

toybox-visual-parity

Proves a built Pocket Arcade screen matches its Toybox design screenshot (light/dark, en/fa) and drives the fixes: capture, element gates, sheets, sign-off. Use when any screen is built or changed, or for visual parity, design match, screenshot compare. Not for building screens (toybox-screens).

★ 0