Преглед изворни кода

feat: 回冲段起始层 F=L-16√L;层数封顶于终点、逃逸按本轮最深判定;修复章节里程碑重复触发

LiuYuYang пре 1 недеља
родитељ
комит
80b3a27cfa

+ 5 - 2
js/config.js

@@ -185,9 +185,12 @@ export function rebirthReward({ maxLayer = 0, exploreSum = 0, incomeMul = 1, rul
 }
 
 // 回溯起始层:F = ⌊本轮最深⌋ + 位面起始加成(修仙 +100)
-export const RETURN_FRAC = 1.0;   // 回溯:F = ⌊本轮最深⌋
+export const RETURN_FRAC = 1.0;   // 回溯:F = ⌊L − RETURN_DEPTH·√L⌋(L = 本轮最深)
+export const RETURN_K = 16;       // 回冲深度系数:F = ⌊L − 16√L⌋(L=1000 → F=494,回冲约 750 秒)
 export function earlyLayer(maxLayerRound, rule) {
-  return Math.floor(RETURN_FRAC * Math.max(0, maxLayerRound)) + ((rule && rule.startBonus) || 0);
+  // 回冲段:F = ⌊L − 16√L⌋(L = 本轮最深)。回冲距离随深度增大,配合“能量谷” gm 曲线形成每次回溯的代价
+  const L = Math.max(0, maxLayerRound);
+  return Math.max(0, Math.floor(L - RETURN_K * Math.sqrt(Math.max(0, L)))) + ((rule && rule.startBonus) || 0);
 }
 
 // ── 危机:侵蚀前沿 ─────────────────────────────────────

+ 1 - 1
js/formulas.js

@@ -15,7 +15,7 @@ export const GRACE = 15, ENV_STEP = 1.04, ENV_CAP = 50, GM_Q = 2, GM_END = 8;
 export function marchBase(layer, start) {
   const D = Math.max(0, layer - (start || 0));
     // 前 GRACE 层 ×1;gm = max(1, 指数包络 ENV_STEP^(D−GRACE)(封顶 ENV_CAP), 二次下界 (min(1, D/Gm))^GM_Q,Gm = TOTAL×(ENV_STEP−1)/(GM_END−1))
-  const Gm = C.TOTAL_LAYERS * (ENV_STEP - 1) / (GM_END - 1);   // 见 config.TOTAL_LAYERS 注释
+  const Gm = C.TOTAL_LAYERS * (ENV_STEP - 1) / (GM_END - 1);   // 标记:Gm 由 TOTAL 与曲线参数共同决定   // 见 config.TOTAL_LAYERS 注释
   // 指数包络只在 D < Gm 内生效(越走越快的“前段”);之后线性增长到终点 ×(GM_END−1)
   if (D >= Gm) return Math.min(ENV_CAP, 1 + (GM_END - 1) * Math.min(1, D / (0.8 * C.TOTAL_LAYERS)));
   return Math.max(1, Math.min(ENV_CAP, Math.pow(ENV_STEP, D - GRACE)), Math.pow(Math.max(1, D) / Gm, GM_Q));

+ 14 - 12
js/state.js

@@ -12,8 +12,8 @@ export function newState() {
   return {
     version: C.SAVE_VERSION,
     createdAt: nowSec(), updatedAt: nowSec(), playSec: 0,
-    // 本轮(临时)
-    essence: 0, layer: 0, maxLayerRound: 0, maxLayerEver: 0,
+    // 本轮(临时):新存档从第 F0 层起飞 = 0
+    essence: 0, layer: C.earlyLayer(0, C.PLANE_RULES[0]), maxLayerRound: 0, maxLayerEver: 0,
     upgrades: { root: 0, canopy: 0 }, lives: {},
     round: { refines: 0 },
     // 永久
@@ -178,6 +178,8 @@ export function tick(s, rift, dt) {
   s.layer += st.layersPerSec * dt;
   s.essence += st.prod * dt;
   s.maxLayerRound = Math.max(s.maxLayerRound, s.layer);
+  // 连续空间的“逃逸进度”= 本轮回抵达的深度 = maxLayerRound(不回退);主世界层数最多推进到终点,溢出归零
+  if (s.layer > C.TOTAL_LAYERS) s.layer = C.TOTAL_LAYERS;
 
   const fl = Math.floor(s.layer);
   if (fl > 0 && fl % 10 === 0 && fl !== s._lastFlash) { s._lastFlash = fl; out.floor = fl; }
@@ -187,15 +189,15 @@ export function tick(s, rift, dt) {
   if (ch > (s.chapterSeen || 0)) {
     for (let c = Math.max(1, (s.chapterSeen || 0) + 1); c <= ch; c++) {
       s.chapterSeen = c;
-      if (c === 5) {
-        s.escaped = true; s.escapedT = 0; s.escapeCount = (s.escapeCount || 0) + 1;
-        s.stats.bestLayer = Math.max(s.stats.bestLayer || 0, s.maxLayerRound);
-        out.events.push({ type: 'milestone', key: 'escape', ...MILESTONES.escape });
-      } else {
-        out.events.push({ type: 'milestone', key: 'chapter' + c, ...MILESTONES.chapter(C.CHAPTERS[c].title) });
-      }
+      out.events.push({ type: 'milestone', key: 'chapter' + c, ...MILESTONES.chapter(C.CHAPTERS[c].title) });
     }
-    if (s.escaped) return out;
+  }
+  // 逃逸判定(连续空间):沿连续空间“抵达”第 TOTAL_LAYERS 层即完成本次逃逸
+  if (s.maxLayerRound >= C.TOTAL_LAYERS && !s.escaped) {
+    s.escaped = true; s.escapedT = 0; s.escapeCount = (s.escapeCount || 0) + 1;
+    s.stats.bestLayer = Math.max(s.stats.bestLayer || 0, s.maxLayerRound);
+    out.events.push({ type: 'milestone', key: 'escape', ...MILESTONES.escape });
+    return out;
   }
 
   // 科技位面:自动化——每秒为已解锁兵种免费 +1 级(上限 autoCap)
@@ -332,7 +334,7 @@ export function rebirth(s) {
   s.crisis = { next: C.CRISIS.firstAt, active: false, buffUntil: 0, penaltyUntil: 0 };
   s.magic = { sig: 0, sigUntil: 0 };
   s._skipAcc = 0; s._autoT = 0; s._lastFlash = undefined;
-  s.chapterSeen = Math.min(5, C.chapterOf(floor));
+  s.chapterSeen = Math.min(5, C.chapterOf(Math.min(C.TOTAL_LAYERS, floor)));
   const evt = s.rebirths === 1
     ? { type: 'milestone', key: 'firstRebirth', ...MILESTONES.firstRebirth }
     : { type: 'milestone', key: 'epoch' + (s.rebirths % 10), ...MILESTONES.epoch(s.rebirths) };
@@ -462,7 +464,7 @@ export function applyOffline(s, elapsedSec, rift) {
   s.maxLayerRound = Math.max(s.maxLayerRound, s.layer);
   s.maxLayerEver = Math.max(s.maxLayerEver, s.layer);
   s.chapterSeen = Math.max(s.chapterSeen || 0, Math.min(5, C.chapterOf(s.layer)));
-  if (s.layer >= C.TOTAL_LAYERS && !s.escaped) { s.escaped = true; s.escapeCount = (s.escapeCount || 0) + 1; s.escapedT = 0; }
+  if (s.maxLayerRound >= C.TOTAL_LAYERS && !s.escaped) { s.escaped = true; s.escapeCount = (s.escapeCount || 0) + 1; s.escapedT = 0; }
   return { sec: Math.round(sec), essence, fromLayer, toLayer: s.layer };
 }
 

+ 1 - 1
tests/balance-sim.mjs

@@ -10,7 +10,7 @@ if (process.argv[1] && process.argv[1].endsWith('balance-sim.mjs')) {
   const CAP = +(process.argv[3] || 0);
   let capHits = 0, lastCapT = -1e9;
   let seed = 7; Math.random = () => { seed = (seed * 16807) % 2147483647; return seed / 2147483647; };
-  const s = S.newState(); s.autoOn = true; s.autoEvery = 60;
+  const s = S.newState(); s.autoOn = true; s.autoEvery = +(process.env.AUTO || 120);
   const dt = 0.2; let upgT = 0; const marks = []; let lastRift = -1e9;
   for (let t = 0; t < H * 3600; t += dt) {
     const o = S.tick(s, { run: s.planeRun }, dt);

BIN
tests/shots/desktop-1-start.png


BIN
tests/shots/desktop-2-progress.png


BIN
tests/shots/desktop-3-first-rebirth.png


BIN
tests/shots/desktop-4-rift-fight.png


BIN
tests/shots/desktop-5-rift-result.png


BIN
tests/shots/desktop-6-crisis.png


BIN
tests/shots/desktop-7-civilization.png


BIN
tests/shots/desktop-8-save.png


BIN
tests/shots/desktop-9-late.png


BIN
tests/shots/mobile-1-growth.png


BIN
tests/shots/mobile-2-march.png


BIN
tests/shots/mobile-5-rift-fight.png


BIN
tests/shots/mobile-6-rift-result.png


+ 2 - 2
tests/unit.mjs

@@ -41,8 +41,8 @@ ok('UI 预期 = state.rebirth() 实得', (() => {
   const a = S.newState(); a.maxLayerRound = 120; a.layer = 120; a.lives = { constsign: 4 }; a.exploreSum = 60; a.planes[0].explore = 60;
   const exp = F.rebirthEstimate(a); const r = S.rebirth(a); return r.gain === exp;
 })());
-ok('回溯起点 F = ⌊本轮最深⌋', C.earlyLayer(123.7, C.PLANE_RULES[0]) === 123);
-ok('修仙道基起始层 +100', C.earlyLayer(50, C.PLANE_RULES[3]) === 150);
+ok('回溯起点 F = ⌊L − 16√L⌋', (() => { const L = 123.7; return C.earlyLayer(L, C.PLANE_RULES[0]) === Math.max(0, Math.floor(L - 16 * Math.sqrt(L))); })());
+ok('修仙道基起始层 +100', C.earlyLayer(400, C.PLANE_RULES[3]) === C.earlyLayer(400, C.PLANE_RULES[0]) + 100);
 ok('里世界中主世界冻结:炼化预期为 0', (() => { const a = S.newState(); a.planeRun = { state: 'fight', active: true }; a.layer = 50; a.maxLayerRound = 50; return F.rebirthEstimate(a) === 0; })());
 
 // 5) 本源产出积分:L=100 时 = (1.05^100 − 1)/(1.05·ln1.05)