/** * 关卡配置:难度随关卡递增,驱动“再闯一关”动力 */ export function getLevelConfig(levelId) { const lv = Math.max(1, Math.min(999, Number(levelId) || 1)) const tier = Math.floor((lv - 1) / 5) return { id: lv, moves: Math.max(14, 26 - tier * 2 - (lv % 3)), goalTargets: [8 + tier * 2 + (lv % 2), 10 + tier * 2 + Math.floor(lv / 4)], scoreTarget: 2800 + lv * 450, startGlucose: 50, /** 餐后消化倒计时(秒):归零时按棋盘上剩余食物升糖 */ digestIntervalSec: Math.max(5, 10 - tier), digestMultiplier: 1 + tier * 0.12, boosters: { insulin: Math.max(1, 3 - Math.floor(tier / 2)), fiber: tier >= 3 ? 0 : 1, meal: Math.max(2, 5 - tier) } } } /** 根据本局表现计算 1~3 星 */ export function calcLevelStars({ movesLeft, glucoseLevel, score, levelConfig }) { let stars = 1 const stable = glucoseLevel >= 30 && glucoseLevel <= 70 if (stable && movesLeft >= 2) stars = 2 if (stars >= 2 && score >= (levelConfig?.scoreTarget ?? 3000) && movesLeft >= 4) stars = 3 return stars }