// 平衡模拟:用游戏真实的状态层 / 公式跑一名“中等勤快”的玩家(每 0.8 秒点一次世界树,按轮换决定买什么), // 输出每颗星的复苏时刻、纪元节奏、根系进度。断言:地球 6–14 分钟复苏;6 小时内九颗星全部复苏;纪元门槛在完成地球后才打开。 // 用法:node tests/balance.mjs [--verbose] import * as S from '../js/game/state.js'; import * as F from '../js/core/formulas.js'; import * as B from '../js/core/balance.js'; import { PLANETS, threatOf } from '../js/data/planets.js'; const DT = 1, TAP = 0.8, SESSION = 600; let seed = 20261115; const realRandom = Math.random; const rng = () => { seed = (seed * 16807) % 2147483647; return seed / 2147483647; }; /** 地球引导期结束后进入的“正常循环”:一颗星从 0 打到复苏 */ export function run({ maxSec = 6 * 3600, verbose = false, tapEvery = 0.8 } = {}) { Math.random = rng; const s = S.newState(); s.tutorial.step = 99; s.scene.next = 1e12; // 单独验证“改造节奏”:随机事件不参与 // 地球新手期(故事 + 引导约 10 分钟):玩家此刻的状态 s.rootLv = 4; s.lives[0] = { moss: 10, firefly: 4 }; // 新手前 8 分钟:根系 4 级、两个生命 s.planets[0].rem = 86; s.res = 0; s.planets[0].explore = 0; // 地球前半段是引导章节:时间从故事开场开始算 const log = []; const clears = { '-1': 600 }; // 开场故事 + 分步引导约 10 分钟,之后才是模拟起点 let reached = 0; let now = S.nowSec(), tapAcc = 0, chapterStart = 0; for (let el = 1; el <= maxSec; el++) { now += DT; tapAcc += DT; for (const ev of S.tick(s, now).world) { if (ev.type === 'planet-done') { clears[ev.planet] = el; reached++; log.push({ el, ev }); if (verbose) console.log(` ✔ ${PLANETS[ev.planet].name} 复苏 @ ${(el / 60).toFixed(1)}min root=${s.rootLv} lives=${JSON.stringify(s.lives[ev.planet])}`); } } if (tapAcc >= tapEvery) { tapAcc = 0; S.tap(s, now); } if (process.env.DBG && el % 30 === 0) console.log(el, 'cost', S.rootCostNow(s), 'p', s.curPlanet, 'rem', s.planets[s.curPlanet].rem.toFixed(1), 'res', s.res.toFixed(0), 'root', s.rootLv, JSON.stringify(s.lives[s.curPlanet]), 'expl', s.planets[s.curPlanet].explore, 'prod', F.prodOf(s, now).toFixed(1), 'gain', F.tapOf(s, now).toFixed(1), 'rate', F.growRateOf(s, s.curPlanet).toFixed(4), 'goal', F.currentGoal(s).key); const i = s.curPlanet, p = s.planets[i]; if (p.rem <= 0) { // 先扎根:根系(及星系共振)是突破下一颗星球价格墙的关键 const targetRoot = Math.min(B.ROOT.max, PLANETS[Math.min(PLANETS.length - 1, i + 1)].unlockLv + 10); const rc0 = S.rootCostNow(s); if (s.rootLv < targetRoot && s.res >= rc0) { S.buyRoot(s, 1); continue; } let moved = false; // 下一颗星:按顺序进入(等级不够时先扎根;本源先不花,留到新星球) if (i + 1 < PLANETS.length) { if (s.rootLv >= PLANETS[i + 1].unlockLv) { S.enterPlanet(s, i + 1); chapterStart = el; moved = true; } } else if (i === PLANETS.length - 1) { s.planets[i].rem = 100; } void moved; // 最后一颗星或暂时无法前进:保持在当前星球继续(根须继续生长,等待门槛) if (!moved && s.planets[i].rem <= 0 && s.curPlanet === PLANETS.length - 1) s.planets[i].rem = 100; continue; } // 勘探:进入一章 8 分钟后(或已到 55%)开始勘探,勘探次数按挑战需求推算出“中位玩家”的次数 const need = threatOf(i).need; const needN = need.kind === 'rootLv' ? 4 : need.kind === 'life' ? 5 : need.n; const explTarget = Math.min(B.STAR.exploreMax, Math.ceil(needN * 3)); const wantsExplore = (100 - p.rem >= 55 || el - chapterStart >= 600 || (el - chapterStart >= 90 && p.rem > 90)) && el - chapterStart >= 30 && p.explore < explTarget; // 买生命(从最新的开始)——先把本源花在生命上,剩下的才用于勘探 let bought = false; for (const l of F.availableLives(s, i).slice().reverse()) { if (s.res >= S.lifeCostNow(s, l.id)) { S.buyLife(s, l.id); bought = true; break; } } if (!bought && wantsExplore && s.res >= S.exploreCostNow(s, i)) { S.explore(s); continue; } // 根系:为下一颗星的等级门槛升级(不足 15 级内时优先) const targetRoot = Math.min(B.ROOT.max, PLANETS[Math.min(PLANETS.length - 1, i + 1)].unlockLv + 10); if (!bought && s.rootLv < targetRoot && s.res >= S.rootCostNow(s) && (100 - p.rem >= 40)) { S.buyRoot(s, 1); continue; } } Math.random = realRandom; return { s, clears, log, reached }; } const fmtMin = (sec) => (sec / 60).toFixed(1) + 'min'; if (import.meta.url === `file://${process.argv[1]}`) { const verbose = process.argv.includes('--verbose'); const r = run({ verbose }); const c = r.clears; // 第二遍:休息型玩家(每 5 秒点一次,但升级与勘探决策相同) const r2 = run({ verbose: false, tapEvery: 5 }); console.log(` 休息型玩家(每 5 秒点一次):${r2.reached}/9 颗星,用时 ${(Math.max(0, ...Object.values(r2.clears)) / 60).toFixed(0)} 分钟`); for (const k of Object.keys(r2.clears)) c[k] = c[k] ?? r2.clears[k]; console.log('── 平衡模拟(每步 1 游戏秒,中等勤快玩家)──'); for (const i of [0, 1, 2, 3, 4, 5, 6, 7, 8]) { if (c[i] === undefined) console.log(` ${PLANETS[i].name.padEnd(5)} 未复苏`); else console.log(` ${PLANETS[i].name.padEnd(5)} 复苏 @ ${fmtMin(c[i])}`); } console.log(`最终:根系 ${r.s.rootLv} 级,星辰共鸣 ×${F.resonanceMul(r.s).toFixed(2)}`); const earthOk = c[0] !== undefined && c[0] <= 20 * 60; const allOk = [0, 1, 2, 3, 4, 5, 6, 7, 8].every((i) => c[i] !== undefined && c[i] <= 6 * 3600); console.log(earthOk ? '✔ 从开场到地球复苏 ≤ 20 分钟(含 10 分钟引导)' : '✘ 地球耗时过长'); console.log(allOk ? '✔ 六小时内九颗星全部复苏' : '✘ 六小时内未能全部复苏'); if (!earthOk || !allOk) process.exitCode = 1; }