// Web console tests, Ghoul Rush's Torch Mob (Hollow End Village's bonus round, between the Square and the Green): its shape (every ditch and the bridge clear with a jump and swallow a wagon that does not jump, every low can be ducked, spacing, checkpoints), the wagon's speed (the brake that is also a duck), every obstacle's cost and cause (barrels, crates, washing lines, inn signs, pitchforks, torches, horses, ditches, the river, the mob), the throwers' wind-up and aim, shooting torches and forks out of the air, the horses, the pursuit meter (the gap that clean riding opens and braking, hits and fire close), the hay fire, the catch, hearts of its own, the grade and the dice, endless lives, the checkpoints, the finish, no random numbers, its sounds and its drawing on a fake canvas, and bots that play it well and badly.
// Run with: node --test scripts/test-web-console-activities-ghoul-wagon.mjs
/* -------------------------------------------------------------- the room */
test("Ghoul Rush's Torch Mob is Hollow End Village's fourth room, between the Square and the Green: lit, no key, no boss, no pickups, a ride about 60 to 75 seconds long, a bonus round that plays its own track",()=>{
assert.ok(BRIDGE_LINE>0,"a line ends at the bridge");
assert.deepEqual([R.blocks.length,R.lows.length,R.throwers.length,R.horses.length,lines.length-1],[7,6,9,2,5],"barrels and crates, washing and signs, throwers, horses, ditches and the bridge");
});
test("Ghoul Rush's Torch Mob: the lip's launch alone carries the wagon onto the green at any speed it can have there, landing 4 to 45 past its start",()=>{
assert.ok(s,`ditch ${i}: a jump ${early} early at ${v} lands`);
assert.equal(s.line,i+1,`ditch ${i} cleared, at ${v}, ${early} early`);
}
}
}
});
test("Ghoul Rush's Torch Mob: the collapsed bridge needs the ramp and a jump at its lip (within about 11 units early) at the wagon's own speed; braking all the way, or no jump, drops it in the river; the horses' panic speed carries it over",()=>{
consti=BRIDGE_LINE;
consta=lines[i];
constlip=a.x1;
constgap=lines[i+1].x0-lip;
assert.ok(gap>=22&&gap<=30,`the span is ${gap} wide`);
assert.equal(none(wg.WAGON_V),null,"the ramp alone is not enough at WAGON_V");
assert.equal(none(wg.BRAKE_V),null);
assert.ok(none(wg.WAGON_V+wg.PANIC_V),"the bolting horses clear it on the ramp alone");
for(constearlyof[0,2,4,8]){
consts=jump(wg.WAGON_V,early);
assert.ok(s&&s.line===i+1,`a jump ${early} early at WAGON_V lands on the far side`);
}
assert.equal(jump(wg.WAGON_V,16),null,"a jump far too early falls short");
assert.equal(jump(wg.BRAKE_V,0),null,"braked all the way, even a good jump falls");
assert.ok(jump(36,0),"a wagon a little slow still clears");
assert.equal(R.surge.length,1);
assert.ok(R.surge[0][1]<lip-20&&R.surge[0][0]>R.bridge[0],"the mob quickens on the bridge's run-up, before the ramp");
});
test("Ghoul Rush's Torch Mob: every thing is on a line, spaced for a player (20 between jumps and 30 beside a duck), a low's underside between a ducked box and a standing one, checkpoints clear of everything",()=>{
assert.ok(gap>=(wins[i][2]&&wins[i+1][2]?20:30),`windows at ${wins[i][1]} and ${wins[i+1][0]} are ${gap.toFixed(0)} apart`);
}
constcs=R.checks;
assert.equal(cs.length,7);
for(leti=0;i<cs.length;i++){
assert.ok(ct.linesAt(R,cs[i]).length,`checkpoint ${i} on the road`);
if(i)assert.ok(cs[i]-cs[i-1]>=250&&cs[i]-cs[i-1]<=450,`${cs[i]-cs[i-1]} between checkpoints`);
for(const[w0,w1]ofwins)assert.ok(w0-cs[i]>8||cs[i]-w1>4,`a thing at ${w0} near checkpoint ${i}`);
}
assert.ok(cs[0]<500&&R.finish-cs.at(-1)>150);
});
/* ------------------------------------------------------------ the wagon */
test("Ghoul Rush's Torch Mob rolls at WAGON_V on the road whatever key is held, DOWN brakes it toward BRAKE_V and ducks, letting go brings it back, and it keeps its speed in the air",()=>{
assert.ok(Math.abs(flat.runner.v-wg.WAGON_V)<0.5,"back to speed");
assert.equal(flat.you.ducking,false);
// A press of up jumps rather than ducking, and the air holds the speed.
flat.input.down=true;
press(flat);
run(flat,40);
assert.equal(flat.you.state,"air");
assert.equal(flat.you.ducking,false);
constv=flat.runner.v;
run(flat,300);
assert.equal(flat.runner.v,v,"no brake in the air");
flat.input.down=false;
});
test("Ghoul Rush's Torch Mob jumps about 7 high for about 0.6 s (a gap of about 26 at WAGON_V), a press saved for a landing jumps on it, one just after a line's end still jumps, and one long after does not",()=>{
test("Ghoul Rush's Torch Mob: a barrel and a crate are cleared by a jump and cost a heart otherwise (causes barrel and crate), each only once, smashed after",()=>{
test("Ghoul Rush's Torch Mob: DOWN passes under a washing line and an inn sign (at the price of the brake), a standing wagon is hit (causes wash and sign), and a jump does not clear one",()=>{
assert.equal(j.bonusRound.hearts,4,"a jump runs into it");
assert.equal(events(j,"lose")[0].cause,"wash");
});
test("Ghoul Rush's Torch Mob: a villager winds up WIND_MS once the wagon is WIND_NEAR short, then throws at where the wagon will be, and a pitchfork meets a wagon at WAGON_V THROW_MEET short of him",()=>{
constw=synth({track:FLAT,throwers:[[400,0,0]]});
wagonAt(w,400-wg.WIND_NEAR-8,0);
run(w,100);
assert.equal(w.runner.throwers[0].state,"idle","still out of range");
assert.ok(p.T>0.35&&p.T<0.6,`${p.T} s of flight`);
// Nothing else is thrown.
run(w,1500);
assert.equal(events(w,"wagonThrow").length,1);
});
test("Ghoul Rush's Torch Mob: a hurled pitchfork costs a heart (cause fork) to a standing wagon, passes over a ducked one and under a jumping one, and the same torch is shot or ducked in vain",()=>{
assert.equal(torchJump.bonusRound.hearts,5,"jumped the torch");
assert.equal(torchJump.runner.fireMs,0);
});
test("Ghoul Rush's Torch Mob: a torch that lands on the hay is a heart (cause torch), sets it alight for FIRE_MS, and the mob closes faster while it burns; ducking smothers it sooner",()=>{
assert.ok(burn>wg.FIRE_MS-200&&burn<wg.FIRE_MS+100,`${burn} ms burning`);
assert.equal(events(w,"wagonOut").length,1);
// Smothered by ducking: out in a third of the time.
consts=set();
s.input.down=true;
constquick=until(s,()=>s.runner.fireMs<=0,5000);
s.input.down=false;
assert.ok(quick<(wg.FIRE_MS/wg.SMOTHER)+150,`${quick} ms smothered`);
// The fire's pull on the mob, alone: it runs faster with the hay alight.
consta=synth({track:FLAT});
constb=synth({track:FLAT});
b.runner.fireMs=1e9;
a.runner.gap=b.runner.gap=20;
run(a,1000);
run(b,1000);
assert.ok(a.runner.gap-b.runner.gap>wg.FIRE_BOOST-1.5,`${a.runner.gap} to ${b.runner.gap}`);
});
test("Ghoul Rush's Torch Mob: bolts shoot a pitchfork (40 points) or a torch (60 points) out of the air, which pushes the mob back and counts as an act; a torch shot is no fire",()=>{
test("Ghoul Rush's Torch Mob: a spooked horse rears HORSE_REAR_MS when the wagon is HORSE_NEAR short, then charges; a jump clears it, a standing wagon is trampled (cause horse), and HORSE_HP bolts turn it back (120 points)",()=>{
assert.equal(s.bonusRound.hearts,5,"turned back, no harm");
});
/* -------------------------------------------------------------- the mob */
test("Ghoul Rush's Torch Mob: the mob runs at MOB_V, so clean riding opens the gap (to GAP_MAX), the brake closes it, a hit shoves it HIT_CLOSE closer, and it starts at GAP_START",()=>{
constw=synth({track:FLAT});
assert.equal(w.runner.gap,wg.GAP_START);
run(w,1000);
assert.ok(Math.abs(w.runner.gap-(wg.GAP_START+wg.WAGON_V-wg.MOB_V))<0.2,`${w.runner.gap} after a clean second`);
run(w,5000);
assert.equal(w.runner.gap,wg.GAP_MAX,"never over GAP_MAX");
w.input.down=true;
run(w,1500);
constg=w.runner.gap;
assert.ok(g<wg.GAP_MAX-8,`braking closed it to ${g.toFixed(1)}`);
run(w,1000);
w.input.down=false;
assert.ok(g-w.runner.gap>6,"held down, it keeps closing");
// A hit shoves it.
consth=synth({track:FLAT,blocks:[[60,0,0]]});
h.runner.gap=30;
wagonAt(h,50,0);
constbefore=h.runner.gap;
until(h,()=>h.bonusRound.hearts<5,1000);
assert.ok(before-h.runner.gap>wg.HIT_CLOSE-1,`${before} to ${h.runner.gap}`);
});
test("Ghoul Rush's Torch Mob: inside PANIC_ON the horses bolt (PANIC_V faster) until PANIC_OFF, so the gap recovers; the brake still overrides it",()=>{
assert.ok(b.runner.v<wg.BRAKE_V+1,"braking all the same");
});
test("Ghoul Rush's Torch Mob: the mob quickens on a surge span, and a catch at CATCH_GAP is a heart (cause mob) that sends it back to GAP_RESET, with the wagon rolling on",()=>{
consta=synth({track:FLAT,surge:[[0,1e6,7]]});
constb=synth({track:FLAT});
a.runner.gap=b.runner.gap=30;
run(a,1000);
run(b,1000);
assert.ok(Math.abs(b.runner.gap-a.runner.gap-7)<0.3,`${b.runner.gap} to ${a.runner.gap}`);
assert.ok(w.bonusRound.perf.hits.includes("m1"),"a catch counts against the grade");
assert.equal(w.runner.done,false);
assert.equal(w.lives,3);
// While blinking safe a catch costs nothing (the Garlic's shield too) but still sends it back.
constsafe=synth({track:FLAT});
safe.you.safeMs=1e9;
safe.runner.gap=wg.CATCH_GAP+0.05;
safe.input.down=true;
until(safe,()=>safe.runner.catches>0,3000);
safe.input.down=false;
assert.equal(safe.bonusRound.hearts,5);
assert.equal(safe.runner.gap,wg.GAP_RESET);
});
/* -------------------------------------------------------- falls, the end */
test("Ghoul Rush's Torch Mob: a ditch with no jump is a heart (cause ditch), the wagon goes back on the road ahead at WAGON_V and rolls on; the bridge's gap is the river; a jump over costs nothing",()=>{
assert.ok(r.you.x>=lines[ditch+1].x0,`back on the road at ${r.you.x}`);
assert.equal(r.runner.line,ditch+1);
assert.equal(r.runner.v,wg.WAGON_V);
run(r,300);
assert.ok(r.you.x>lines[ditch+1].x0);
// The bridge.
constb=wagonRound();
wagonAt(b,lines[BRIDGE_LINE].x1-14,BRIDGE_LINE);
until(b,()=>b.bonusRound.hearts<5,3000);
assert.equal(events(b,"lose")[0].cause,"river");
assert.equal(b.runner.line,BRIDGE_LINE+1);
// A jump clears a ditch for free.
constj=wagonRound();
wagonAt(j,L.x1-10,ditch);
until(j,()=>lines[ditch].x1-j.you.x<2,1000);
press(j);
run(j,1200);
assert.equal(j.bonusRound.hearts,5);
assert.equal(j.runner.line,ditch+1);
voidw;
});
test("Ghoul Rush's Torch Mob: the last heart gone ends the round with nothing at once (no life lost, the dice in hand kept) and the run goes on to the Green",()=>{
constw=synth({track:FLAT,blocks:[[70,0,0]]});
w.dice=4;
w.lives=3;
w.bonusRound.hearts=1;
wagonAt(w,60,0);
until(w,()=>w.phase==="clear",6000);
assert.equal(w.phase,"clear");
assert.equal(w.bonusRound.hearts,0);
assert.equal(w.bonusRound.won,false);
assert.equal(w.bonusRound.dice,0);
assert.equal(w.lives,3,"no life lost");
assert.equal(w.dice,4,"the dice in hand kept");
assert.equal(w.over,false,"not game over");
assert.equal(events(w,"bonusEnd").length,1);
assert.equal(events(w,"bonusEnd")[0].won,false);
run(w,ghoul.CARD_LOST_MS+100);
assert.equal(w.spec.id,"green");
assert.equal(w.runner,null);
assert.equal(w.bonusRound,null);
assert.equal(w.lives,3);
assert.equal(w.dice,4);
});
test("Ghoul Rush's Torch Mob: the checkpoints are passed in order (an event each) and the ride goes back to the last one passed after the last heart",()=>{
// A place after that goes back to the checkpoint, with the catches kept.
w.runner.catches=2;
wg.WAGON.place[0](w,{});
assert.equal(w.runner.check,2);
assert.equal(w.you.x,R.checks[2]);
assert.equal(w.runner.catches,2);
assert.equal(w.runner.gap,wg.GAP_START);
});
test("Ghoul Rush's Torch Mob: off the lip the wagon launches, lands on the green and stops (wagonFinish), the door opens, and walking out ends the round with 3 to 9 Lucky dice",()=>{
test("Ghoul Rush's Torch Mob: no random number is drawn in the room (a ride of 20 seconds, jumping, ducking and shooting, on a draw that throws)",()=>{
constw=wagonRound();
w.you.safeMs=1e9;
for(lett=0;t<20000;t+=16){
w.input.fire=true;
w.input.down=t%3000<400;
if(t%1900<20)press(w);
w.you.safeMs=1e9;
ghoul.advance(w,16,never);
w.events.length=0;
}
assert.ok(w.you.x>600);
assert.equal(w.runner.id,"wagon");
});
test("Ghoul Rush's Torch Mob's grade: the dice formula, shooting 8 things for the die, and the steady die (the mob kept far: the gap's average over the ride)",()=>{
test("Ghoul Rush's Torch Mob draws: the room, the wagon on the road, in the air and braking, each thing (barrels, crates, washing, signs, throwers winding up, throws in flight, horses in each state), the mob close and far, the fire, a crash, the finish and the cards",()=>{
assert.ok(off>4&&off<70,`the wagon stays in view (${off.toFixed(1)} from the left edge at ${round.you.x.toFixed(0)})`);
}
round.events.length=0;
}
return{round,lost,ms:t};
}
test("Ghoul Rush's Torch Mob: a bot that dodges well finishes the whole road in 60 to 76 seconds, 6 to 9 dice, a few hearts lost at most, past every checkpoint",()=>{
test("Ghoul Rush's Torch Mob: a bot that never dodges loses all five hearts before the first half, ends with 0 dice and the run goes on",()=>{
for(letseed=1;seed<=6;seed++){
const{round,lost}=rideWith(seed,idleBot);
constb=round.bonusRound;
assert.equal(b.won,false,"never finishes");
assert.equal(b.dice,0);
assert.equal(b.hearts,0);
assert.equal(lost.length,5);
assert.ok(round.you.x<ROOM.length*0.6,`out at ${round.you.x}`);
assert.equal(round.lives,3);
assert.equal(round.over,false);
}
});
test("Ghoul Rush's Torch Mob: a bot that rides without ever braking or ducking but holds fire keeps the mob far, and one that holds DOWN the whole way is caught again and again",()=>{
test("Ghoul Rush's Torch Mob telegraphs: DUCK over washing lines, signs and pitchfork throwers, JUMP over ditches, the bridge, barrels, crates, torch throwers and horses, words only on the first three of each kind, the same every time",()=>{
constmarks=telegraphMarks(R);
assert.equal(marks.length,(R.track.length-1)+R.blocks.length+R.lows.length+R.throwers.length+R.horses.length,"one per thing to dodge");