| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- // 平衡模拟:用游戏真实的 tick / bestUpgrade / rebirth 跑一名“会点技能”的玩家。
- // 用法:node tests/balance-sim.mjs [小时数] [可选:玩家给自己设的层数上限 CAP,达到即回溯]
- // 输出:回溯样本、进入里世界的探索收益、每 30 分钟的行程、逃逸节点。
- import * as C from '/opt/data/git-repos/worldtree-escape/js/config.js';
- import * as F from '/opt/data/git-repos/worldtree-escape/js/formulas.js';
- import * as S from '/opt/data/git-repos/worldtree-escape/js/state.js';
- import * as R from '/opt/data/git-repos/worldtree-escape/js/rift.js';
- import * as FS from 'node:fs';
- function require2(s){ FS.appendFileSync('/opt/data/git-repos/worldtree-escape/.probe', [s.layer, s.maxLayerRound, s.maxLayerEver, s.chapterSeen, s.playSec, s.rebirths].join(',')+'\n'); }
- const H = +(process.argv[2] || 3);
- const CAP = +(process.argv[3] || 0);
- let seed = 7;
- Math.random = () => { seed = (seed * 16807) % 2147483647; return seed / 2147483647; };
- const s = S.newState();
- s.autoOn = true;
- s.autoEvery = +(process.env.AUTO || 120);
- const marks = [];
- const dt = 0.2;
- let upgT = 0, lastRift = -1e9, lastCapT = -1e9, capHits = 0;
- function buySmart() {
- for (let g = 0; g < 64; g++) {
- const b = F.bestUpgrade(s);
- if (!b) break;
- if (b.kind === 'life') { if (!S.buyLife(s, b.id)) break; }
- else {
- const mult = C.piCostMul(F.piOf(s.layer || 0, F.F0(s)));
- const n = C.maxAffordable(b.kind, s.upgrades[b.kind] || 0, s.essence * 0.95 / mult);
- const cost = C.batchCost(b.kind, s.upgrades[b.kind] || 0, n) * mult;
- if (n <= 0 || cost > s.essence) break;
- s.essence -= cost; s.upgrades[b.kind] += n;
- }
- }
- const bp = F.bestPerm(s);
- if (bp && bp.cost <= s.crystals) { if (bp.kind === 'stem') S.buyTree(s); else S.buyRelic(s); }
- }
- function autoPlayRift() {
- for (let q = 3; q >= 0; q--) if (C.planeUnlocked(s, q)) { S.switchPlane(s, q); break; }
- const run = S.startRift(s);
- if (!run) return;
- R.autoSpend(run); R.buildDone(run, 1);
- let guard = 0;
- while (run.state !== 'result' && guard++ < 400) {
- if (run.state === 'fight') {
- const m = run.mouth, atk = R.atkOf(run);
- const crit = Math.ceil(m.threat * 1.75 - atk), win = Math.ceil(m.threat + 1 - atk);
- const roll = crit >= 0 && crit <= 5 ? crit : win >= 0 && win <= 5 ? win : 5;
- R.afterSlash(run, R.slash(run, roll));
- } else if (run.state === 'event') R.applyOption(run, 1);
- }
- const p = run.plane, before = s.planes[p].explore;
- S.endRift(s);
- marks.push(` · 里世界[${C.PLANES[p].name}] +${s.planes[p].explore - before} 探索 → ${s.planes.map((x) => x.explore | 0).join('/')}`);
- upgT = 0;
- }
- for (let t = 0; t < H * 3600; t += dt) {
- const o = S.tick(s, { run: s.planeRun }, dt);
- if (o.crisis) S.crisisRespond(s, 'relieve');
- for (const e of o.events) if (e.type === 'civ') S.civChoose(s, e.civIdx, 0);
- upgT -= dt;
- if (upgT <= 0) { upgT = 0.2; buySmart(); }
- if (CAP && s.layer >= CAP && !s.escaped && t - lastCapT > 30) {
- lastCapT = t; capHits++;
- if (capHits % 50 === 1) marks.push(` · 卡 ${CAP} 层 → 回溯 #${s.rebirths} t=${(t / 60) | 0}m +${F.rebirthEstimate(s)} 树D${s.treeLv}`);
- S.rebirth(s); continue;
- }
- if (s.escaped) { const L = s.layer, MR = s.maxLayerRound, T0 = t; S.rebirth(s); marks.push(`★ 逃逸完成 t=${(t / 60).toFixed(1)}m L=${L.toFixed(0)} mr=${MR.toFixed(0)} → F=${s.layer.toFixed(0)}(轮回 ${s.rebirths},树 D${s.treeLv})`); }
- if (o.auto) { const r = S.rebirth(s); if (s.rebirths % 10 === 0 || s.rebirths <= 4) marks.push(`回溯 #${s.rebirths} t=${(t / 60) | 0}m 本轮 T=${r.T.toFixed(0)}→F=${r.floor} +${r.gain} 树D${s.treeLv}`); }
- if (t > 300 && t - lastRift > 480 && !s.planeRun) { lastRift = t; autoPlayRift(); }
- if (t % 1800 < dt) {
- const st = F.computeStats(s);
- marks.push(`${(t / 60) | 0}m:本轮 L=${s.layer.toFixed(0)} (F=${st.start.toFixed(0)}) 产出=${st.prod.toExponential(1)} 分/层=${st.minutesPerLayer.toFixed(2)} 跳关=${st.skipP.toFixed(2)} 树=D${s.treeLv} 遗物=${s.relics.length} 结晶=${Math.floor(s.crystals)} 回溯=${s.rebirths} 逃逸=${s.escapeCount} 位面=${s.currentPlane}`);
- }
- }
- console.log(marks.join('\n'));
- console.log(`结束:layer=${s.layer.toFixed(0)} 逃逸=${s.escapeCount} 轮回=${s.rebirths} 树=D${s.treeLv} 探索=${s.planes.map((p) => p.explore | 0).join('/')}`);
|