From 437448ab1d9d1057603bbe35e0032d4fed86425d Mon Sep 17 00:00:00 2001 From: 44r0n7 <44r0n7+gitea@pm.me> Date: Thu, 29 Oct 2026 18:41:36 -0400 Subject: [PATCH] Move the test-only toolDig helper into the test harness (t84) Written by the local model (qwen3-coder-30b) in a sandboxed worktree via local-run; reviewed by Claude. Co-Authored-By: Claude Opus 5.5 --- src/sim/tools.js | 35 ----------------------------------- test/harness.js | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/sim/tools.js b/src/sim/tools.js index c5e9ae1..6404167 100644 --- a/src/sim/tools.js +++ b/src/sim/tools.js @@ -28,38 +28,3 @@ function forBrush(cx, cy, r, fn) { // how far the drill reaches: set by the bit, and stretched or shortened by the pulse width function drillReach(w = drillWidth) { return Math.round(BIT_TIERS[player.bitTier].reach * (PULSE_W[w] || PULSE_W[1]).reach); } function inDrillReach(x, y, w) { const dx = x - (bot.x + bot.w / 2), dy = y - (bot.y + bot.h / 2), R2 = drillReach(w); return dx * dx + dy * dy <= R2 * R2; } -// Plain digging in a circle. The game itself uses the resonance drill (drill.js); the tests use -// this to clear rock quickly. -function toolDig(cx, cy, r) { - const tier = BIT_TIERS[player.bitTier]; - let dug = 0, tooHard = 0, far = 0; - forBrush(cx, cy, r, (x, y, i) => { - if (!inDrillReach(x, y)) { far++; return; } - const m = mat[i]; - if (bgm[i] && (m === EMPTY || PH[m] === PH_GAS || PH[m] === PH_LIQUID)) { if (cutTree(i, x, y, tier)) dug++; return; } - if (PH[m] !== PH_SOLID) return; - if (PARTMAT[m] || part[i] || mach[i]) return; - const h = HARD[m]; - if (h > tier.hard) { tooHard = m; return; } - const p = digp[i] + tier.speed * 60 / (1 + h * h * 0.6); - if (p >= 255) { - const to = YLD[m]; - const b = blockP[((y / BS) | 0) * BW + ((x / BS) | 0)]; - setCell(i, to, temp[i], 0); - discover(to, x, y, m, 'dig'); - if (isWall(b) && !blockIntegrity(((y / BS) | 0) * BW + ((x / BS) | 0))) removeBlock((x / BS) | 0, (y / BS) | 0); - dug++; - if ((dug & 3) === 0) emit({ t: 'debris', x, y, m }); - } else { digp[i] = p; renderDirtyIdx(i); } - }); - stats.dug += dug; - let status = ''; - void 0; - if (far && !dug && !tooHard) status = `Out of reach; your bit reaches ${drillReach()} grains.`; - if (tooHard && !dug) { - const need = BIT_TIERS.find(b => b.hard >= HARD[tooHard]); - const nb = need ? need.name.toLowerCase() : 'better bit'; - status = HARD[tooHard] > 6 ? `${MD[tooHard].name} cannot be drilled.` : `${MD[tooHard].name} is too hard; needs ${/^[aeiou]/.test(nb) ? 'an' : 'a'} ${nb}.`; - } - return { dug, status, tooHard }; -} diff --git a/test/harness.js b/test/harness.js index 39e65aa..4572b4b 100644 --- a/test/harness.js +++ b/test/harness.js @@ -16,6 +16,43 @@ function fixStack(e) { if (e && typeof e.stack === 'string') e.stack = e.stack.replace(/sim-bundle\.js:(\d+)/g, (_, n) => 'src/' + where(+n)); return e; } +// test-only drill helper; the game drills through its own tool code. +const TOOL_DIG_SRC = `// Plain digging in a circle. The game itself uses the resonance drill (drill.js); the tests use +// this to clear rock quickly. +function toolDig(cx, cy, r) { + const tier = BIT_TIERS[player.bitTier]; + let dug = 0, tooHard = 0, far = 0; + forBrush(cx, cy, r, (x, y, i) => { + if (!inDrillReach(x, y)) { far++; return; } + const m = mat[i]; + if (bgm[i] && (m === EMPTY || PH[m] === PH_GAS || PH[m] === PH_LIQUID)) { if (cutTree(i, x, y, tier)) dug++; return; } + if (PH[m] !== PH_SOLID) return; + if (PARTMAT[m] || part[i] || mach[i]) return; + const h = HARD[m]; + if (h > tier.hard) { tooHard = m; return; } + const p = digp[i] + tier.speed * 60 / (1 + h * h * 0.6); + if (p >= 255) { + const to = YLD[m]; + const b = blockP[((y / BS) | 0) * BW + ((x / BS) | 0)]; + setCell(i, to, temp[i], 0); + discover(to, x, y, m, 'dig'); + if (isWall(b) && !blockIntegrity(((y / BS) | 0) * BW + ((x / BS) | 0))) removeBlock((x / BS) | 0, (y / BS) | 0); + dug++; + if ((dug & 3) === 0) emit({ t: 'debris', x, y, m }); + } else { digp[i] = p; renderDirtyIdx(i); } + }); + stats.dug += dug; + let status = ''; + void 0; + if (far && !dug && !tooHard) status = \`Out of reach; your bit reaches \${drillReach()} grains.\`; + if (tooHard && !dug) { + const need = BIT_TIERS.find(b => b.hard >= HARD[tooHard]); + const nb = need ? need.name.toLowerCase() : 'better bit'; + status = HARD[tooHard] > 6 ? \`\${MD[tooHard].name} cannot be drilled.\` : \`\${MD[tooHard].name} is too hard; needs \${/^[aeiou]/.test(nb) ? 'an' : 'a'} \${nb}.\`; + } + return { dug, status, tooHard }; +}`; + function load() { const man = JSON.parse(fs.readFileSync(path.join(SRC, 'manifest.json'), 'utf8')); const parts = []; let line = 1; starts = []; @@ -24,6 +61,7 @@ function load() { starts.push([line, f]); parts.push(text); line += text.split('\n').length; } try { vm.runInThisContext(parts.join('\n'), { filename: 'sim-bundle.js' }); } catch (e) { throw fixStack(e); } + vm.runInThisContext(TOOL_DIG_SRC, { filename: 'toolDig.js' }); const run = (src) => { try { return vm.runInThisContext(src); } catch (e) { throw fixStack(e); } }; return { run }; }