// Web console tests, Ghoul Rush's Servants' Back Stairs (the East Wing's bonus round, between the Attic and the Crypt): its shape (every gap between flights clears with a jump and swallows a tray that does not jump, every low can be ducked, spacing, checkpoints, greased stretches, the clock), the tray's speed on slopes and grease, its jump and duck, a pot, cutlery, a ham, pans, the cook's dish, the domes and plates (the courses), the cherries, a fall down the stairs, the checkpoint, the jump off the last shelf and the door, the bonus round's hearts and dice (3 to 9), endless lives for every new cause, a voice for every event, the drawing, and bots that ride the whole route (one that dodges well, one that never does).
// Run with: node --test scripts/test-web-console-activities-ghoul-tray.mjs
/* -------------------------------------------------------------- the room */
test("Ghoul Rush's Servants' Back Stairs is the East Wing's fourth room, between the Attic and the Crypt: lit, no key, no boss, no pickups, a ride about 60 to 70 seconds long, a bonus round with its own track",()=>{
assert.ok(ghoulSfx.default.music.ghoulTrayRide,"its own track");
assert.deepEqual(Object.keys(tr.TRAY.monsters),[],"no new monster kinds");
assert.equal(LOOKS.tray,TRAY_LOOKS.tray);
assert.equal(LOOKS.tray.pack,"tray");
assert.ok(Object.isFrozen(R)&&Object.isFrozen(R.track)&&Object.isFrozen(R.track[0][0])&&Object.isFrozen(R.domes[0]),"frozen all the way down");
assert.ok(ROOM.horde.length===0&&ROOM.spawns.length===0&&ROOM.items.length===0,"no monsters and no pickups: the things on the route are the pack's own");
assert.equal(ROOM.ground.length,2);
assert.ok(ROOM.ground[0][1]<60&&ROOM.ground[1][0]>ROOM.length-100,"floor only at the ends");
assert.ok(R.domes.length>=12&&R.plates.length>=10,"more courses than the seven a meal needs");
assert.ok(R.domes.length+R.plates.length>=3*tr.COURSES_GOAL,"a seven course meal is within reach, not a given");
assert.ok(R.domes.some(([,,lift])=>lift===0)&&R.domes.some(([,,lift])=>lift>=5),"some domes on the track, some in the air");
assert.ok(R.plates.some(([,,lift])=>lift<=3)&&R.plates.some(([,,lift])=>lift>=4),"plates to shoot standing and from a jump");
assert.ok(ROOM.candy.length>=200,"cherries all along");
assert.match(R.how,/UP to jump, DOWN to duck/);
});
test("Ghoul Rush's Servants' Back Stairs: the lip's launch alone carries the tray onto the dining table at any speed it can have there, landing 2 to 40 past its start",()=>{
constlip=lines.at(-1);
constend=lip.pts.at(-1);
constrise=ct.slopeOf(R,lines.length-1,lip.x1);
assert.ok(rise>=tr.RAMP_SLOPE,"the last shelf ends rising");
assert.ok(x>=R.finish+2&&x<=R.finish+40,`at ${v} it lands ${x-R.finish} past the table's start`);
}
});
test("Ghoul Rush's Servants' Back Stairs: every gap between flights clears with a jump at the edge or a few units early, and a tray that never jumps drops into it",()=>{
assert.equal(lines.length-1,17,"seventeen gaps");
for(leti=0;i+1<lines.length-1;i++){
consta=lines[i];
constb=lines[i+1];
constgap=b.x0-a.x1;
assert.ok(gap>=9&&gap<=18,`gap ${i} is ${gap} wide`);
constend=a.pts.at(-1);
constslope=ct.slopeOf(R,i,a.x1);
assert.ok(slope<0,"gaps lie at the foot of a flight (no ramp launch)");
for(constvof[40,44,50,60]){
assert.equal(tr.flight(R,a.x1,end[1],slope*v,v),null,`gap ${i}, no jump, at ${v}`);
test("Ghoul Rush's Servants' Back Stairs: every thing is on a line, off the ends, spaced for a player (22 between jumps and 38 between a jump and a duck), greased stretches flat, a low's underside between a ducked box and a standing one",()=>{
constjumps=[];
for(const[x,line,kind]ofR.pots){
assert.ok(ct.trackY(R,line,x)!==null,`a pot at ${x} stands on line ${line}`);
jumps.push([x-(kind?2.4:2),x+(kind?2.4:2)]);
assert.ok(x-lines[line].x0>8&&lines[line].x1-x>14,`a pot at ${x} well inside its line`);
}
// A cook's dish meets the tray about 14 to 2 short of him.
for(const[x,line]ofR.cooks){
assert.ok(ct.trackY(R,line,x)!==null);
assert.ok(x-lines[line].x0>50&&lines[line].x1-x>14,`a cook at ${x} well inside his line`);
for(leti=0;i+1<inside.length;i++)assert.ok(inside[i+1][0]-inside[i][1]>=30,`jumps at ${inside[i][1]} and ${inside[i+1][0]} on the grease`);
}
// Checkpoints every 300 to 400 units, each on a shelf and clear of a thing.
constcs=R.checks;
for(leti=0;i<cs.length;i++){
assert.ok(ct.linesAt(R,cs[i]).length,`checkpoint ${i} on a shelf`);
if(i)assert.ok(cs[i]-cs[i-1]>=300&&cs[i]-cs[i-1]<=400,`${cs[i]-cs[i-1]} between checkpoints`);
for(const[j0,j1]ofjumps)assert.ok(j0-cs[i]>20||cs[i]-j1>4,`a thing at ${j0} near checkpoint ${i}`);
}
assert.ok(cs[0]<450&&R.finish-cs.at(-1)>200);
});
/* ------------------------------------------------------------ the tray */
test("Ghoul Rush's Servants' Back Stairs: the tray rolls at TRAY_V on the flat, GREASE_V on the grease, faster down a flight and slower up a shelf, never past TRAY_MIN or TRAY_MAX, and no key changes it",()=>{
constflat=synth({track:FLAT});
run(flat,3000);
assert.ok(Math.abs(flat.runner.v-tr.TRAY_V)<0.5,`${flat.runner.v} on the flat`);
constslick=synth({track:FLAT,grease:[[0,4000]]});
run(slick,4000);
assert.ok(Math.abs(slick.runner.v-tr.GREASE_V)<0.5,`${slick.runner.v} on the grease`);
assert.ok(tr.GREASE_V>tr.TRAY_V+10,"a real pickup");
assert.ok(Math.abs(keyed.runner.v-tr.TRAY_V)<0.5,"left does not brake");
run(keyed,1000,{right:true});
assert.ok(Math.abs(keyed.runner.v-tr.TRAY_V)<0.5,"right does not lean");
assert.equal(greasyAt(slick,100),true);
assert.equal(greasyAt(flat,100),false);
});
functiongreasyAt(round,x){
returntr.greasy(round.spec.ride,x);
}
test("Ghoul Rush's Servants' Back Stairs: the tray jumps about 13 high for about three quarters of a second, a press saved for a landing jumps on it, one just after a line's end still jumps",()=>{
test("Ghoul Rush's Servants' Back Stairs: down ducks (and a press of up jumps instead of ducking), a ducked Planny passes under a ham or pans and a standing one hits them (causes ham and pans), at the cost of a heart",()=>{
assert.equal(jump.bonusRound.hearts,4,"a jump does not clear a low");
constboth=synth({track:FLAT});
both.input.down=true;
press(both);
run(both,20);
assert.equal(both.you.ducking,false);
assert.equal(events(both,"trayJump").length,1);
});
test("Ghoul Rush's Servants' Back Stairs: a rolling pot and a drop of cutlery are cleared by a jump and cost a heart otherwise (causes pot and cutlery), each only once",()=>{
test("Ghoul Rush's Servants' Back Stairs: a cook wakes COOK_NEAR short, winds up, flings a dish that flies back along the track (jump it: cause dish otherwise), and one bolt shoots the cook (150 points) or the dish",()=>{
assert.equal(dish.bonusRound.perf.acts,0,"not a course");
});
test("Ghoul Rush's Servants' Back Stairs: running through a dome serves a course (80 points; a high one takes a jump), and a plate is served by a bolt, not by touching it (120 points)",()=>{
// A high plate needs a bolt from a jump: a standing bolt flies under it.
consthigh=synth({track:FLAT,plates:[[100,0,6]]});
high.input.fire=true;
until(high,()=>high.you.x>130,3000);
assert.equal(high.runner.plates[0],false,"a level bolt flies under it");
// What is eaten stays eaten after a restart in the same room.
constagain=synth({track:FLAT,domes:[[60,0,0]]});
again.runner.domes[0]=true;
again.runner.served=1;
again.runner.check=-1;
tr.TRAY.place[0](again,{});
assert.equal(again.runner.domes[0],true);
assert.equal(again.runner.served,1);
});
test("Ghoul Rush's Servants' Back Stairs: bolts follow the stairs (the same height over the track on a descent)",()=>{
constprobe=synth({track:DOWN});
probe.input.fire=true;
run(probe,300);
probe.input.fire=false;
assert.ok(probe.shots.length>0);
for(constsofprobe.shots){
constover=s.y-(40-0.15*s.x);
assert.ok(Math.abs(over-ghoul.SHOT_Y)<0.5,`a bolt ${over.toFixed(2)} over the track`);
}
assert.equal(probe.bonusRound.perf.acts,0);
});
test("Ghoul Rush's Servants' Back Stairs: a gap with no jump is a heart (cause tumble), the tray goes back on the shelf ahead at TRAY_V and rolls on; a jump over it costs nothing",()=>{
assert.equal(fall.runner.line,1,"back on the shelf ahead");
assert.equal(fall.bonusRound.hearts,4);
consthop=synth({track:gap});
trayAt(hop,30,0);
run(hop,500);
press(hop);
run(hop,20);
hop.input.up=false;
until(hop,()=>hop.you.x>100,3000);
assert.equal(hop.bonusRound.hearts,5,"jumped");
});
test("Ghoul Rush's Servants' Back Stairs: 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 Crypt",()=>{
assert.equal(round.phase,"bossintro","the boss room opens on its card");
skipBossIntro(ghoul,round);
assert.equal(round.phase,"ready");
});
test("Ghoul Rush's Servants' Back Stairs: the checkpoints are passed in order (an event each) and the ride goes back to the last one after the last heart's restart",()=>{
assert.equal(round.you.x,R.checks[1],"back at the last checkpoint passed");
assert.equal(round.runner.check,1);
});
test("Ghoul Rush's Servants' Back Stairs: off the lip the tray launches, lands on the table and stops (trayFinish), the door opens, and walking out ends the round with 3 to 9 Lucky dice",()=>{
test("Ghoul Rush's Servants' Back Stairs: no random number is drawn in the room (a ride of 20 seconds, jumping and shooting, on a draw that throws)",()=>{
constround=trayRound();
trayAt(round,120,1,{safe:true});
round.input.fire=true;
for(lett=0;t<20000;t+=4){
if(t%1500===0)press(round);
ghoul.advance(round,4,never);
round.events.length=0;
round.you.safeMs=1e9;
if(round.phase!=="play")break;
}
assert.ok(round.you.x>600);
});
/* ----------------------------------------------------------- the grade */
test("Ghoul Rush's Servants' Back Stairs' grade: the dice formula, a seven course meal for the die, and the cherries die (45% of them)",()=>{
test("Ghoul Rush's Servants' Back Stairs: the Garlic shield takes a hit instead of a heart",()=>{
constround=synth({track:FLAT,pots:[[60,0,0]]});
round.you.garlic=true;
until(round,()=>round.you.x>70,3000);
assert.equal(round.bonusRound.hearts,5);
assert.equal(round.you.garlic,false,"spent");
});
/* ------------------------------------------------------ sounds and words */
test("Ghoul Rush's Servants' Back Stairs: every event has a voice that plays, every cause has words and a sound, and every tone exists and is at most 1.2 s",()=>{
assert.deepEqual(Object.keys(EVENT_VOICE).sort(),[...tr.EVENTS].sort(),"a voice for every event and no more");
test("Ghoul Rush's Servants' Back Stairs draws: the room in a lit and a dark one, the tray on the shelf, in the air and ducking, each thing (pots, cutlery, hams, pans, cooks in each state, a dish, domes and plates whole and taken), a crash, the finish and the cards",()=>{
assert.ok(off>4&&off<70,`the tray 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 Servants' Back Stairs: a bot that dodges well finishes the whole route in 60 to 76 seconds, 6 to 9 dice, a seven course meal, past every checkpoint",()=>{
test("Ghoul Rush's Servants' Back Stairs: a bot that never dodges (holding fire) loses all five hearts before the first third, 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.4,`out at ${round.you.x}`);
test("Ghoul Rush's Servants' Back Stairs telegraphs: DUCK over hams and pans, JUMP over gaps, pots and cutlery, SHOOT for cooks, none for domes or plates, words only on the first three of each kind, the same every time",()=>{