SOURCE / PINNED RELEASE
Made of little things.
Limb Race
- Release
- 6a8ae4fc626e…
- Author-recorded commit
- 008c01ee6454…
- License
- LICENSE
- Author’s source reference
- nostr://npub182jczunncwe0jn6frpqwq3e0qjws7yqqnc3auccqv9nte2dnd63scjm4rf/wss%3A%2F%2Fgit.napplet.soy%2F/n-c2869f12ad8
Archive hash verified: 7be8492d1f89b891…. The source-to-build association is the author’s claim; it has not been independently rebuilt.
import assert from 'node:assert/strict';
import test from 'node:test';
import ts from 'typescript';
import { readFile } from 'node:fs/promises';
const code=ts.transpileModule(await readFile(new URL('../src/physics.ts',import.meta.url),'utf8'), {compilerOptions:{module:ts.ModuleKind.ES2022,target:ts.ScriptTarget.ES2022}}).outputText;
const {Race,TRACKS,presetDesign,validDesign,terrainContact,PHYSICS_VERSION}=await import(`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`);
const circle=(radius=1,sy=1,offset=0)=>[Array.from({length:97},(_,i)=>({x:Math.cos(i/96*Math.PI*2)*radius+offset,y:Math.sin(i/96*Math.PI*2)*radius*sy}))];
const simulate=(track,design,material='rigid',seconds=180)=>{const r=new Race(track,design,material);for(let i=0;i<seconds*120&&!r.finished&&!r.failed;i++)r.step();return r;};
const flat={...TRACKS[0],length:10000,ground:[{x:-2000,y:300},{x:12000,y:300}]};
for(const material of ['rigid','bendy']) {
test(`${material} Runner can finish Meadow Run`,()=>{const r=simulate(TRACKS[0],presetDesign('runner'),material);assert.ok(r.finished,`stuck at ${r.x}`);});
for(const id of ['steps','cliffs']) {
const track=TRACKS.find(t=>t.id===id);
test(`${material} long legs can climb ${track.name}`,()=>{const r=simulate(track,presetDesign('climber'),material);assert.ok(r.finished,`stuck at ${r.x}`);});
for(const [label,drawing]of [['small',circle(.35)],['medium',circle(.65)],['large',circle(.85)],['full-size',circle()],['oval',circle(1,.8)],['eccentric',circle(.85,1,.12)]]) {
test(`${material} ${label} wheel cannot clear ${track.name}`,()=>{
const r=simulate(track,drawing,material);assert.equal(r.finished,false);assert.ok(r.x<track.ground[1].x,`wheel escaped first wall at ${r.x}`);
});
}
}
test(`${material} rotation creates no horizontal thrust in midair`,()=>{
const race=new Race(flat,presetDesign('runner'),material);race.y=-2000;for(let i=0;i<120;i++)race.step();assert.equal(race.x,130);assert.equal(race.vx,0);
});
}
test('vertical face collision pushes left, never teleports the racer to the top',()=>{
const track=TRACKS.find(t=>t.id==='steps'),wall=track.ground[1].x;
for(const x of [wall-2,wall+2]){const hit=terrainContact(track,x,270,4);assert.ok(hit);assert.ok(hit.nx<-.99);assert.ok(Math.abs(hit.ny)<1e-6);}
});
test('motor direction, rather than a hidden forward force, controls rolling direction',()=>{
const forward=new Race(flat,circle()),reverse=new Race(flat,circle());reverse.motorDirection=-1;
for(let i=0;i<240;i++){forward.step();reverse.step();}assert.ok(forward.x>250);assert.ok(reverse.x<0);
});
test('a stopped motor does not propel a wheel',()=>{
const race=new Race(flat,circle());race.motorDirection=0;for(let i=0;i<600;i++)race.step();assert.ok(Math.abs(race.x-130)<2);
});
test('bendy limbs visibly deform under contact and recover when unloaded',()=>{
const race=new Race(flat,presetDesign('runner'),'bendy');let deflection=0;
for(let i=0;i<600;i++){race.step();deflection=Math.max(deflection,...race.bends.map(b=>Math.abs(b.angle)));}
assert.ok(deflection>.08&&deflection<=.65);assert.notDeepEqual(race.visualDesign(),race.design);
race.y=-10000;race.vy=0;for(let i=0;i<240;i++)race.step();assert.ok(race.bends.every(b=>Math.abs(b.angle)<.01));
});
test('bendy and rigid results stay physically distinct',()=>{
const a=simulate(TRACKS[0],presetDesign('runner'),'rigid'),b=simulate(TRACKS[0],presetDesign('runner'),'bendy');assert.ok(Math.abs(a.elapsed-b.elapsed)>1);
});
test('Live Draw keeps progress and copies drawing snapshots by value',()=>{
const drawing=presetDesign('runner'),race=new Race(flat,drawing,'bendy');for(let i=0;i<240;i++)race.step();
const before=[race.x,race.y,race.vx,race.vy,race.elapsed];race.setDesign(presetDesign('climber'));assert.deepEqual([race.x,race.y,race.vx,race.vy,race.elapsed],before);
const other=new Race(flat,drawing);drawing[0][1].x=.9;assert.notEqual(other.design[0][1].x,.9);
});
test('square corners are usable and invalid coordinates are rejected',()=>{
assert.equal(validDesign([[{x:0,y:0},{x:1,y:1},{x:-1,y:1}]]),true);
assert.equal(validDesign([[{x:0,y:0},{x:NaN,y:0}]]),false);assert.equal(validDesign([[{x:0,y:0},{x:1.01,y:0}]]),false);
});
test('drawing boards have separate IDs and stay within the host limit',async()=>{
const config=JSON.parse(await readFile(new URL('../napplet.json',import.meta.url),'utf8'));
const expected=TRACKS.slice(0,4).flatMap(t=>['classic','live'].flatMap(mode=>['rigid','bendy'].map(material=>`${t.id}-${mode}-${material}-v${PHYSICS_VERSION}-draw1`)));
assert.equal(new Set(expected).size,16);assert.deepEqual(config.backend.boards.map(b=>b.board).sort(),expected.sort());
const publicBackend=JSON.parse(await readFile(new URL('../soy-backend.json',import.meta.url),'utf8'));assert.deepEqual(publicBackend.boards.slice().sort(),expected.sort());assert.deepEqual(publicBackend.provider,config.backend.provider);
});
test('bendy rendering preserves a stroke that retraces through the hub',()=>{const r=new Race(flat,[[{x:0,y:0},{x:1,y:0},{x:0,y:0},{x:0,y:1}]],'bendy');assert.ok(r.visualDesign()[0].filter(p=>p.x===0&&p.y===0).length>=2);});
const challenges=TRACKS.slice(4);
test('the challenge pack adds six distinct, valid courses without changing physics rules',()=>{
assert.equal(TRACKS.length,10);assert.equal(new Set(TRACKS.map(t=>t.id)).size,10);assert.equal(PHYSICS_VERSION,2);
for(const t of challenges){assert.ok(t.ground[0].x<0);assert.ok(t.ground.at(-1).x>t.length);assert.equal(t.ground[0].y,300);for(let i=1;i<t.ground.length;i++){const a=t.ground[i-1],b=t.ground[i];assert.ok(b.x>=a.x);assert.ok(a.x!==b.x||a.y!==b.y);assert.ok(Number.isFinite(b.x)&&Number.isFinite(b.y));}}
});
for(const track of challenges){
for(const material of ['rigid','bendy'])test(`${track.name} is completable with ${material} drawn legs`,()=>{
const r=simulate(track,presetDesign('climber'),material);assert.ok(r.finished,`stuck at ${r.x}`);assert.ok(r.elapsed<120,`${r.elapsed}s leaves too little margin`);
});
test(`${track.name} requires more reach than the Runner starter`,()=>{const r=simulate(track,presetDesign('runner'));assert.equal(r.finished,false);assert.ok(r.x<track.length*.5);});
}
for(const id of ['sawtooth','trenches','skyline'])for(const material of ['rigid','bendy'])test(`${material} full-size wheel cannot clear ${id}`,()=>{assert.equal(simulate(TRACKS.find(t=>t.id===id),circle(),material).finished,false);});
