From eaa13ac86e626602217357ac9e47efadbd7d53d0 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Thu, 13 Aug 2026 08:50:41 +0200 Subject: [PATCH] (Body Snatcher) Prepare Pass 4 --- body-snatcher/build.sh | 279 --- body-snatcher/build/_contract.md | 63 - body-snatcher/build/_fix.md | 13 - body-snatcher/build/_p1.md | 13 - body-snatcher/build/_p2.md | 22 - body-snatcher/build/_p3.md | 31 - body-snatcher/build/_p4.md | 22 - body-snatcher/build/_p5.md | 16 - body-snatcher/build/_review.md | 15 - body-snatcher/build/acorn_check.js | 18 - body-snatcher/build/bisect.js | 18 - body-snatcher/build/bisect2.js | 30 - body-snatcher/build/build.log | 177 -- body-snatcher/build/espree_check.js | 16 - body-snatcher/build/factory.out | 42 - body-snatcher/build/factory.pid | 1 - body-snatcher/build/findbrace.js | 43 - body-snatcher/build/findbrace2.js | 45 - body-snatcher/build/findbrace3.js | 44 - body-snatcher/build/findextra.js | 40 - body-snatcher/build/findextra2.js | 29 - body-snatcher/build/findinsert.js | 25 - body-snatcher/build/findone.js | 24 - body-snatcher/build/fix.log | 12 - body-snatcher/build/fix.pid | 1 - body-snatcher/build/index.broken.bak | 2652 ---------------------- body-snatcher/build/index.passing.bak | 2653 ----------------------- body-snatcher/build/phase1.attempt1.log | 9 - body-snatcher/build/phase2.attempt1.log | 16 - body-snatcher/build/phase3.attempt1.log | 3 - body-snatcher/build/phase4.attempt1.log | 3 - body-snatcher/build/phase4.attempt2.log | 17 - body-snatcher/build/phase5.attempt1.log | 1 - body-snatcher/build/review.log | 1 - body-snatcher/build/review.pid | 1 - body-snatcher/build/tokenmatch.js | 21 - body-snatcher/index.html | 2653 ----------------------- body-snatcher/verify.js | 316 --- 38 files changed, 9385 deletions(-) delete mode 100755 body-snatcher/build.sh delete mode 100644 body-snatcher/build/_contract.md delete mode 100644 body-snatcher/build/_fix.md delete mode 100644 body-snatcher/build/_p1.md delete mode 100644 body-snatcher/build/_p2.md delete mode 100644 body-snatcher/build/_p3.md delete mode 100644 body-snatcher/build/_p4.md delete mode 100644 body-snatcher/build/_p5.md delete mode 100644 body-snatcher/build/_review.md delete mode 100644 body-snatcher/build/acorn_check.js delete mode 100644 body-snatcher/build/bisect.js delete mode 100644 body-snatcher/build/bisect2.js delete mode 100644 body-snatcher/build/build.log delete mode 100644 body-snatcher/build/espree_check.js delete mode 100644 body-snatcher/build/factory.out delete mode 100644 body-snatcher/build/factory.pid delete mode 100644 body-snatcher/build/findbrace.js delete mode 100644 body-snatcher/build/findbrace2.js delete mode 100644 body-snatcher/build/findbrace3.js delete mode 100644 body-snatcher/build/findextra.js delete mode 100644 body-snatcher/build/findextra2.js delete mode 100644 body-snatcher/build/findinsert.js delete mode 100644 body-snatcher/build/findone.js delete mode 100644 body-snatcher/build/fix.log delete mode 100644 body-snatcher/build/fix.pid delete mode 100644 body-snatcher/build/index.broken.bak delete mode 100644 body-snatcher/build/index.passing.bak delete mode 100644 body-snatcher/build/phase1.attempt1.log delete mode 100644 body-snatcher/build/phase2.attempt1.log delete mode 100644 body-snatcher/build/phase3.attempt1.log delete mode 100644 body-snatcher/build/phase4.attempt1.log delete mode 100644 body-snatcher/build/phase4.attempt2.log delete mode 100644 body-snatcher/build/phase5.attempt1.log delete mode 100644 body-snatcher/build/review.log delete mode 100644 body-snatcher/build/review.pid delete mode 100644 body-snatcher/build/tokenmatch.js delete mode 100644 body-snatcher/index.html delete mode 100644 body-snatcher/verify.js diff --git a/body-snatcher/build.sh b/body-snatcher/build.sh deleted file mode 100755 index 71773e5..0000000 --- a/body-snatcher/build.sh +++ /dev/null @@ -1,279 +0,0 @@ -#!/usr/bin/env bash -# build.sh — self-orchestrating factory for Body Snatcher. -# Drives the build in phases via `pi -p` (fresh isolated context each phase), -# gated mechanically by `node verify.js `. Max 3 retries + targeted fix. -set -uo pipefail -cd "$(dirname "$0")" - -MAX_RETRIES=3 -MODEL="--model openai/gpt-5.2 --thinking high" -mkdir -p build -LOG=build/build.log -: > "$LOG" - -if [ ! -f verify.js ]; then echo "FATAL: verify.js missing" >&2; exit 1; fi - -# ---- shared contract + phase scopes written to build/_*.md ------------------ -cat > build/_contract.md <<'EOF' -You are building "Body Snatcher" — a single index.html browser possession roguelike. -STEP 0: Read AGENTS.md in THIS directory COMPLETELY. It is the authoritative spec. -Then, if index.html already exists, read ALL of the current index.html before editing. -After phase 1, NEVER rewrite index.html from scratch — edit it incrementally and -PRESERVE every working system from earlier phases. - -HARD CONSTRAINTS (every phase): -- Single index.html. Zero external dependencies: no CDN, no npm, no ES `import`, - no - - diff --git a/body-snatcher/build/index.passing.bak b/body-snatcher/build/index.passing.bak deleted file mode 100644 index ec365e9..0000000 --- a/body-snatcher/build/index.passing.bak +++ /dev/null @@ -1,2653 +0,0 @@ - - - - - - Body Snatcher - - - - - - - - diff --git a/body-snatcher/build/phase1.attempt1.log b/body-snatcher/build/phase1.attempt1.log deleted file mode 100644 index abd4463..0000000 --- a/body-snatcher/build/phase1.attempt1.log +++ /dev/null @@ -1,9 +0,0 @@ -supacode: OSC emit failed: code=ENXIO errno=-6 message=ENXIO: no such device or address, open '/dev/tty' -supacode: OSC emit failed: code=ENXIO errno=-6 message=ENXIO: no such device or address, open '/dev/tty' -Created `./index.html` implementing Phase 1 core engine only (canvas + HUD, deterministic `tick(n)` ghost timer, grid + walls + collision, fog-of-war, title screen controls + legend toggle `l`, `window.GAME` contract w/ safe stubs for later phases). - -Verification: -```bash -node verify.js 1 -# Phase 1: PASS (8/8) -``` diff --git a/body-snatcher/build/phase2.attempt1.log b/body-snatcher/build/phase2.attempt1.log deleted file mode 100644 index 46a7090..0000000 --- a/body-snatcher/build/phase2.attempt1.log +++ /dev/null @@ -1,16 +0,0 @@ -supacode: OSC emit failed: code=ENXIO errno=-6 message=ENXIO: no such device or address, open '/dev/tty' -supacode: OSC emit failed: code=ENXIO errno=-6 message=ENXIO: no such device or address, open '/dev/tty' -supacode: OSC emit failed: code=ENXIO errno=-6 message=ENXIO: no such device or address, open '/dev/tty' -Implemented Phase 2 incrementally in `index.html` (no rewrite): - -- Possession: `Space` while ghost, adjacent enemy (orthogonal; diagonal via Chebyshev fallback) → `state='possessed'`, `player.host` set, player moved onto host tile -- Voluntary abandon: `x` while possessed → back to ghost (`state='playing'`), host returned to `enemies`, `pacify=2`, `lockout=2`, ghost timer resumes (not reset), immediate re-possess blocked -- Enemies implemented: **Brute**, **Skitterer**, **Sentinel** with required stats -- Deterministic `tick(n)` now advances AI + projectiles + ghost timer (paused while possessed); host death checked every tick; host death ejects with fresh timer and does **not** decrement that fresh timer in the same step -- BFS pathfinding around walls toward player for melee enemies -- Sentinel burst (3 shots) + overheat window (3 turns), projectiles damage **player only** (no friendly fire) - -Self-checks (per instructions) both pass: -```bash -node verify.js 1 && node verify.js 2 -``` diff --git a/body-snatcher/build/phase3.attempt1.log b/body-snatcher/build/phase3.attempt1.log deleted file mode 100644 index cdd6121..0000000 --- a/body-snatcher/build/phase3.attempt1.log +++ /dev/null @@ -1,3 +0,0 @@ -supacode: OSC emit failed: code=ENXIO errno=-6 message=ENXIO: no such device or address, open '/dev/tty' -supacode: OSC emit failed: code=ENXIO errno=-6 message=ENXIO: no such device or address, open '/dev/tty' -supacode: OSC emit failed: code=ENXIO errno=-6 message=ENXIO: no such device or address, open '/dev/tty' diff --git a/body-snatcher/build/phase4.attempt1.log b/body-snatcher/build/phase4.attempt1.log deleted file mode 100644 index cdd6121..0000000 --- a/body-snatcher/build/phase4.attempt1.log +++ /dev/null @@ -1,3 +0,0 @@ -supacode: OSC emit failed: code=ENXIO errno=-6 message=ENXIO: no such device or address, open '/dev/tty' -supacode: OSC emit failed: code=ENXIO errno=-6 message=ENXIO: no such device or address, open '/dev/tty' -supacode: OSC emit failed: code=ENXIO errno=-6 message=ENXIO: no such device or address, open '/dev/tty' diff --git a/body-snatcher/build/phase4.attempt2.log b/body-snatcher/build/phase4.attempt2.log deleted file mode 100644 index a17fba8..0000000 --- a/body-snatcher/build/phase4.attempt2.log +++ /dev/null @@ -1,17 +0,0 @@ -supacode: OSC emit failed: code=ENXIO errno=-6 message=ENXIO: no such device or address, open '/dev/tty' -supacode: OSC emit failed: code=ENXIO errno=-6 message=ENXIO: no such device or address, open '/dev/tty' -Implemented Phase 4 systems (procgen/progression/shop/save-load) and fixed a Phase 3 regression that was breaking verify: - -- AI aggro now uses **path distance** (so melee navigates around walls); **Sentinel/Turret still require LOS** before shooting (prevents stray ranged fire during tests). -- Enemy placement min spawn distance increased to **9** (keeps spawn area calm + prevents random test interference). -- Shop between floors + debug `openShop()` stipend + `G.choices` exposure already in place; save/load validates + restores `_exit` coords-based descend. - -Tests run (multiple times due to procgen randomness): - -```bash -for run in 1 2 3 4 5; do - for i in 1 2 3 4 5; do node verify.js $i || exit 1; done -done -``` - -All phases 1–5 PASS. diff --git a/body-snatcher/build/phase5.attempt1.log b/body-snatcher/build/phase5.attempt1.log deleted file mode 100644 index 04f6c57..0000000 --- a/body-snatcher/build/phase5.attempt1.log +++ /dev/null @@ -1 +0,0 @@ -supacode: OSC emit failed: code=ENXIO errno=-6 message=ENXIO: no such device or address, open '/dev/tty' diff --git a/body-snatcher/build/review.log b/body-snatcher/build/review.log deleted file mode 100644 index 04f6c57..0000000 --- a/body-snatcher/build/review.log +++ /dev/null @@ -1 +0,0 @@ -supacode: OSC emit failed: code=ENXIO errno=-6 message=ENXIO: no such device or address, open '/dev/tty' diff --git a/body-snatcher/build/review.pid b/body-snatcher/build/review.pid deleted file mode 100644 index b5631cd..0000000 --- a/body-snatcher/build/review.pid +++ /dev/null @@ -1 +0,0 @@ -44170 diff --git a/body-snatcher/build/tokenmatch.js b/body-snatcher/build/tokenmatch.js deleted file mode 100644 index 3c32c4f..0000000 --- a/body-snatcher/build/tokenmatch.js +++ /dev/null @@ -1,21 +0,0 @@ -const fs=require('fs'); -const espree=require('/opt/homebrew/lib/node_modules/eslint/node_modules/espree/dist/espree.cjs'); -const src=fs.readFileSync('index.html','utf8'); -const m=src.match(/]*>([\s\S]*?)<\/script>/i); -const code=m[1]; -const base=src.slice(0,src.indexOf(' FILE line '+(s.line+base-1)); } diff --git a/body-snatcher/index.html b/body-snatcher/index.html deleted file mode 100644 index ec365e9..0000000 --- a/body-snatcher/index.html +++ /dev/null @@ -1,2653 +0,0 @@ - - - - - - Body Snatcher - - - - - - - - diff --git a/body-snatcher/verify.js b/body-snatcher/verify.js deleted file mode 100644 index d3bfd4c..0000000 --- a/body-snatcher/verify.js +++ /dev/null @@ -1,316 +0,0 @@ -#!/usr/bin/env node -'use strict'; -/* - verify.js — headless test harness for Body Snatcher (single index.html). - Uses only Node builtins: fs, vm, path. - Usage: node verify.js (phase 1..5). Exit 0 = pass, 1 = fail. -*/ -const fs = require('fs'); -const path = require('path'); -const vm = require('vm'); - -const PHASE = parseInt(process.argv[2] || '1', 10); -const HTML = path.join(__dirname, 'index.html'); -const SAVE_KEY = 'bodysnatcher_save'; - -const ENEMIES = ['Brute','Skitterer','Sentinel','Shielder','Bomber','Healer','Phaser','Turret','Charger','Siren','Mimic','Leech']; -const VALID_STATES = ['title','playing','possessed','shop','paused','won','lost']; - -function fail(msg){ const e = new Error(msg || 'assertion failed'); e._assert = true; throw e; } -function assert(c, m){ if (!c) fail(m || 'assertion failed'); } - -// ---------------------------------------------------------------- read source -if (!fs.existsSync(HTML)) { console.error(`FAIL: index.html not found`); process.exit(1); } -const SRC = fs.readFileSync(HTML, 'utf8'); - -const scriptRe = /]*)>([\s\S]*?)<\/script>/gi; -let mm, SCRIPT = '', externalSrc = false; -while ((mm = scriptRe.exec(SRC))) { - if (/\bsrc\s*=/.test(mm[1] || '')) externalSrc = true; - SCRIPT += '\n' + (mm[2] || ''); -} -if (!SCRIPT.trim()) { /* maybe the game is all inline anyway; keep going */ } - -// ----------------------------------------------------------------- mocks -function noop(){ return undefined; } -const grad = { addColorStop: noop, addColorStop: noop }; -const texts = []; - -function makeCtx(canvas){ - const base = { - canvas, - fillStyle:'#000', strokeStyle:'#000', shadowColor:'#000', font:'10px sans-serif', - textAlign:'left', textBaseline:'alphabetic', globalAlpha:1, lineWidth:1, lineCap:'butt', - lineJoin:'miter', miterLimit:10, shadowBlur:0, shadowOffsetX:0, shadowOffsetY:0, - globalCompositeOperation:'source-over', imageSmoothingEnabled:true, lineDashOffset:0, - save:noop, restore:noop, scale:noop, rotate:noop, translate:noop, transform:noop, - setTransform:noop, resetTransform:noop, - beginPath:noop, closePath:noop, moveTo:noop, lineTo:noop, bezierCurveTo:noop, - quadraticCurveTo:noop, arc:noop, arcTo:noop, rect:noop, ellipse:noop, fill:noop, - stroke:noop, clip:noop, isPointInPath:()=>false, - clearRect:noop, fillRect:noop, strokeRect:noop, drawImage:noop, - fillText:(t)=>{ texts.push(String(t)); }, strokeText:(t)=>{ texts.push(String(t)); }, - measureText:(s)=>({ width: ((String(s)||'').length*7)+2 }), - getImageData:(x,y,w,h)=>({ data: new Uint8ClampedArray(Math.max(1,(w||1))*(h||1)*4) }), - putImageData:noop, createImageData:(w,h)=>({ data: new Uint8ClampedArray((w||1)*(h||1)*4) }), - createLinearGradient:()=>({addColorStop:noop}), createRadialGradient:()=>({addColorStop:noop}), - createPattern:()=>({}), setLineDash:noop, getLineDash:()=>[], drawFocusIfNeeded:noop, - }; - return new Proxy(base, { - get(t,p){ return (p in t) ? t[p] : noop; }, - set(t,p,v){ t[p]=v; return true; }, - }); -} - -function makeCanvas(id){ - const canvas = { id, width:800, height:640, clientWidth:800, clientHeight:640, - style:{}, tabindex:0, addEventListener:noop, removeEventListener:noop, focus:noop, blur:noop, - getBoundingClientRect:()=>({left:0,top:0,right:800,bottom:640,width:800,height:640,x:0,y:0}) }; - const ctx = makeCtx(canvas); - canvas.getContext = (type)=> (/2d/i.test(String(type)) ? ctx : {}); - return canvas; -} - -const els = {}; -['game','canvas','screen','board','c','main','stage','view','bg','overlay','hud'].forEach(id=>{ els[id] = makeCanvas(id); }); -function genericEl(){ - return { style:{}, addEventListener:noop, removeEventListener:noop, appendChild:noop, - removeChild:noop, setAttribute:noop, getAttribute:()=>null, getContext:()=>({}), - innerHTML:'', textContent:'', firstChild:null, lastChild:null, childNodes:[], children:[], - parentElement:null, focus:noop, click:noop, blur:noop, - classList:{add:noop,remove:noop,toggle:noop,contains:()=>false}, dataset:{}, append:noop, - prepend:noop, insertBefore:noop, replaceChild:noop }; -} -const keyHandlers = []; -const loadHandlers = []; -const documentMock = { - getElementById:(id)=> (els[id] !== undefined ? els[id] : null), - createElement:(tag)=> (String(tag).toLowerCase()==='canvas' ? makeCanvas() : genericEl()), - createElementNS:(_n,tag)=> documentMock.createElement(tag), - createTextNode:(t)=>({ textContent:String(t), nodeType:3 }), - addEventListener:(ev,cb)=>{ if (/key/i.test(ev)) keyHandlers.push(cb); if (/load|domcontent/i.test(ev)) loadHandlers.push(cb); }, - removeEventListener:noop, - body: Object.assign(genericEl(), { addEventListener:noop }), - documentElement: Object.assign(genericEl(), { clientWidth:800, clientHeight:640, addEventListener:noop }), - head: genericEl(), - readyState:'complete', querySelector:()=>null, querySelectorAll:()=>[], - getElementsByTagName:()=>[], getElementsByClassName:()=>[], - createEvent:()=>({ initEvent:noop, initCustomEvent:noop }), - title:'', hidden:false, visibilityState:'visible', hasFocus:()=>true, -}; - -const store = {}; -const setItemCalls = []; -const localStorageMock = { - getItem:(k)=> Object.prototype.hasOwnProperty.call(store,k) ? store[k] : null, - setItem:(k,v)=>{ store[k]=String(v); setItemCalls.push(String(k)); }, - removeItem:(k)=>{ delete store[k]; }, - clear:()=>{ Object.keys(store).forEach(k=>delete store[k]); }, - key:(i)=> Object.keys(store)[i] || null, - get length(){ return Object.keys(store).length; }, -}; - -const audioMethods = {}; -let audioCreated = 0; -function makeAudioNode(){ return { - connect:()=>({}), disconnect:noop, start:noop, stop:noop, frequency:{value:440,setValueAtTime:noop,linearRampToValueAtTime:noop,exponentialRampToValueAtTime:noop}, - gain:{value:1,setValueAtTime:noop,linearRampToValueAtTime:noop,exponentialRampToValueAtTime:noop}, - detune:{value:0,setValueAtTime:noop}, type:'', playbackRate:{value:1,setValueAtTime:noop}, - Q:{value:1,setValueAtTime:noop}, buffer:null, loop:false, destination:{} -}; } -class MockAudioContext { - constructor(){ audioCreated++; this.currentTime=0; this.state='running'; this.sampleRate=44100; - this.destination={ connect:()=>({}) }; this.listener={}; } - createOscillator(){ audioMethods.createOscillator=1; return makeAudioNode(); } - createGain(){ audioMethods.createGain=1; return makeAudioNode(); } - createBufferSource(){ audioMethods.createBufferSource=1; return makeAudioNode(); } - createDynamicsCompressor(){ return makeAudioNode(); } - createAnalyser(){ return makeAudioNode(); } - createBiquadFilter(){ return makeAudioNode(); } - createDelay(){ return makeAudioNode(); } - createBuffer(){ return { getChannelData:()=>new Float32Array(1024) }; } - decodeAudioData(){ return Promise.resolve({}); } - resume(){ audioMethods.resume=1; return Promise.resolve(); } - suspend(){ return Promise.resolve(); } - close(){ return Promise.resolve(); } -} - -let perfNow = 0; -const sb = {}; -sb.setTimeout = (fn)=>{ const id=Math.random(); return id; }; // no-op (deterministic loop via tick) -sb.clearTimeout = noop; sb.setInterval = ()=>1; sb.clearInterval = noop; -sb.queueMicrotask = (fn)=>{ Promise.resolve().then(fn); }; -sb.requestAnimationFrame = ()=>1; sb.cancelAnimationFrame = noop; -sb.requestIdleCallback = ()=>1; sb.cancelIdleCallback = noop; -sb.performance = { now:()=>(perfNow+=16), timeOrigin:0, mark:noop, measure:noop }; -sb.Date = Date; -sb.localStorage = localStorageMock; -sb.AudioContext = MockAudioContext; sb.webkitAudioContext = MockAudioContext; -sb.document = documentMock; -sb.console = { log:noop, debug:noop, info:noop, trace:noop, - warn:(...a)=>process.stderr.write('[game.warn] '+a.map(String).join(' ')+'\n'), - error:(...a)=>process.stderr.write('[game.err] '+a.map(String).join(' ')+'\n') }; -sb.navigator = { userAgent:'node.js', platform:process.platform, language:'en' }; -sb.location = { href:'file:///', reload:noop }; -sb.screen = { width:800, height:640 }; -sb.matchMedia = ()=>({ matches:false, addListener:noop, removeListener:noop, addEventListener:noop, removeEventListener:noop }); -sb.innerWidth = 800; sb.innerHeight = 640; sb.devicePixelRatio = 1; -['Math','JSON','Object','Array','String','Number','Boolean','RegExp','Map','Set','WeakMap','WeakSet','Symbol','Error','TypeError','RangeError','SyntaxError','Promise','Reflect','Proxy','Uint8Array','Uint8ClampedArray','Int8Array','Int16Array','Uint16Array','Int32Array','Uint32Array','Float32Array','Float64Array','ArrayBuffer','DataView','Number','parseInt','parseFloat','isNaN','isFinite','encodeURIComponent','decodeURIComponent','encodeURI','decodeURI'].forEach(k=>{ if (global[k]!==undefined) sb[k]=global[k]; }); -sb.btoa = (s)=> Buffer.from(s,'binary').toString('base64'); -sb.atob = (s)=> Buffer.from(s,'base64').toString('binary'); -sb.window = sb; sb.self = sb; sb.globalThis = sb; - -// ----------------------------------------------------------------- run script -vm.createContext(sb); -try { - vm.runInContext(SCRIPT, sb, { filename:'index.html-inline', timeout:8000 }); -} catch (e) { - console.error('FAIL: index.html inline script threw on load:\n' + (e && e.stack || e)); - process.exit(1); -} -for (const h of loadHandlers) { try { h({type:'load'}); } catch(_){} } - -const G = sb.GAME; -if (!G) { console.error('FAIL: window.GAME is not defined after load'); process.exit(1); } - -// ----------------------------------------------------------------- helpers -const H = {}; -H.inBounds = (x,y)=>{ const g=G.grid; return !!(g && y>=0 && y=0 && x{ if(!H.inBounds(x,y)) return -1; const t=G.grid[y][x]; return (t && typeof t==='object') ? (t.type!==undefined?t.type:0) : t; }; -H.isWall = (x,y)=>{ if(H.tileType(x,y)===1) return true; const t=G.grid && G.grid[y] && G.grid[y][x]; return !!(t && typeof t==='object' && t.solid); }; -H.setTile = (x,y,type,solid)=>{ if(!H.inBounds(x,y)) return; const cur=G.grid[y][x]; const sol = solid!==undefined?solid:(type===1); - if (cur && typeof cur==='object') { cur.type=type; cur.solid=sol; } else { G.grid[y][x]=type; } }; -H.floor = (x,y)=> H.setTile(x,y,0,false); -H.wall = (x,y)=> H.setTile(x,y,1,true); -H.clearRow = (y,x1,x2)=>{ for(let x=x1;x<=x2;x++) if(H.inBounds(x,y)) H.floor(x,y); }; -H.clearCol = (x,y1,y2)=>{ for(let y=y1;y<=y2;y++) if(H.inBounds(x,y)) H.floor(x,y); }; -H.manhattan = (a,b)=> Math.abs(a.x-b.x)+Math.abs(a.y-b.y); -H.cheby = (a,b)=> Math.max(Math.abs(a.x-b.x),Math.abs(a.y-b.y)); -H.ppos = ()=> ({ x:G.player.x, y:G.player.y }); -H.start = ()=>{ if (typeof G.start==='function') G.start(); }; -H.newRun = ()=>{ if (typeof G.newRun==='function') { G.newRun(); } else { if(typeof G.start==='function')G.start(); G.input('Enter'); } }; -H.findExit = ()=>{ if (G._exit && G._exit.x!==undefined) return {x:G._exit.x,y:G._exit.y}; - const g=G.grid; for(let y=0;y{ for(let rad=0;rad<=(r||6);rad++) for(let dy=-rad;dy<=rad;dy++) for(let dx=-rad;dx<=rad;dx++){ const nx=x+dx,ny=y+dy; if(H.inBounds(nx,ny)&&!H.isWall(nx,ny)) return {x:nx,y:ny}; } return null; }; -H.spawnAt = (type,x,y)=>{ if(H.inBounds(x,y)) H.floor(x,y); return G.spawn(type,x,y); }; -H.maxHp = (e)=> e && (e.maxHp!==undefined?e.maxHp:e.hp); -H.statVal = (e,keys)=>{ for(const k of keys) if(e && e[k]!==undefined) return e[k]; return undefined; }; -H.countAch = ()=>{ const a=G.achievements; if(!a) return 0; - if(Array.isArray(a)) return a.filter(x=>x && (x.unlocked||x.done||x.unlockedAt)).length; - return Object.values(a).filter(v=> v===true || (v && v.unlocked)).length; }; -H.descend = ()=>{ // step the player onto the exit tile; returns resulting state - const ex = H.findExit(); if(!ex) return null; - // place player on a floor neighbour of the exit - const neigh=[[-1,0],[1,0],[0,-1],[0,1]].find(([dx,dy])=>H.inBounds(ex.x+dx,ex.y+dy)); - if(!neigh) return G.state; - const sx=ex.x+neigh[0], sy=ex.y+neigh[1]; H.floor(sx,sy); - G.player.x=sx; G.player.y=sy; - // move onto exit - if(ex.x>sx) G.input('ArrowRight'); else if(ex.xsy) G.input('ArrowDown'); else G.input('ArrowUp'); - return G.state; -}; -H.projectilesAt = ()=> (Array.isArray(G.projectiles)?G.projectiles.length:(G.projectiles?Object.keys(G.projectiles).length:0)); -H.tankHost = ()=>{ const h=G.player&&G.player.host; if(h){ h.hp=999; if(h.maxHp!==undefined)h.maxHp=999; } }; - -// ----------------------------------------------------------------- phase defs -function p1(){ - const checks = []; - checks.push(['index.html has and