// Web console tests, Ghoul Rush's Drowned Lantern (Gallows Bog's bonus round, between the Stilt House and the Drowning Pool, a top-down game on one screen and not a ride): the island, the walk and the slide, the flare and the oil, the shrines and the run to the boat, each hunter's one rule (the Lurker hears steps on wood and dashes down a lane through where it heard you, the wisps guard the shrines and burst in a flare, the leeches never enter the light, the bog bodies take only someone standing still, Old Mother Bog's hand), the hearts and the grade, the clock, determinism, the balance (a bot that ignores the hunters loses, one that plays them wins), the voices, the hums and the drawing.
// Run with: node --test scripts/test-web-console-activities-ghoul-lantern.mjs
// A round in the Drowned Lantern set up the way a room is, in play.
functionlanternRound(seed=5){
constround=ghoul.newRound(seed);
round.lives=3;
round.dice=0;
ghoul.setupRoom(round,"lantern");
round.phase="play";
round.monsters.length=0;
round.hordeMs=Infinity;
round.events.length=0;
returnround;
}
// The same round with every hunter out of the way (the Lurker resting for good, the rest gone, Mother's hand held off), for what the hunters would spoil.
/* -------------------------------------------------------------- the room */
test("Ghoul Rush's Drowned Lantern is Gallows Bog's fourth room, between the Stilt House and the Drowning Pool: lit, no key, no boss, a bonus round on one fixed screen with a 90 second clock",()=>{
assert.deepEqual([ROOM.title,ROOM.sub],["The Drowned Lantern","Keep the flame lit, and keep quiet"]);
assert.equal(ROOM.bonus,true);
assert.equal(ROOM.dark,false,"the room's own art is the night");
assert.equal(ROOM.key,null);
assert.equal(ROOM.boss,null);
assert.equal(R.runner,"lantern");
assert.equal(R.time,lz.TIME_S*1000);
assert.equal(ghoul.timeFor(ROOM),R.time,"its own clock");
assert.equal(ROOM.length,ghoul.FIELD_W,"one fixed screen: the camera never moves");
assert.ok(ROOM.door<ROOM.length&&ghoul.groundAt(ROOM,ROOM.door)>-Infinity,"a door with floor to stand at");
assert.ok(ROOM.horde.length===0&&ROOM.spawns.length===0&&ROOM.items.length===0&&ROOM.candy.length===0,"no monsters or pickups: the hunters are the pack's own");
assert.ok(Object.isFrozen(R)&&Object.isFrozen(R.hummocks)&&Object.isFrozen(R.hummocks[0])&&Object.isFrozen(R.lurker.route)&&Object.isFrozen(R.wisps[0]),"frozen all the way down");
assert.equal(ghoul.ROOM_MUSIC.lantern,"ghoulLanternTheme","plays its own theme");
assert.deepEqual(Object.keys(lz.LANTERN.monsters),[],"no new monster kinds");
test("Ghoul Rush's Drowned Lantern: the island fits the map and is all joined, every shrine stands on a hummock, the boat is in reach of the landing, the pool is open water",()=>{
for(const[x,y,r]ofR.hummocks)assert.ok(x-r>=lz.MAP.x0-1&&x+r<=lz.MAP.x1+1&&y-r>=lz.MAP.y0-1&&y+r<=lz.MAP.y1+1,`hummock at ${x},${y}`);
assert.equal(reach().size,R.hummocks.length,"every hummock is joined to the landing");
for(consthofR.shrines)assert.ok(R.hummocks[h],`shrine on hummock ${h}`);
assert.equal(newSet(R.shrines).size,lz.SHRINES);
assert.ok(!R.shrines.includes(0),"the landing is no shrine");
assert.ok(lz.onMoss(R,...R.start),"Planny starts on the landing's moss");
assert.ok(Math.hypot(R.boat[0]-R.start[0],R.boat[1]-R.start[1])<8,"the boat is at the landing");
const[lx,ly,lr]=R.hummocks[0];
assert.ok(Math.hypot(R.boat[0]-lx,R.boat[1]-ly)-lr<lz.BOAT_R,"the landing's edge reaches the boat");
assert.ok(!lz.onMoss(R,...R.pool),"Mother's pool is no hummock");
});
test("Ghoul Rush's Drowned Lantern's tables: each shrine has one guardian wisp starting on its circle, the roamers sleep in Mother's pool till the third, fourth and fifth shrine, and every bog body lies in the water beside a plank",()=>{
assert.ok(Math.abs(Math.hypot(w.home[0]-sx,w.home[1]-sy)-lz.ORBIT_R)<0.1,`wisp of shrine ${w.shrine} on its circle`);
}
constroam=R.wisps.filter((w)=>w.shrine<0);
assert.deepEqual(roam.map((w)=>w.wake),[3,4,5]);
for(constwofroam)assert.deepEqual([...w.home],[...R.pool],"out of the pool");
for(const[x,y]ofR.bodies){
assert.ok(!lz.onIsland(R,x,y),`the body at ${x},${y} is in the water`);
constd=onAxis(x,y);
assert.ok(d<lz.BODY_NOTICE&&d>lz.PLANK_HALF,`beside a plank (${d.toFixed(1)} from its middle)`);
}
});
/* ------------------------------------------------------------- the walk */
test("Ghoul Rush's Drowned Lantern: the arrows walk Planny at WALK_V (two at once a diagonal) and never off the moss and planks; the walk slides along a crooked plank with one arrow",()=>{
constround=quiet(lanternRound());
constc=round.runner;
const[x0,y0]=R.start;
assert.deepEqual([c.x,c.y],[x0,y0]);
run(round,400,{right:true});
assert.ok(Math.abs(c.x-x0-lz.WALK_V*0.4)<0.1,`right at WALK_V (${(c.x-x0).toFixed(2)})`);
assert.equal(c.y,y0);
assert.equal(c.fx,1);
// A diagonal is no faster.
at(round,x0,y0);
run(round,300,{up:true,right:true});
assert.ok(Math.abs(Math.hypot(c.x-x0,c.y-y0)-lz.WALK_V*0.3)<0.2,"diagonal at WALK_V");
// Into the water: it stays on the island, wherever the keys push.
/* -------------------------------------------------------- the flare, oil */
test("Ghoul Rush's Drowned Lantern: SPACE flares once a press (holding does not repeat): FLARE_OIL of oil, FLARE_CD_MS between, a sputter and no flare without the oil for one",()=>{
test("Ghoul Rush's Drowned Lantern: the oil burns down over OIL_MS and the light shrinks with it; out, the flame gutters (once, and the grade's steady hand is gone); a shrine fills it again",()=>{
/* ----------------------------------------------------------- the shrines */
test("Ghoul Rush's Drowned Lantern: standing on a shrine's stone SHRINE_MS lights it (200 points, the oil full, its guardian laid to rest); the time is kept if you step off; a lit one stays lit",()=>{
constround=quiet(lanternRound());
constc=round.runner;
const[sx,sy]=lz.shrineAt(R,0);
at(round,sx,sy);
c.oil=0.5;
run(round,lz.SHRINE_MS/2,{});
assert.equal(c.lit,0);
at(round,sx+lz.SHRINE_R+1,sy);
run(round,500,{});
assert.ok(c.shrines[0]>=lz.SHRINE_MS/2-8,"the time is kept");
assert.equal(wisp.state,"gone","its guardian is laid to rest");
run(round,2000,{});
assert.equal(c.lit,1,"lit once");
});
test("Ghoul Rush's Drowned Lantern: the third shrine wakes Old Mother Bog, the fifth raises her (and sends the Lurker cowering); then the boat at the landing is the way out",()=>{
constround=quiet(lanternRound());
constc=round.runner;
R.shrines.forEach((h,i)=>{
at(round,...R.hummocks[h].slice(0,2));
run(round,lz.SHRINE_MS+50,{});
assert.equal(c.lit,i+1);
assert.equal(c.mother.stir,i+1,"her eyes open a fifth a shrine");
test("Ghoul Rush's Drowned Lantern: all five lit and Planny at the boat ends the round: the bonus ends won with 3 to 9 Lucky dice added, no heart or life lost; the boat does nothing before then",()=>{
constearly=quiet(lanternRound());
at(early,R.boat[0]+1,R.boat[1]);
run(early,500,{});
assert.equal(early.runner.done,false,"the boat waits for the five");
// Planny on the plank between hummocks 1 and 9 (y 44), x along it.
constPLANK_Y=R.hummocks[1][1];
test("Ghoul Rush's Drowned Lantern's Bog Lurker hears steps on wood within STEP_HEAR (not beyond, not on the moss, not standing still) and swims at LURKER_V to where it heard them",()=>{
test("Ghoul Rush's Drowned Lantern's Lurker strikes where it HEARD you: within AIM_FROM it lines up a lane through that spot (DASH_PAST beyond) for AIM_MS, then dashes: on the lane a heart (cause lanternLurker), just off it a close call (an act), then it rests deaf for REST_MS",()=>{
test("Ghoul Rush's Drowned Lantern's guardian wisps circle their shrine at ORBIT_R, rush a lantern within GUARD_SENSE (while it is within LEASH of the shrine) at WISP_V, and have you at WISP_CATCH (a heart, cause lanternWisp)",()=>{
const{round,w}=guardRound();
const[sx,sy]=lz.shrineAt(R,0);
at(round,...R.start);
run(round,1500,{});
assert.equal(w.state,"guard");
assert.ok(Math.abs(Math.hypot(w.x-sx,w.y-sy)-lz.ORBIT_R)<0.05,"on its circle");
assert.equal(w.state,"popped","it bursts on you");
// Out of the leash it goes home.
constback=guardRound();
at(back.round,sx,sy+lz.GUARD_SENSE-4);
run(back.round,100,{});
assert.equal(back.w.state,"chase");
at(back.round,sx+lz.LEASH+6,sy+10);
run(back.round,3000,{});
assert.equal(back.w.state,"guard");
});
test("Ghoul Rush's Drowned Lantern: a flare bursts every wisp within FLARE_R (an act and 80 points each, more at once is a combo), not one beyond; a burst guardian comes back after WISP_REFORM_MS unless its shrine is lit",()=>{
test("Ghoul Rush's Drowned Lantern's roaming wisps sleep in Mother's pool until their shrine count, then drift after a lantern within ROAM_SENSE",()=>{
assert.ok(nearest>=0,`never inside the light (${nearest.toFixed(2)})`);
assert.equal(S.state,"stalk");
assert.ok(dist(S,c)-lz.lightOf(c)<2,"at its edge");
assert.equal(round.bonusRound.hearts,5);
});
test("Ghoul Rush's Drowned Lantern's leeches: once the flame gutters they swarm in and bite (a heart, cause lanternLeech; Planny fans the flame back to OIL_AFTER_BITE and they scatter); a flare scatters them for SCATTER_MS",()=>{
test("Ghoul Rush's Drowned Lantern's bog bodies take only someone standing still: a walk right past never wakes one; stand within BODY_NOTICE for BODY_STILL_MS and it boils for BODY_RISE_MS, then takes what is within BODY_REACH (cause lanternBody)",()=>{
// Body 0 lies beside the plank from the landing to shrine 0: walk the plank past it.
constwalk=bodyRound(0);
at(walk,...R.hummocks[0].slice(0,2));
walkTo(walk,...R.hummocks[2].slice(0,2));
assert.equal(walk.runner.bodies[0].state,"sunk","a walk past never wakes it");
assert.equal(A.state,"sunk","and it sinks back to wait");
});
/* --------------------------------------------------------- Old Mother Bog */
functionmotherRound(lit){
constround=quiet(lanternRound());
round.hush=false;
constc=round.runner;
c.lit=lit;
c.mother.stir=lit;
returnround;
}
test("Old Mother Bog in the Drowned Lantern sleeps until the third shrine (or MOTHER_LATE_S); then her hand's shadow follows you HAND_TRACK_MS, stops and reddens HAND_LOCK_MS, and slams: standing still a heart (cause lanternMother), walking on a miss",()=>{
constasleep=motherRound(2);
at(asleep,...R.start);
run(asleep,20000,{});
assert.equal(events(asleep,"lanternHand").length,0,"nothing before the third");
test("Old Mother Bog in the Drowned Lantern: the gap between hands shrinks with the shrines (MOTHER_GAP), and once she has risen they come one after another",()=>{
test("Ghoul Rush's Drowned Lantern: every hunter's catch costs exactly one heart, never a life, and leaves Planny where he stood, blinking safe so a second catch is free; the last heart gone ends the round with nothing, the dice in hand untouched",()=>{
for(constkindoflz.HUNTERS){
constround=quiet(lanternRound());
constb=round.bonusRound;
onYou(round,kind);
const[x,y]=[round.runner.x,round.runner.y];
run(round,12,{});
assert.equal(b.hearts,4,`${kind}: one heart`);
assert.equal(round.lives,3,`${kind}: no life`);
assert.equal(events(round,"lose").length,1,`${kind}: one loss`);
assert.equal(round.phase,"play","the round plays on");
}
constround=quiet(lanternRound());
constb=round.bonusRound;
onYou(round,"wisp");
run(round,12,{});
onYou(round,"body");
run(round,12,{});
assert.equal(b.hearts,4,"the blink took the second");
// The last heart.
constlast=quiet(lanternRound());
last.dice=4;
last.bonusRound.hearts=1;
onYou(last,"wisp");
run(last,12,{});
assert.equal(last.bonusRound.hearts,0);
run(last,4000,{});
assert.equal(last.bonusRound.won,false);
assert.equal(last.bonusRound.dice,0);
assert.equal(last.dice,4,"the dice in hand are untouched");
assert.equal(last.lives,3,"no run life");
});
test("Ghoul Rush's Drowned Lantern: endless lives (round.infinite) spare the hearts for every hunter, and the Garlic shield takes a catch instead of a heart",()=>{
for(constkindoflz.HUNTERS){
constround=quiet(lanternRound());
round.infinite=true;
onYou(round,kind);
run(round,12,{});
assert.equal(round.bonusRound.hearts,5,kind);
}
constround=quiet(lanternRound());
round.you.garlic=true;
onYou(round,"wisp");
run(round,12,{});
assert.equal(round.bonusRound.hearts,5);
assert.equal(round.you.garlic,false);
});
test("Ghoul Rush's Drowned Lantern's grade: total is the five kinds that can take you, a hit is a kind that did, the acts are wisps burst by a flare and close calls (ACTS_GOAL is the die), steady falls when the flame gutters; the dice follow ghoul-bonus.js",()=>{
constround=quiet(lanternRound());
constb=round.bonusRound;
assert.equal(b.perf.total,5);
assert.equal(b.perf.goal,lz.ACTS_GOAL);
assert.deepEqual(b.perf.hits,[]);
assert.equal(b.perf.steady,true);
// A clean, sharp run: every die.
b.perf.acts=lz.ACTS_GOAL;
assert.equal(diceFor(b),ghoul.MAX_DICE);
// Two kinds took a heart each, the flame guttered, few acts.
/* ------------------------------------------------------- the whole round */
test("Ghoul Rush's Drowned Lantern draws no random number (every hunter, flare, catch and the finish on a draw that throws), and the same keys give the same round",()=>{
test("Ghoul Rush's Drowned Lantern is fair and has teeth: a bot that walks to every shrine ignoring the hunters loses all five hearts, one that flares the wisps, keeps off the Lurker's lane and out of Mother's shadow wins with hearts to spare, whatever the shrines' order",()=>{
for(constorderofORDERS){
constdumb=lanternRound();
constlost=playOut(dumb,{order});
assert.equal(dumb.bonusRound.won,false,`${order}: the careless walk is lost`);
assert.equal(dumb.bonusRound.hearts,0);
assert.ok(lost.caught.length>=5);
assert.equal(dumb.lives,3,"no run life");
constsharp=lanternRound();
constwon=playOut(sharp,{smart:true,order});
assert.equal(sharp.bonusRound.won,true,`${order}: the careful run wins (${won.caught})`);
test("Ghoul Rush's Drowned Lantern names each hunter's rule once, the first time it comes near (lanternMeet), and lists what a banner must keep clear of",()=>{
assert.equal(ghoul.underBanner(m,54-34-2),true,"Planny in a banner's strip");
});
test("Ghoul Rush's Drowned Lantern's hums: the Lurker growls louder as it nears and hunts, Mother breathes once awake; every hum is one the engine has",()=>{
assert.equal(lz.lanternHums(round).some((h)=>h[0]==="ghoul:lurker"),false,"a cowering Lurker is quiet");
});
/* ------------------------------------------------------------ voices, art */
test("Ghoul Rush's Drowned Lantern: every event has a voice that plays, every cause has words and a sound, the tones exist and are short, and each hunter sounds its own",()=>{
assert.deepEqual(Object.keys(EVENT_VOICE).sort(),[...lz.EVENTS].sort(),"a voice for every event and no more");
assert.ok(!R.how.includes(String.fromCharCode(0x2014)),"no em dash");
});
test("Ghoul Rush's Drowned Lantern draws: every hunter in each state, the flare, the oil low and out, a catch's blink, Mother asleep, stirring, risen and her hand, the run to the boat and the cards, with and without a dark layer, and no blaster gauge",()=>{