import { readFileSync } from 'node:fs'; const source = readFileSync(new URL('../game.js', import.meta.url), 'utf8'); const number = name => { const raw = source.match(new RegExp(`\\b${name}\\s*=\\s*(\\.?\\d+(?:\\.\\d+)?)`))?.[1]; if (!raw) throw new Error(`Missing numeric constant: ${name}`); return Number(raw); }; const approach = (value, target, amount) => value < target ? Math.min(target, value + amount) : Math.max(target, value - amount); const RUN_SPEED = number('RUN_SPEED'); const GROUND_ACCEL = number('GROUND_ACCEL'); const TURN_ACCEL = number('TURN_ACCEL'); const GROUND_DECEL = number('GROUND_DECEL'); const JUMP_SPEED = number('JUMP_SPEED'); const GRAVITY = number('GRAVITY'); const APEX_GRAVITY_SCALE = number('APEX_GRAVITY_SCALE'); const FALL_GRAVITY_SCALE = number('FALL_GRAVITY_SCALE'); const JUMP_CUT_GRAVITY_SCALE = number('JUMP_CUT_GRAVITY_SCALE'); const COYOTE_TIME = number('COYOTE_TIME'); const JUMP_BUFFER_TIME = number('JUMP_BUFFER_TIME'); const ATTACK_BUFFER_TIME = number('ATTACK_BUFFER_TIME'); const dt = 1 / 240; const timeTo = (initial, target, acceleration, threshold) => { let value = initial, time = 0; while (time < 2 && Math.abs(value - target) > threshold) { value = approach(value, target, acceleration * dt); time += dt; } return time; }; const simulateJump = releaseAt => { let y = 0, velocity = -JUMP_SPEED, time = 0, highest = 0; while (time < 2) { const held = time < releaseAt; let scale = 1; if (velocity < 0 && !held) scale = JUMP_CUT_GRAVITY_SCALE; else if (Math.abs(velocity) < 95) scale = APEX_GRAVITY_SCALE; else if (velocity > 0) scale = FALL_GRAVITY_SCALE; velocity = Math.min(980, velocity + GRAVITY * scale * dt); y += velocity * dt; highest = Math.min(highest, y); time += dt; if (time > .1 && y >= 0 && velocity > 0) break; } return { height: -highest, airtime: time }; }; const run90 = timeTo(0, RUN_SPEED, GROUND_ACCEL, RUN_SPEED * .1); const stop = timeTo(RUN_SPEED, 0, GROUND_DECEL, 1); const reverse90 = timeTo(RUN_SPEED, -RUN_SPEED, TURN_ACCEL, RUN_SPEED * .1); const fullJump = simulateJump(Infinity); const shortJump = simulateJump(.09); const checks = [ ['90% run speed reached in 70–130ms', run90 >= .07 && run90 <= .13], ['ground stop completes within 100ms', stop <= .1], ['full reverse completes within 150ms', reverse90 <= .15], ['full jump remains compatible with authored 92px rises', fullJump.height >= 108 && fullJump.height <= 130], ['short jump is meaningfully lower', shortJump.height < fullJump.height * .78 && shortJump.height >= 48], ['coyote and jump buffers are forgiving but bounded', COYOTE_TIME >= .1 && COYOTE_TIME <= .16 && JUMP_BUFFER_TIME >= .1 && JUMP_BUFFER_TIME <= .18], ['combat buffer stays below one eighth-note window', ATTACK_BUFFER_TIME > 0 && ATTACK_BUFFER_TIME < .18], ['thin platforms use player-only one-way collision', source.includes("oneWay&&e===player") && source.includes('standingOnOneWay') && source.includes('player.dropTimer')], ['hit stop preserves rhythm clock', source.includes('advanceRhythmClock(dt)') && source.includes('if(hitStop>0)')], ['camera uses smoothed directional lookahead', source.includes('desiredLookahead') && source.includes('cameraLookahead')], ['touch joystick preserves analog magnitude outside a deadzone', source.includes('const normalized=x/max,deadzone=.18') && source.includes('player.dir=direction')] ]; console.log(`Run 90%: ${(run90 * 1000).toFixed(1)}ms; stop: ${(stop * 1000).toFixed(1)}ms; reverse 90%: ${(reverse90 * 1000).toFixed(1)}ms`); console.log(`Full jump: ${fullJump.height.toFixed(1)}px / ${fullJump.airtime.toFixed(3)}s; short jump: ${shortJump.height.toFixed(1)}px / ${shortJump.airtime.toFixed(3)}s`); for (const [label, passed] of checks) console.log(`${passed ? 'PASS' : 'FAIL'} ${label}`); if (checks.some(([, passed]) => !passed)) process.exitCode = 1;