balance-sim.mjs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // 平衡模拟:模拟一名“会点技能”的玩家跑 6 小时(仅用底层动作,不调用 UI)
  2. // 用法:node tests/balance-sim.mjs [小时数]
  3. import * as C from '/opt/data/git-repos/worldtree-escape/js/config.js';
  4. import * as F from '/opt/data/git-repos/worldtree-escape/js/formulas.js';
  5. import * as S from '/opt/data/git-repos/worldtree-escape/js/state.js';
  6. import * as R from '/opt/data/git-repos/worldtree-escape/js/rift.js';
  7. if (process.argv[1] && process.argv[1].endsWith('balance-sim.mjs')) {
  8. const H = +(process.argv[2] || 6);
  9. const CAP = +(process.argv[3] || 0);
  10. let capHits = 0, lastCapT = -1e9;
  11. let seed = 7; Math.random = () => { seed = (seed * 16807) % 2147483647; return seed / 2147483647; };
  12. const s = S.newState(); s.autoOn = true; s.autoEvery = 60;
  13. const dt = 0.2; let upgT = 0; const marks = []; let lastRift = -1e9;
  14. for (let t = 0; t < H * 3600; t += dt) {
  15. const o = S.tick(s, { run: s.planeRun }, dt);
  16. if (o.crisis) S.crisisRespond(s, 'relieve');
  17. if (o.auto) { const r = S.rebirth(s); if (s.rebirths % 10 === 0 || s.rebirths < 5) marks.push(`回溯 #${s.rebirths} t=${(t / 60) | 0}m 本轮 T=${r.T.toFixed(0)}→F=${r.floor} +${r.gain} 深度≈${(r.T / 60).toFixed(1)} 分/轮回`); }
  18. upgT -= dt;
  19. if (upgT <= 0) {
  20. upgT = 0.2;
  21. for (let g = 0; g < 5; g++) {
  22. const best = F.bestUpgrade(s);
  23. if (!best) break;
  24. if (best.kind === 'life') { if (!S.buyLife(s, best.id)) break; }
  25. else { const mult = C.piCostMul(F.piOf(s.layer || 0, F.F0(s))); const n = C.maxAffordable(best.kind, s.upgrades[best.kind] || 0, s.essence * 0.95 / mult); const cost = C.batchCost(best.kind, s.upgrades[best.kind] || 0, n) * mult; if (n <= 0 || cost > s.essence) break; s.essence -= cost; s.upgrades[best.kind] += n; }
  26. }
  27. const bp = F.bestPerm(s); if (bp && bp.cost <= s.crystals) { if (bp.kind === 'stem') S.buyTree(s); else S.buyRelic(s); }
  28. }
  29. 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); capHits = 0; continue; }
  30. if (s.escaped) { S.rebirth(s); marks.push(`★ 逃逸完成 t=${(t / 60) | 0}m 第 ${s.escapeCount} 次(轮回 ${s.rebirths},树 D${s.treeLv})`); }
  31. if (t > 300 && t - lastRift > 480 && !s.planeRun) {
  32. lastRift = t;
  33. for (let q = 3; q >= 0; q--) if (C.planeUnlocked(s, q)) { S.switchPlane(s, q); break; }
  34. const run = S.startRift(s);
  35. if (run) {
  36. R.autoSpend(run); R.buildDone(run, 1);
  37. let guard = 0;
  38. while (run.state !== 'result' && guard++ < 400) {
  39. 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)); }
  40. else if (run.state === 'event') R.applyOption(run, 1);
  41. }
  42. const before = s.planes[run.plane].explore;
  43. S.endRift(s);
  44. marks.push(` · 里世界[${C.PLANES[run.plane].name}] +${s.planes[run.plane].explore - before} 探索 → ${s.planes.map((p) => p.explore | 0).join('/')}`);
  45. upgT = 0;
  46. }
  47. }
  48. if (t % 1800 < dt) {
  49. const st = F.computeStats(s);
  50. 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}`);
  51. }
  52. }
  53. console.log(marks.join('\n'));
  54. const st = F.computeStats(s);
  55. console.log(`结束:layer=${s.layer.toFixed(0)} 逃逸=${s.escapeCount} 轮回=${s.rebirths} 树=D${s.treeLv} 探索=${s.planes.map((p) => p.explore | 0).join('/')}`);
  56. }