Add Ghoul Rush's new stages (bog, hearse, pew, wagon and more) with their intros and suites

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-03 04:08:02 -08:00
1 parent c1e32b8aca
commit d016ba862a
78 files changed
+30982 -145

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
// Shared helpers for the Ghoul Rush tests (not a test itself).
// Leaves a boss room's intro card (phase "bossintro", ghoul-bossintro-draw.js) the way a player does: after the lockout, a fresh press.
// A round in any other phase is left alone. Returns true when it left a card.
export function skipBossIntro(ghoul, round) {
if (round.phase !== "bossintro") return false;
round.introMs = Math.max(round.introMs || 0, ghoul.INTRO_MIN_MS);
return ghoul.takeIntro(round);
}
@@ -521,7 +521,8 @@ test("Ghoul Rush's Silver Bear Trap sets at his feet, snaps on the first thing t
});
test("Ghoul Rush's ride rooms keep what needs a floor in the bag, use the next kind down, and a stick or a flash goes off in the air rather than being lost", () => {
const room = ghoul.ROOMS.find((r) => r.ride);
// The Mine's Runaway Cart, whichever rides other stages have in the room list before it.
const room = ghoul.ROOMS.find((r) => r.ride && r.id === "cart");
if (!room) return;
const round = ghoul.newRound(5);
round.dice = 0;
@@ -1635,3 +1636,31 @@ test("Ghoul Rush's Dynamite, Road Flare, Salt and Flash Powder are aimed: they l
const lob = pie.hazards.find((h) => h.kind === "armPie");
assert.ok(lob && Math.abs(lob.vx - arm.PIE_VX) < 1e-9, "the pie is not aimed");
});
test("Ghoul Rush's Dynamite keeps its fuse but also goes off at once when a monster stands within a unit of it after it lands", () => {
const blasts = (round) => events(round, "dynBlast").length;
// A monster that walks up to a landed stick sets it off before the fuse.
const near = roomOf("village", "inn");
standAt(near, 40);
give(near, "dyn", 2);
tapTap(near);
const stick = near.hazards.find((h) => h.kind === "stick");
for (let i = 0; i < 200 && !stick.rest; i++) run(near, 16);
assert.ok(stick.rest && stick.fuse > 200, "landed with fuse left");
assert.equal(blasts(near), 0);
put(near, "zombie", stick.x + 0.5, { stunMs: 1e9 });
run(near, 40);
assert.equal(blasts(near), 1, "went off at once on the neighbor");
// A monster further off than a unit does not set it off; the fuse still does.
const far = roomOf("village", "inn");
standAt(far, 40);
give(far, "dyn", 2);
tapTap(far);
const s2 = far.hazards.find((h) => h.kind === "stick");
for (let i = 0; i < 200 && !s2.rest; i++) run(far, 16);
put(far, "zombie", s2.x + 6, { stunMs: 1e9 });
run(far, 40);
assert.equal(blasts(far), 0, "too far");
run(far, arm.DYN_FUSE_MS + 40);
assert.equal(blasts(far), 1, "the fuse still blows it");
});
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,990 @@
// Web console tests, Ghoul Rush's Gallows Bog stage: the pack skeleton (the
// lurker, the leech swarm, the will-o'-wisp, the bog body and Old Mother Bog
// joined to the game's tables), the stage row and its five rooms' shapes, the
// mud spans that slow and sink you, the Bog Runner's stub and the Drowning
// Pool's boss spec. The monsters' rules, the fight and the ride land in
// later phases.
import { test } from "node:test";
import assert from "node:assert/strict";
import * as ghoul from "../src/web-console/public/activities/ghoul.js";
import * as bog from "../src/web-console/public/activities/ghoul-bog.js";
import * as ghoulSfx from "../src/web-console/public/activities/ghoul-sfx.js";
import { LOSE_SOUNDS, LOSE_WORDS, VOICES } from "../src/web-console/public/activities/ghoul-bog-draw.js";
import { BOG_SFX } from "../src/web-console/public/activities/ghoul-sfx-bog.js";
import { BOSS_INTROS, bossIntroFor } from "../src/web-console/public/activities/ghoul-boss-intros.js";
import { INTROS, introFor } from "../src/web-console/public/activities/ghoul-intros.js";
import { react } from "../src/web-console/public/activities/ghoul-draw.js";
const steady = () => 0.5;
const events = (round, type) => round.events.filter((e) => e.type === type);
const ROOM_IDS = ["boardwalk", "hollow", "stilts", "bogboat", "drowning"];
function through(round) {
round.phase = "clear";
round.phaseMs = 1;
ghoul.advance(round, 4, steady);
}
// A round in the Gallows Bog room `id`, reached the way play reaches it (out
// of the hall, the stage picked, the rooms before it gone through), nothing
// woken.
function bogRound(id) {
const round = ghoul.newRound(5);
round.dice = 0;
through(round);
assert.equal(round.phase, "pick");
round.offer = ["bog"];
round.phaseMs = 0;
ghoul.pickStage(round, 0);
while (round.spec.id !== id) through(round);
round.phase = "play";
for (const st of round.spawns) st.over = true;
round.monsters.length = 0;
round.hordeMs = Infinity;
round.items.fill(true);
round.candy.fill(true);
round.sky.fill(true);
round.events.length = 0;
return round;
}
function standAt(round, x, shelf = -1) {
const y = shelf >= 0 ? round.spec.shelves[shelf][2] : ghoul.groundAt(round.spec, x);
Object.assign(round.you, { x, y, vx: 0, vy: 0, state: "run", shelf, coyote: 0, drop: -1, cuttable: false, out: 0, safeMs: 0 });
round.camX = Math.max(0, Math.min(round.spec.length - ghoul.FIELD_W, x - 36));
}
function run(round, ms, keys = {}, random = steady) {
Object.assign(round.input, keys);
for (let t = 0; t < ms; t += 4) ghoul.advance(round, 4, random);
for (const k of Object.keys(keys)) round.input[k] = false;
}
/* ------------------------------------------------------------ the stage */
test("Ghoul Rush's Gallows Bog is a stage of five rooms ending on the Drowning Pool, its kinds and boss joined to the game's, last in the list", () => {
const st = ghoul.stageById("bog");
assert.deepEqual(st.rooms, ROOM_IDS);
assert.equal(st.boss, "motherbog");
assert.equal(st.title, "Gallows Bog");
assert.equal(st.sub, "The mud does not like to let go");
assert.equal(ghoul.STAGES.at(-1), st, "the last stage in the list");
for (const kind of Object.keys(bog.MONSTERS)) assert.equal(ghoul.MONSTERS[kind], bog.MONSTERS[kind], `${kind} is a monster`);
assert.deepEqual(Object.keys(bog.MONSTERS).sort(), ["bogbody", "leech", "lurker", "wisp"]);
assert.equal(ghoul.BOSSES.motherbog, bog.BOSSES.motherbog);
assert.equal(bog.BOSSES.motherbog.name, "Old Mother Bog");
assert.equal(bog.BOSSES.motherbog.sub, "Keep to the planks, she owns the water");
assert.equal(bog.BOG.id, "bog");
for (const key of ["walkers", "zombies", "act", "swoops", "solid", "unseen", "move", "kill", "horde", "tick", "bosses", "boss", "weak", "cause", "hazards"]) assert.ok(key in bog.BOG, `the pack carries ${key}`);
assert.deepEqual(bog.BOG.zombies, ["bogbody"], "the bog body counts as a zombie");
for (const id of ROOM_IDS) {
assert.ok(ghoul.roomById(id), `${id} resolves`);
assert.ok(ghoul.ROOM_MUSIC[id], `${id} has music`);
assert.ok(Object.hasOwn(ghoulSfx.default.music, ghoul.ROOM_MUSIC[id]), `${id}'s track exists`);
}
});
test("Ghoul Rush's bog rooms carry the usual pieces: a key, sky treasures, candy, items and a horde in each walked room, mud spans frozen, the ride its own course, the arena the hag's", () => {
const [boardwalk, hollow, stilts, bogboat, drowning] = ROOM_IDS.map((id) => ghoul.roomById(id));
assert.deepEqual([boardwalk.title, hollow.title, stilts.title, bogboat.title, drowning.title], ["Sunken Boardwalk", "Cypress Hollow", "Stilt House", "The Bog Runner", "The Drowning Pool"]);
assert.deepEqual([boardwalk.sub, hollow.sub, stilts.sub, drowning.sub], ["Mind the gaps. Something lives in them", "The moss is breathing", "She has been expecting you", "Keep to the planks, she owns the water"]);
for (const room of [boardwalk, hollow, stilts]) {
assert.ok(room.key, `${room.id}: a key`);
assert.ok(room.door > room.length - 14, `${room.id}: the door at the end`);
assert.ok(room.sky.length && room.candy.length && room.items.length && room.horde.length, `${room.id}: sky treasures, candy, items and a horde`);
const wings = room.items.find((i) => i[0] === "wings");
assert.ok(wings && wings[1] < Math.min(...room.sky.map(([, x]) => x)), `${room.id}: wings on the way to the sky`);
assert.ok(room.mud.length >= 1, `${room.id}: mud spans`);
for (const span of room.mud) assert.ok(Object.isFrozen(span), `${room.id}: a mud span is frozen`);
for (const kind of room.horde) assert.ok(ghoul.MONSTERS[kind], `${room.id}: ${kind} is a monster`);
assert.equal(room.boss, null, `${room.id}: no boss`);
assert.equal(room.dark, null, `${room.id}: dark or lit by the roll`);
}
assert.ok(hollow.water.length && stilts.water.length, "the hollow and the stilts keep pools beside the mud");
assert.ok(boardwalk.shelves.some((s) => s[3] === "crumble") && hollow.shelves.some((s) => s[3] === "crumble") && stilts.shelves.some((s) => s[3] === "crumble"), "rotting boards that give way");
// The Bog Runner is a stub: a bonus ride with empty obstacle arrays that
// Phase 4's deterministic generator fills in.
assert.equal(bogboat.bonus, true);
assert.equal(bogboat.dark, false);
assert.equal(bogboat.key, null);
assert.equal(bogboat.boss, null);
assert.equal(bogboat.horde.length, 0);
assert.equal(bogboat.ride.runner, "bogboat");
assert.equal(bogboat.ride.how, "LEFT or RIGHT at a bank: switch lane. UP jump, DOWN duck, SPACE shoot");
assert.ok(bogboat.ride.time >= 70000 && bogboat.ride.time <= 120000);
assert.ok(bogboat.ride.finish > 0 && bogboat.ride.finish < bogboat.length);
assert.ok(bogboat.ride.checks.length >= 1 && bogboat.ride.checks.every((x) => x > 0 && x < bogboat.ride.finish), "checkpoints inside the run");
assert.ok(Object.isFrozen(bogboat.ride), "the ride is frozen");
assert.equal(drowning.boss, "motherbog");
assert.equal(drowning.key, null);
assert.equal(drowning.horde.length, 0);
assert.equal(drowning.dark, null, "the arena rolls dark or lit");
assert.ok(drowning.length - ghoul.FIELD_W > 30, "room to walk into the arena");
});
/* ---------------------------------------------------------- the mud */
test("Ghoul Rush's mud slows a run the longer you stand in it, down to a crawl, and lets go on dry floor", () => {
const round = bogRound("boardwalk");
const inMud = round.spec.mud[0][0] + 2;
standAt(round, inMud);
round.you.safeMs = 1e9;
run(round, 200, { right: true });
assert.equal(round.you.mud, true, "in the span you are muddy");
// Fresh mud drags like water; the run crawls as the sink deepens.
standAt(round, inMud);
const x0 = round.you.x;
run(round, 1000, { right: true });
const early = round.you.x - x0;
assert.ok(round.you.mudMs > 900, `sunk a second (${round.you.mudMs} ms)`);
run(round, 1800, { right: true });
const x1 = round.you.x;
run(round, 1000, { right: true });
const late = round.you.x - x1;
assert.ok(late < early * 0.6, `deeper is slower (${early.toFixed(1)} then ${late.toFixed(1)})`);
// Out of the mud it drains away.
round.you.mudMs = 2000;
standAt(round, 290);
run(round, 500, { right: true });
assert.equal(round.you.mud, false);
assert.ok(round.you.mudMs < 2000, `it lets go (${round.you.mudMs} ms)`);
});
test("Ghoul Rush's mud cuts a jump lower the deeper you sink, and a shelf keeps you out of it", () => {
const round = bogRound("boardwalk");
const inMud = round.spec.mud[0][0] + 2;
// A fresh jump in mud leaves near WATER_JUMP of full speed; a sunk one nears MUD_JUMP_MIN.
const jumpV = (ms) => {
standAt(round, inMud);
round.you.mudMs = ms;
run(round, 4, {});
round.input.jump = ghoul.JUMP_BUFFER_MS;
ghoul.advance(round, 4, steady);
return round.you.vy;
};
const fresh = jumpV(0);
const sunk = jumpV(ghoul.MUD_MS);
// The vy read is one gravity slice after the jump itself.
assert.ok(Math.abs(fresh - ghoul.JUMP_V * ghoul.WATER_JUMP) < 2, `fresh mud jumps near water height (${fresh.toFixed(1)})`);
assert.ok(Math.abs(sunk - ghoul.JUMP_V * ghoul.MUD_JUMP_MIN) < 2, `sunk jumps near the floor of it (${sunk.toFixed(1)})`);
assert.ok(sunk < fresh, "the deeper the sink, the lower the jump");
// On a shelf over the mud there is no sinking.
const shelf = round.spec.shelves.findIndex(([a, b]) => round.spec.mud.some(([m0, m1]) => a < m1 && b > m0));
assert.ok(shelf >= 0, "a board over the mud to stand on");
const [a, b] = round.spec.shelves[shelf];
standAt(round, (a + b) / 2, shelf);
run(round, 300, {});
assert.equal(round.you.mud, false, "a board over the mud is dry");
});
test("Ghoul Rush's wisp lure pulls the dead inside a bright wisp's light and lets go when it dims, and never touches another stage's lure", () => {
const round = bogRound("boardwalk");
standAt(round, 20);
round.you.safeMs = 60000;
const wisp = ghoul.spawnMonster(round, "wisp", 24, 10);
const risen = ghoul.spawnMonster(round, "bogbody", 28, ghoul.groundAt(round.spec, 28));
run(round, 40, {});
assert.ok(risen.lure > 0 && risen.hasteMs > 0 && risen.haste === bog.WISP_HASTE, "in the light it is pulled, a step quicker");
wisp.act = "dim";
run(round, 8, {});
assert.equal(risen.lure, 0, "a shot-out wisp lets it go");
// In any other stage the same fields belong to another pack (the moth's call).
const hall = ghoul.newRound(5);
const moth = ghoul.spawnMonster(hall, "zombie", 20, 6);
moth.lure = 500;
moth.hasteMs = 500;
ghoul.advance(hall, 4, steady);
assert.equal(moth.lure, 500, "the hall's lure is not the wisp's to clear");
});
/* ------------------------------------------------------ monsters */
const put = (round, kind, x, over = {}) => ghoul.spawnMonster(round, kind, x, over.y ?? ghoul.groundAt(round.spec, x), over);
// Runs until `done()` (or `ms` have passed), 4 ms at a time.
function until(round, done, ms = 4000) {
for (let t = 0; t < ms && !done(); t += 4) ghoul.advance(round, 4, steady);
}
const tx2 = (e) => e.tx2;
// A bolt arriving from the left at height `y` on the monster `m`.
const bolt = (round, m, y, extra = {}) => round.shots.push({ x: m.x - m.w / 2 - 0.3, y, vx: 80, vy: 0, gone: 0, ...extra });
// A hollow x on dry floor with open floor to either side.
const dry = (round, x) => {
assert.ok(Number.isFinite(ghoul.groundAt(round.spec, x)), `floor at ${x}`);
return x;
};
test("Ghoul Rush's lurker is eyes you cannot touch or shoot until you cross it, then snaps out of the water solid and sinks back", () => {
const round = bogRound("hollow");
standAt(round, dry(round, 20));
round.you.safeMs = 1e9;
const m = put(round, "lurker", 60);
assert.equal(m.act, "eyes");
run(round, 8);
assert.equal(m.unseen, true, "eyes are unseen");
assert.equal(ghoul.solid(m), false, "nothing to stomp or hit");
bolt(round, m, m.y + 1);
run(round, 40);
assert.equal(m.hp, m.max, "a bolt goes through the eyes");
assert.equal(events(round, "lurkerSnap").length, 0, "far away it stays down");
// Cross into its range: it snaps, solid and lunging at you.
standAt(round, m.x - bog.SNAP_RANGE + 2);
round.you.safeMs = 1e9;
run(round, 8);
assert.equal(m.act, "snap");
assert.equal(events(round, "lurkerSnap").length, 1);
assert.equal(ghoul.solid(m), true, "snapping it is solid");
const x0 = m.x;
run(round, 200);
assert.ok(Math.abs(m.x - x0) > 1, "it lunges");
// The snap ends in a sink, then eyes again.
run(round, bog.SNAP_MS);
assert.equal(events(round, "lurkerSink").length, 1);
assert.ok(m.act === "sink" || m.act === "eyes");
run(round, bog.LURKER_SINK_MS + 40);
assert.ok(m.act === "eyes" || m.act === "snap", "back to eyes (or snapping again if you are still near)");
// Eyes at the waterline do no harm when you walk through them with the shield down.
const calm = bogRound("hollow");
standAt(calm, 20);
calm.you.safeMs = 0;
const e = put(calm, "lurker", 20, { act: "eyes" });
calm.you.out = 1000;
run(calm, 30);
assert.equal(events(calm, "lose").length, 0);
assert.equal(e.act, "eyes", "a player who is out never wakes it");
});
test("Ghoul Rush's leech swarm latches for one heart on touch, drops off and cannot latch again at once, and a hit disperses it", () => {
const round = bogRound("hollow");
standAt(round, dry(round, 30));
round.you.safeMs = 0;
const hearts = round.lives;
const m = put(round, "leech", 30);
run(round, 8);
assert.equal(events(round, "leechLatch").length, 1, "one latch");
assert.equal(events(round, "lose")[0]?.cause, "leeches", "it costs a heart, named for the leeches");
assert.equal(m.act, "drop");
assert.equal(round.lives, hearts - 1, "exactly one heart");
// It drops off for LEECH_DROP_MS, then drifts again; a second latch waits LEECH_AGAIN_MS.
const lives = round.lives;
round.you.safeMs = 0;
run(round, bog.LEECH_DROP_MS + 20);
assert.equal(m.act === "drift" || m.act === "drop", true);
assert.ok(m.latchIn > 0, "cannot latch again yet");
assert.equal(events(round, "leechLatch").length, 1, "still the one latch");
assert.equal(round.lives, lives);
// Stomp-free dispersal: a bolt takes LEECH hp, the swarm comes apart.
const swarm = put(round, "leech", 60);
standAt(round, 30);
round.you.safeMs = 1e9;
ghoul.hurt(round, swarm, 99, "shot");
assert.equal(events(round, "leechDie").length, 1, "the swarm comes apart");
});
test("Ghoul Rush's will-o'-wisp is hit only while bright: a bolt puts it out, it stays dim, glows where it will return, then burns again", () => {
const round = bogRound("boardwalk");
standAt(round, 20);
round.you.safeMs = 1e9;
const m = put(round, "wisp", 40, { y: 10 });
assert.equal(m.act, "bright");
assert.equal(ghoul.solid(m), true);
bolt(round, m, m.y + m.h / 2);
run(round, 4);
assert.equal(m.act, "dim", "a bolt puts it out");
assert.equal(events(round, "wispOut").length, 1);
assert.equal(ghoul.solid(m), false, "a dim wisp is no target and no threat");
assert.ok(m.relight && Number.isFinite(m.relight.x), "the spot it returns to is seeded");
run(round, bog.WISP_RELIGHT_MS - 100);
assert.equal(m.act, "dim", "stays dim for the relight time");
run(round, 200);
assert.equal(m.act, "rekindle");
assert.equal(events(round, "wispRelight").length, 1);
assert.equal(ghoul.solid(m), false, "glowing is not yet burning");
run(round, bog.WISP_REKINDLE_MS + 20);
assert.equal(m.act, "bright");
assert.equal(events(round, "wispOn").length, 1);
// A dim wisp is a dip you can pass through: touching it costs nothing.
const pass = bogRound("boardwalk");
standAt(pass, 20);
pass.you.safeMs = 0;
put(pass, "wisp", 20, { y: pass.you.y + 1, act: "dim", wait: 5000 });
run(pass, 40);
assert.equal(events(pass, "lose").length, 0);
});
test("Ghoul Rush's bog body climbs out of the mud harmless, then shambles toward you", () => {
const round = bogRound("boardwalk");
standAt(round, 20);
round.you.safeMs = 1e9;
const m = put(round, "bogbody", 50);
assert.equal(m.act, "rise");
run(round, 8);
assert.ok(m.rise > 0, "climbing out");
assert.equal(ghoul.solid(m), false, "harmless while it rises");
assert.equal(events(round, "bogRise").length, 1);
const x0 = m.x;
run(round, 300);
assert.equal(m.x, x0, "it does not walk while it climbs");
run(round, bog.BOG_RISE_MS);
assert.equal(m.act, "walk");
assert.equal(ghoul.solid(m), true);
const x1 = m.x;
run(round, 400);
assert.ok(m.x < x1 - 1, "it walks toward you");
// One that comes in with the horde is already up.
const up = put(round, "bogbody", 80, { horde: true });
run(round, 8);
assert.equal(up.act, "walk");
assert.equal(events(round, "bogRise").length, 1, "no second climb");
});
/* ------------------------------------------------------ the lure */
test("Ghoul Rush's bright wisp lures monsters inside WISP_LURE toward you at WISP_HASTE times their speed, and shot out the pull ends", () => {
const walked = (withWisp) => {
const round = bogRound("boardwalk");
standAt(round, 20);
round.you.safeMs = 1e9;
const m = put(round, "bogbody", 70, { rise: 0, act: "walk" });
if (withWisp) put(round, "wisp", 70, { y: 10 });
const x0 = m.x;
run(round, 1000);
return { m, round, dx: x0 - m.x };
};
const plain = walked(false);
const lured = walked(true);
assert.equal(plain.m.lure || 0, 0);
assert.ok(lured.m.lure > 0, "pulled");
assert.ok(lured.m.haste <= bog.WISP_HASTE, "never past the cap");
const ratio = lured.dx / plain.dx;
assert.ok(ratio > 1.1 && ratio < bog.WISP_HASTE + 0.05, `about ${bog.WISP_HASTE}x, not more (${ratio.toFixed(2)})`);
assert.equal(events(lured.round, "wispLure").length, 1, "the pull is announced once");
// Out of reach of a bright light it is no quicker.
const round = bogRound("boardwalk");
standAt(round, 20);
round.you.safeMs = 1e9;
const far = put(round, "bogbody", 75, { rise: 0, act: "walk" });
const w = put(round, "wisp", 75 - bog.WISP_LURE - 6, { y: 10 });
run(round, 100);
assert.equal(w.act, "bright", "the wisp is burning");
assert.equal(far.lure || 0, 0, "a bright wisp out of reach lures nobody");
assert.equal(far.haste || 1, 1);
// Shot out, the pull ends at once; a monster beyond the radius is not drawn.
const shot = bogRound("boardwalk");
standAt(shot, 20);
shot.you.safeMs = 1e9;
const walker = put(shot, "bogbody", 70, { rise: 0, act: "walk" });
const light = put(shot, "wisp", 72, { y: 10 });
run(shot, 60);
assert.ok(walker.lure > 0);
light.act = "dim";
light.wait = 1e9;
run(shot, 8);
assert.equal(walker.lure, 0);
assert.equal(walker.hasteMs, 0);
assert.equal(walker.haste, 1);
});
test("Ghoul Rush's wisp lure stays fair in a horde: every monster in the light is capped at WISP_HASTE, a wisp never lures another wisp, and shooting the wisp out frees the lot", () => {
const round = bogRound("boardwalk");
standAt(round, 20);
round.you.safeMs = 1e9;
const pack = [put(round, "bogbody", 70, { rise: 0, act: "walk" }), put(round, "bogbody", 75, { rise: 0, act: "walk" }), put(round, "leech", 72), put(round, "bogbody", 78, { rise: 0, act: "walk" })];
const lights = [put(round, "wisp", 74, { y: 10 }), put(round, "wisp", 76, { y: 11 })];
run(round, 120);
for (const m of pack) {
assert.ok(m.lure > 0, `${m.kind} is lured`);
assert.ok(m.haste <= bog.WISP_HASTE + 1e-9, `${m.kind} at ${m.haste}x`);
}
for (const w of lights) assert.equal(w.lure || 0, 0, "a wisp is never lured by a wisp");
// Two lights do not stack: the cap is the cap.
assert.equal(new Set(pack.map((m) => m.haste)).size, 1);
for (const w of lights) {
bolt(round, w, w.y + w.h / 2);
run(round, 8);
}
run(round, 20);
for (const m of pack) assert.equal(m.lure, 0, `${m.kind} is let go`);
});
/* ---------------------------------------------------------- mud, boots, harpoon */
test("Ghoul Rush's mud holds you only on its spans and on the ground: a jump lets go of the sink, mudMs builds and drains, and the speed bottoms out at MUD_SPEED_MIN", () => {
const round = bogRound("boardwalk");
const [a, b] = round.spec.mud[0];
standAt(round, a + 3);
round.you.safeMs = 1e9;
run(round, 4);
assert.equal(round.you.mud, true, "on the span");
standAt(round, a - 3);
run(round, 4);
assert.equal(round.you.mud, false, "just off it");
standAt(round, b + 3);
run(round, 4);
assert.equal(round.you.mud, false, "past it");
// In the air over the mud nothing sinks.
standAt(round, a + 3);
round.you.y += 4;
round.you.vy = 0;
round.you.state = "fall";
run(round, 4);
assert.equal(round.you.mud, false, "airborne is dry");
// mudMs builds one-for-one and drains the same way, never below zero.
standAt(round, a + 3);
round.you.mudMs = 0;
run(round, 400);
assert.ok(round.you.mudMs >= 380 && round.you.mudMs <= 440, `built (${round.you.mudMs})`);
standAt(round, a - 20);
run(round, 10000);
assert.equal(round.you.mudMs, 0, "never below zero");
// At full sink the run is a crawl: MUD_SPEED_MIN of a dry run's reach over the same time.
const reach = (mudMs, x) => {
standAt(round, x);
round.you.mudMs = mudMs;
const x0 = round.you.x;
run(round, 160, { right: true });
return round.you.x - x0;
};
const dryReach = reach(0, 270);
const fresh = reach(0, a + 3);
const sunk = reach(ghoul.MUD_MS, a + 3);
assert.ok(sunk < fresh && fresh < dryReach, `dry ${dryReach.toFixed(1)} > fresh ${fresh.toFixed(1)} > sunk ${sunk.toFixed(1)}`);
assert.ok(sunk / dryReach < ghoul.MUD_SPEED_MIN + 0.12, `crawls (${(sunk / dryReach).toFixed(2)} of dry)`);
assert.ok(ghoul.MUD_SPEED_MIN < ghoul.WATER_SPEED && ghoul.MUD_JUMP_MIN < ghoul.WATER_JUMP, "mud is always worse than water");
});
test("Ghoul Rush's Stilt Boots let the mud go while they last, and the mud takes hold again after", () => {
const round = bogRound("boardwalk");
const [a] = round.spec.mud[0];
standAt(round, a + 3);
round.you.safeMs = 1e9;
round.effects.boots = 300;
run(round, 100);
assert.equal(round.you.mud, false, "boots neutralize it");
assert.equal(round.you.mudMs, 0);
const x0 = round.you.x;
run(round, 100, { right: true });
const booted = round.you.x - x0;
assert.ok(booted > 0);
round.effects.boots = 0;
standAt(round, a + 3);
run(round, 8);
assert.equal(round.you.mud, true, "the mud takes hold again");
assert.equal(ghoul.POWERS.boots.stage, "bog");
});
test("Ghoul Rush's harpoon pierces everything in its line, reaches a lurker's eyes under the water that any other bolt passes through, and a plain bolt does not", () => {
const round = bogRound("hollow");
standAt(round, dry(round, 20));
round.you.safeMs = 1e9;
const near = put(round, "lurker", 50);
const far = put(round, "lurker", 70);
run(round, 8);
assert.equal(near.unseen && far.unseen, true);
const harpoon = () => ({ arm: "harpoon", x: 30, y: near.y + 1, vx: 84, vy: 0, gone: 0, t: 0, spin: 0, dmg: 14, bossDmg: 8, pierce: true });
// A plain bolt flies through both pairs of eyes.
round.shots.push({ x: 30, y: near.y + 1, vx: 80, vy: 0, gone: 0 });
run(round, 600);
assert.equal(near.hp, near.max);
assert.equal(far.hp, far.max);
assert.equal(events(round, "harpoonHit").length, 0);
// A harpoon finds the first, goes on through it and finds the second.
round.shots.push(harpoon());
run(round, 800);
assert.equal(events(round, "harpoonHit").length, 2, "one hit for each, none twice");
assert.ok(near.dead || near.hp < near.max, "the near lurker is hurt");
assert.ok(far.dead || far.hp < far.max, "the far one too");
assert.equal(events(round, "kill").length, 2, "14 damage is enough for a lurker");
});
/* ------------------------------------------------------ Old Mother Bog */
// The Drowning Pool with the hag awake and fighting, nothing else on the field.
function motherFight() {
const round = bogRound("drowning");
standAt(round, round.spec.arena + ghoul.BOSS_LOCK + 2);
ghoul.advance(round, 4, steady);
ghoul.advance(round, ghoul.BOSS_INTRO_MS + 8, steady);
assert.equal(round.boss.state, "fight");
round.you.safeMs = 0;
round.events.length = 0;
return round;
}
// Straight to her next move, as if her wait had run out.
const hurry = (b) => (b.wait = 0);
test("Old Mother Bog's mud wave winds up, rolls down the planks at you, and is jumped: standing in it costs a heart (swamped), a jump clears it", () => {
const round = motherFight();
const b = round.boss;
assert.equal(b.kind, "motherbog");
assert.equal(b.hp, bog.BOSSES.motherbog.hp);
standAt(round, 150);
b.act = "idle";
hurry(b);
run(round, 8);
assert.equal(b.act, "wind", "the first move is the wave");
assert.equal(events(round, "motherWind").length, 1, "a wind-up to read");
assert.equal(round.waves.length, 0, "nothing rolls during the wind-up");
run(round, bog.MOTHER_WIND_MS + 20);
assert.equal(events(round, "mudWave").length, 1);
assert.equal(round.waves[0]?.cause, "mudwave");
assert.equal(b.act, "rest");
// Stand still: it arrives and swamps you.
const stand = round.you.x;
until(round, () => events(round, "lose").length > 0, 3000);
assert.equal(events(round, "lose")[0]?.cause, "mudwave");
assert.equal(round.you.x, stand);
// The same wave, jumped at the edge, goes by.
const jumper = motherFight();
standAt(jumper, 150);
jumper.boss.act = "rest";
jumper.boss.wait = 1e9;
jumper.waves.push({ x: 170, y: 6, dir: -1, life: 6000, kind: "mudwave", cause: "mudwave" });
let jumped = false;
until(jumper, () => {
const w = jumper.waves[0];
if (!jumped && w && w.x - jumper.you.x < 9) {
jumper.input.jump = ghoul.JUMP_BUFFER_MS;
jumped = true;
}
return !jumper.waves.length || jumper.waves[0].x < jumper.you.x - 3;
}, 3000);
assert.ok(jumped, "it came at me");
assert.equal(events(jumper, "lose").length, 0, "a jump clears the wave");
});
test("Old Mother Bog's cauldron opens late in each rest, and a shot into her then counts triple, any other time one", () => {
const round = motherFight();
const b = round.boss;
const hit = (act, wait) => {
Object.assign(b, { act, wait });
round.shots.push({ x: b.x - b.w / 2 - 0.2, y: b.y + b.h * 0.35, vx: 80, vy: 0, gone: 0 });
const hp = b.hp;
ghoul.advance(round, 4, steady);
return hp - b.hp;
};
assert.equal(hit("idle", 1e9), 1, "shut: one");
assert.equal(hit("rest", bog.MOTHER_REST_MS), 1, "early in the rest: one");
assert.equal(b.lit, false);
round.events.length = 0;
assert.equal(hit("rest", bog.MOTHER_OPEN_MS - 100), 3, "open: triple");
assert.equal(b.lit, true);
assert.equal(events(round, "cauldronOpen").length, 1, "the opening is announced");
assert.equal(round.events.filter((e) => e.type === "bossHit").at(-1).weak, true, "and the hit says it was a weak spot");
assert.equal(hit("wind", 400), 1, "mid-wind-up: one");
assert.equal(b.lit, false, "closed again");
});
test("Old Mother Bog's cauldron spit lands a muck patch where you stand after a wind-up, warns before it burns, burns for MUCK_MS and hurts only while live", () => {
const round = motherFight();
const b = round.boss;
standAt(round, 150);
round.you.safeMs = 1e9;
b.act = "idle";
b.attacks = 1;
hurry(b);
run(round, 8);
assert.equal(b.act, "throwWind");
assert.equal(events(round, "spitWind").length, 1);
assert.equal(round.hazards.length, 0, "the glob is not thrown during the wind-up");
run(round, bog.SPIT_WIND_MS + 20);
const spit = events(round, "cauldronSpit");
assert.equal(spit.length, 1);
assert.equal(round.hazards.length, 1, "one patch before she is angry");
const patch = round.hazards[0];
assert.equal(patch.kind, "muck");
assert.equal(patch.cause, "muck");
assert.ok(Math.abs(patch.x - 150) <= 6, "where you stood");
assert.equal(spit[0].tx, patch.x);
assert.equal(tx2(spit[0]), undefined, "no second patch yet");
// It warns first: standing in the glob's shadow is safe.
round.you.safeMs = 0;
standAt(round, patch.x);
run(round, bog.MUCK_LAND_MS - 100);
assert.equal(events(round, "lose").length, 0, "still in the air");
run(round, 200);
assert.equal(events(round, "muckLand").length, 1);
assert.equal(events(round, "lose")[0]?.cause, "muck", "burning, it hurts");
// It burns out MUCK_MS after it lands.
const out = motherFight();
out.boss.act = "rest";
out.boss.wait = 1e9;
out.hazards.push({ kind: "muck", x: 150, y: 6, w: bog.MUCK_W, h: bog.MUCK_H, warn: 0, live: bog.MUCK_MS, cause: "muck" });
standAt(out, 100);
out.you.safeMs = 1e9;
run(out, bog.MUCK_MS - 100);
assert.equal(out.hazards.length, 1);
run(out, 200);
assert.equal(out.hazards.length, 0, "burnt out");
});
test("Old Mother Bog goes meaner at half her hp: waits shrink to MOTHER_QUICK of themselves and the spit leaves a second patch ahead of your feet", () => {
const round = motherFight();
const b = round.boss;
standAt(round, 150);
round.you.safeMs = 1e9;
Object.assign(b, { raged: true, sank: true, act: "idle", attacks: 1, y: 6, x: 176 });
b.wait = 0;
round.you.vx = 20;
run(round, 8);
assert.equal(b.act, "throwWind");
assert.ok(b.wait <= bog.SPIT_WIND_MS * bog.MOTHER_QUICK + 1, `quicker wind-up (${b.wait})`);
run(round, bog.SPIT_WIND_MS);
const spit = events(round, "cauldronSpit")[0];
assert.ok(spit, "spat");
assert.equal(round.hazards.length, 2, "two patches");
assert.ok(tx2(spit) !== undefined && Math.abs(tx2(spit) - spit.tx) >= bog.MUCK_W, "the second is a patch away from the first");
assert.ok(b.wait <= bog.MOTHER_REST_MS * bog.MOTHER_QUICK + 1, "and her rest is shorter");
// Calm, the same spit is one patch.
const calm = motherFight();
standAt(calm, 150);
calm.you.safeMs = 1e9;
Object.assign(calm.boss, { act: "throwWind", wait: 0 });
run(calm, 8);
assert.equal(calm.hazards.length, 1);
});
test("Old Mother Bog sinks at half her hp, bubbles where she will rise, rises near you on a plank and is hittable the instant she does", () => {
const calm = motherFight();
assert.equal(calm.boss.sank || false, false);
calm.boss.act = "idle";
calm.boss.wait = 1e9;
calm.boss.hp = calm.boss.max * bog.MOTHER_RAGE + 1;
run(calm, 40);
assert.equal(calm.boss.sank || false, false, "above half she stays up");
standAt(calm, 150);
calm.you.safeMs = 1e9;
calm.boss.hp = calm.boss.max * bog.MOTHER_RAGE;
run(calm, 8);
const h = calm.boss;
assert.equal(h.sank, true);
assert.equal(h.act, "sink");
assert.equal(h.raged, true);
assert.equal(h.hidden, true, "gone at once");
assert.equal(events(calm, "motherSink").length, 1);
// Under the water nothing she is hurts and nothing hurts her: a bolt meets water.
const hp = h.hp;
calm.shots.push({ x: h.x - 2, y: 6.5, vx: 80, vy: 0, gone: 0 });
Object.assign(calm.you, { x: h.x - 1 });
calm.you.safeMs = 0;
run(calm, 40);
assert.equal(h.hp, hp, "no damage while she is under");
assert.equal(events(calm, "lose").length, 0, "and she cannot hurt you from the water");
// She bubbles where she will come up: a plank near you, never on top of you.
standAt(calm, 150);
calm.you.safeMs = 1e9;
until(calm, () => h.act === "under", 2000);
const bubble = events(calm, "motherBubble")[0];
assert.ok(bubble, "bubbles show");
assert.equal(h.act, "under");
assert.equal(bubble.x, h.sinkX);
assert.ok(Number.isFinite(ghoul.groundAt(calm.spec, h.sinkX)), "on a plank");
assert.ok(Math.abs(h.sinkX - calm.you.x) >= 6, "never on top of you");
// She rises exactly there, touchable and hittable at once.
until(calm, () => h.act === "resurface", 2000);
assert.equal(h.x, bubble.x);
assert.equal(h.hidden, false);
assert.equal(h.y, h.home);
assert.equal(events(calm, "motherRise").length, 1);
const before = h.hp;
calm.shots.push({ x: h.x - h.w / 2 - 0.2, y: h.y + h.h * 0.35, vx: 80, vy: 0, gone: 0 });
ghoul.advance(calm, 4, steady);
assert.ok(before - h.hp >= 1, "never unhittable once she is up");
until(calm, () => h.act === "rest", 2000);
assert.ok(h.wait <= bog.MOTHER_REST_MS * bog.MOTHER_QUICK + 1, "and her next wait is the quick one");
});
test("Old Mother Bog: her guard and weak spot are what the pack says, her touch is the motherbog cause, and her fall clears the field", () => {
assert.equal(bog.BOG.guard.motherbog({ hidden: true }), true);
assert.equal(bog.BOG.guard.motherbog({ hidden: false }), false);
assert.equal(bog.BOG.weak.motherbog({ lit: true }), 3);
assert.equal(bog.BOG.weak.motherbog({ lit: false }), 1);
assert.equal(bog.BOG.cause.motherbog(), "motherbog");
const touch = motherFight();
touch.boss.act = "idle";
touch.boss.wait = 1e9;
Object.assign(touch.you, { x: touch.boss.x - 3 });
run(touch, 20);
assert.equal(events(touch, "lose")[0]?.cause, "motherbog");
const round = motherFight();
const b = round.boss;
b.hp = 1;
b.sank = true;
round.hazards.push({ kind: "muck", x: 150, y: 6, w: bog.MUCK_W, h: bog.MUCK_H, warn: 0, live: 2000, cause: "muck" });
round.waves.push({ x: 140, y: 6, dir: -1, life: 6000, kind: "mudwave", cause: "mudwave" });
Object.assign(b, { act: "rest", wait: bog.MOTHER_OPEN_MS - 100 });
standAt(round, 120);
round.you.safeMs = 1e9;
round.shots.push({ x: b.x - b.w / 2 - 0.2, y: b.y + b.h * 0.35, vx: 80, vy: 0, gone: 0 });
ghoul.advance(round, 4, steady);
assert.equal(b.state, "down");
assert.equal(round.hasKey, true);
assert.equal(round.hazards.length, 0);
assert.equal(round.waves.length, 0);
});
/* ------------------------------------------------------ voices, words, cards */
const heard = (e, extra = {}) => {
const played = [];
const noop = () => {};
const kit = { tone: (name) => played.push(name), burst: noop, float: noop, ring: noop, banner: () => null, shake: noop, flash: noop, glow: noop, splat: noop, fx: { clock: 1e6 }, monsters: ghoul.MONSTERS, powers: ghoul.POWERS, bosses: ghoul.BOSSES, g: {}, floorAt: () => 6, ...extra };
react(e, kit);
return played;
};
test("Ghoul Rush's bog: every new kind has a voice for every act, every new event plays exactly one picked sound, and the tones are the stage's own", () => {
const own = { lurker: ["appear", "snap", "sink", "hurt", "die"], leech: ["appear", "latch", "hurt", "die"], wisp: ["appear", "out", "relight", "on", "hurt", "die"], bogbody: ["appear", "rise", "hurt", "die"], motherbog: ["wake", "wind", "wave", "spitWind", "spit", "open", "sink", "bubble", "rise", "muck", "hurt", "weak", "die"] };
assert.deepEqual(Object.keys(VOICES).sort(), Object.keys(own).sort(), "a voice table for each new kind and the boss");
for (const [kind, acts] of Object.entries(own)) assert.deepEqual(Object.keys(VOICES[kind]).sort(), [...acts].sort(), `${kind}: every act`);
const names = Object.values(VOICES).flatMap((v) => Object.values(v));
const at = { x: 10, y: 6, tx: 20, ty: 6 };
const cases = [
[{ type: "lurkerSnap", kind: "lurker" }, "lurker", "snap"],
[{ type: "lurkerSink", kind: "lurker" }, "lurker", "sink"],
[{ type: "leechLatch", kind: "leech" }, "leech", "latch"],
[{ type: "bogRise", kind: "bogbody" }, "bogbody", "rise"],
[{ type: "wispOut", kind: "wisp" }, "wisp", "out"],
[{ type: "wispRelight", kind: "wisp" }, "wisp", "relight"],
[{ type: "wispOn", kind: "wisp" }, "wisp", "on"],
[{ type: "motherWind", kind: "motherbog" }, "motherbog", "wind"],
[{ type: "mudWave", kind: "motherbog" }, "motherbog", "wave"],
[{ type: "spitWind", kind: "motherbog" }, "motherbog", "spitWind"],
[{ type: "cauldronSpit", kind: "motherbog" }, "motherbog", "spit"],
[{ type: "cauldronOpen", kind: "motherbog" }, "motherbog", "open"],
[{ type: "muckLand" }, "motherbog", "muck"],
[{ type: "motherSink", kind: "motherbog" }, "motherbog", "sink"],
[{ type: "motherBubble", kind: "motherbog" }, "motherbog", "bubble"],
[{ type: "motherRise", kind: "motherbog" }, "motherbog", "rise"],
[{ type: "bossWake", kind: "motherbog" }, "motherbog", "wake"],
[{ type: "bossHit", kind: "motherbog", how: "shot" }, "motherbog", "hurt"],
[{ type: "bossHit", kind: "motherbog", how: "weak", weak: true }, "motherbog", "weak"],
[{ type: "bossDown", kind: "motherbog", points: 1 }, "motherbog", "die"],
[{ type: "hit", kind: "lurker" }, "lurker", "hurt"],
[{ type: "hit", kind: "leech" }, "leech", "hurt"],
[{ type: "hit", kind: "wisp" }, "wisp", "hurt"],
[{ type: "hit", kind: "bogbody" }, "bogbody", "hurt"],
[{ type: "kill", kind: "lurker", mult: 1, how: "shot", points: 1 }, "lurker", "die"],
[{ type: "kill", kind: "leech", mult: 1, how: "shot", points: 1 }, "leech", "die"],
[{ type: "kill", kind: "wisp", mult: 1, how: "shot", points: 1 }, "wisp", "die"],
[{ type: "kill", kind: "bogbody", mult: 1, how: "shot", points: 1 }, "bogbody", "die"],
[{ type: "spawn", kind: "lurker" }, "lurker", "appear"],
[{ type: "spawn", kind: "leech" }, "leech", "appear"],
[{ type: "spawn", kind: "wisp" }, "wisp", "appear"],
[{ type: "spawn", kind: "bogbody" }, "bogbody", "appear"],
];
for (const [e, kind, act] of cases) assert.ok(heard({ ...at, ...e }).includes(VOICES[kind][act]), `${e.type}: ${kind} ${act}`);
const reached = new Set(cases.map(([, kind, act]) => `${kind}.${act}`));
for (const [kind, acts] of Object.entries(own)) for (const act of acts) assert.ok(reached.has(`${kind}.${act}`), `${kind}.${act} is reached by an event`);
for (const e of cases.map((c) => c[0])) {
const picked = heard({ ...at, ...e }).filter((n) => names.includes(n));
assert.equal(picked.length, 1, `${e.type}${e.kind ? ` (${e.kind})` : ""} plays exactly one picked sound`);
}
const weakHit = heard({ ...at, type: "bossHit", kind: "motherbog", how: "weak", weak: true });
assert.equal(weakHit.includes(VOICES.motherbog.hurt), false, "weak replaces hurt");
assert.equal(heard({ ...at, type: "bossHit", kind: "motherbog", how: "shot" }).includes(VOICES.motherbog.weak), false, "a plain shot is not weak");
// Events that are only looks (the pull of the lure, a swarm coming apart) say nothing the voices own.
for (const type of ["wispLure", "leechDie"]) assert.equal(heard({ ...at, type, kind: "leech" }).filter((n) => names.includes(n)).length, 0, `${type} is visual`);
// Every picked tone exists in the merged tones, lives in the stage's file and is named by kind and act.
const merged = ghoulSfx.default.tones;
for (const [kind, acts] of Object.entries(VOICES)) {
for (const [act, name] of Object.entries(acts)) {
assert.ok(merged[name]?.layers?.length, `${kind}.${act}: ${name} is in the merged tones`);
assert.ok(BOG_SFX.tones[name], `${name} lives in ghoul-sfx-bog.js`);
assert.equal(name, `ghoul${kind === "motherbog" ? "Mother" : kind[0].toUpperCase() + kind.slice(1)}${act[0].toUpperCase()}${act.slice(1)}`, "named by kind and act");
}
}
});
test("Ghoul Rush's bog: every new way to die has its words and its own sound, and endless lives spare the heart for each", () => {
const causes = ["lurker", "leeches", "wisp", "bogbody", "mudwave", "muck", "motherbog"];
assert.deepEqual(Object.keys(LOSE_WORDS).sort(), [...causes].sort(), "words for exactly these");
assert.deepEqual(Object.keys(LOSE_SOUNDS).sort(), [...causes].sort(), "a sound for exactly these");
for (const cause of causes) {
assert.ok(LOSE_WORDS[cause] && LOSE_SOUNDS[cause], `${cause} has its words and its sound`);
assert.ok(heard({ x: 10, y: 6, type: "lose", cause, lives: 2 }).includes(LOSE_SOUNDS[cause][0]), `${cause} plays its own sound`);
const round = motherFight();
round.infinite = true;
const lives = round.lives;
ghoul.lose(round, cause);
assert.equal(round.lives, lives, `${cause} costs none`);
const normal = motherFight();
const had = normal.lives;
ghoul.lose(normal, cause);
assert.equal(normal.lives, had - 1, `${cause} costs a heart otherwise`);
}
// The real causes the stage raises are all among them.
for (const cause of ["leeches", "mudwave", "muck", "motherbog"]) assert.ok(LOSE_WORDS[cause]);
assert.equal(bog.BOG.cause.motherbog(), "motherbog");
});
test("Ghoul Rush's bog cards: the stage card names the stage, boss and no em dash, the boss card names Old Mother Bog, and both agree", () => {
const card = INTROS.bog;
assert.equal(card.title, "Gallows Bog");
assert.equal(card.boss, "Old Mother Bog");
assert.ok(card.lines.length >= 3 && card.lines.length <= 4);
assert.equal(card.kicker, ghoul.stageById("bog").sub, "the card's kicker is the stage's subtitle");
assert.ok(card.lines.some((l) => /YOU/.test(l)) && !card.lines.some((l) => /Planny/.test(l)), "addressed to YOU, never the hero's name");
assert.ok(![card.title, card.kicker, card.boss, ...card.lines].some((t) => t.includes("\u2014")), "no em dash");
const boss = BOSS_INTROS.motherbog;
assert.equal(boss.name, "Old Mother Bog");
assert.equal(boss.name, card.boss, "the two cards agree on the name");
assert.ok(boss.epithet && !boss.epithet.includes("\u2014") && !/Planny/.test(boss.epithet));
assert.equal(bossIntroFor("motherbog"), boss);
assert.equal(introFor("bog"), card);
});
/* ------------------------------------------------------ round flow */
test("Ghoul Rush's bog round flow: the stage card opens before the Sunken Boardwalk, the hag's card before the Drowning Pool (after the ride), and neither shows on a retry", () => {
const r = ghoul.newRound(5);
r.dice = 0;
through(r);
r.offer = ["bog"];
r.phaseMs = 0;
assert.equal(ghoul.pickStage(r, 0), true);
assert.equal(r.stage, "bog");
assert.equal(r.spec.id, "boardwalk");
assert.equal(r.phase, "intro", "the stage card first");
assert.deepEqual(r.events.filter((e) => e.type === "intro").map((e) => e.stage), ["bog"]);
assert.equal(r.events.some((e) => e.type === "room"), false, "the room waits for the card");
r.introMs = ghoul.INTRO_MIN_MS;
assert.equal(ghoul.takeIntro(r), true);
assert.equal(r.phase, "ready");
ghoul.advance(r, ghoul.READY_MS + 20, steady);
assert.equal(r.phase, "play");
for (const id of ["hollow", "stilts", "bogboat"]) {
r.events.length = 0;
through(r);
assert.equal(r.spec.id, id);
assert.notEqual(r.phase, "bossintro", `${id}: no boss card`);
assert.equal(r.events.some((e) => e.type === "bossIntro"), false);
}
assert.ok(ghoul.roomById("bogboat").bonus, "the ride comes right before the boss");
r.events.length = 0;
through(r);
assert.equal(r.spec.id, "drowning");
assert.equal(r.phase, "bossintro", "the boss card");
assert.deepEqual(r.events.filter((e) => e.type === "bossIntro").map((e) => [e.boss, e.stage]), [["motherbog", "bog"]]);
assert.equal(r.boss.kind, "motherbog");
assert.equal(r.boss.state, "sleep", "she sleeps behind the card");
r.introMs = ghoul.INTRO_MIN_MS;
assert.equal(ghoul.takeIntro(r), true);
assert.equal(r.phase, "ready");
ghoul.advance(r, ghoul.READY_MS + 20, steady);
assert.equal(r.phase, "play");
// Into the pool, the fight starts; a life lost there goes back without the card.
r.events.length = 0;
standAt(r, r.spec.arena + ghoul.BOSS_LOCK + 2);
ghoul.advance(r, 4, steady);
ghoul.advance(r, ghoul.BOSS_INTRO_MS + 8, steady);
assert.equal(r.boss.state, "fight");
ghoul.lose(r, "motherbog");
for (let t = 0; t < 6000 && r.phase !== "play" && !r.over; t += 4) ghoul.advance(r, 4, steady);
assert.notEqual(r.phase, "bossintro", "no card on a retry");
assert.equal(r.events.some((e) => e.type === "bossIntro"), false, "no card event on a retry");
});
test("Ghoul Rush's bog draws: every walked room and the arena, every monster in every act, the hag in each move above and under the water, the mud wave and the muck, in a lit room and a dark one", () => {
const ctx = new Proxy({}, { get: (t, name) => (name in t ? t[name] : () => {}), set: (t, name, value) => ((t[name] = value), true) });
const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } });
g.resize(900, 900);
g.key("action");
g.tick(16);
const r = g.round;
through(r);
r.offer = ["bog"];
r.phaseMs = 0;
ghoul.pickStage(r, 0);
const acts = { lurker: ["eyes", "snap", "sink"], leech: ["drift", "drop"], wisp: ["bright", "dim", "rekindle"], bogbody: ["rise", "walk"] };
let drew = 0;
for (const id of ["boardwalk", "hollow", "stilts", "drowning"]) {
while (r.spec.id !== id) through(r);
for (const dark of [true, false]) {
r.dark = dark;
r.phase = "play";
r.lives = 99;
for (const st of r.spawns) st.over = true;
r.hordeMs = Infinity;
r.monsters.length = 0;
standAt(r, id === "drowning" ? r.spec.arena + ghoul.BOSS_LOCK + 2 : 40);
r.you.safeMs = 1e9;
for (const [kind, list] of Object.entries(acts)) list.forEach((act, i) => put(r, kind, r.you.x + 6 + i * 5, { act, wait: 300, rise: act === "rise" ? 300 : 0, y: kind === "wisp" ? 12 : undefined }));
r.monsters.at(-1).lurching = true;
if (r.boss) {
ghoul.advance(r, ghoul.BOSS_INTRO_MS + 16, steady);
for (const hidden of [false, true]) {
for (const act of ["idle", "wind", "rest", "throwWind", "sink", "under", "resurface"]) {
Object.assign(r.boss, { act, wait: 400, dir: -1, lit: act === "rest", hidden: hidden && (act === "sink" || act === "under"), sinkX: r.boss.x - 10, home: 6 });
g.tick(16);
drew++;
}
}
Object.assign(r.boss, { hidden: false, act: "rest", wait: 1e9 });
r.hazards.push({ kind: "muck", x: r.you.x + 10, y: 6, w: bog.MUCK_W, h: bog.MUCK_H, warn: 400, live: 0, cause: "muck", sx: r.boss.x, sy: 9 }, { kind: "muck", x: r.you.x + 20, y: 6, w: bog.MUCK_W, h: bog.MUCK_H, warn: 0, live: 1500, cause: "muck" });
r.waves.push({ x: r.you.x + 8, y: 6, dir: -1, life: 6000, kind: "mudwave", cause: "mudwave" });
}
for (let k = 0; k < 20; k++) g.tick(16);
r.you.safeMs = 1e9;
drew++;
}
}
assert.ok(drew >= 8 + 14, "drew a lot");
assert.equal(r.spec.id, "drowning", "got to the pool and drew it");
});
test("Ghoul Rush's bog: a seeded bot, shielded and with endless lives, plays the Sunken Boardwalk on a draw that throws if the bog's own rules ask for a random number, and any life it loses is for a cause the stage names", () => {
// The engine rolls dice of its own (power-up drops, horde edges, variants), so the draw is a steady one that throws only when the call came out of the bog's pack file.
const boom = () => {
Error.stackTraceLimit = 20;
const stack = new Error().stack;
if (stack.includes("ghoul-bog.js")) throw new Error(`the bog pack drew a random number: ${stack}`);
return 0.5;
};
let seed = 7;
const next = () => ((seed = (seed * 1103515245 + 12345) & 0x7fffffff) / 0x7fffffff);
const causes = new Set();
const round = ghoul.newRound(5);
round.dice = 0;
round.infinite = true;
through(round);
round.offer = ["bog"];
round.phaseMs = 0;
ghoul.pickStage(round, 0);
round.introMs = ghoul.INTRO_MIN_MS;
ghoul.takeIntro(round);
ghoul.advance(round, ghoul.READY_MS + 20, steady);
assert.equal(round.phase, "play");
assert.equal(round.spec.id, "boardwalk");
round.hasKey = true;
round.effects.boots = 1e9;
let far = 0;
let wake = 0;
// Walking right, firing, jumping at a gap or a step and now and then at nothing: a bot with no sense of the lurkers, the leeches or the lights.
for (let t = 0; t < 90000 && !round.over; t += 4) {
const you = round.you;
you.safeMs = 1e9;
const ahead = ghoul.groundAt(round.spec, you.x + 3);
round.input.right = true;
round.input.fire = true;
if (!Number.isFinite(ahead) || ahead > you.y + 0.4 || next() < 0.02) round.input.jump = ghoul.JUMP_BUFFER_MS;
ghoul.advance(round, 4, boom);
for (const e of round.events) {
if (e.type === "lose") causes.add(e.cause);
if (/^(lurkerSnap|leechLatch|wispLure|wispOut|bogRise)$/.test(e.type)) wake++;
}
round.events.length = 0;
far = Math.max(far, you.x);
assert.ok(Number.isFinite(you.x), "the player stays on the map");
if (round.phase === "clear") break;
}
assert.ok(far > 150, `the bot got well into the room (${far.toFixed(0)} of ${round.spec.length})`);
assert.ok(wake > 0, "the stage's monsters woke and acted around it");
assert.equal(round.lives, ghoul.newRound(5).lives, "endless lives: not one heart spent");
const known = new Set([...Object.keys(LOSE_WORDS), "pit"]);
for (const cause of causes) assert.ok(known.has(cause), `${cause} has words`);
});
@@ -0,0 +1,945 @@
// Web console tests, Ghoul Rush's Bog Runner (Gallows Bog's bonus round, between the Stilt House and the Drowning Pool): its shape (two lanes, the banks, every thing spaced for a player), the boat's motion (a steady speed on the channel, slower on the flats, a jump, a duck, a hop between lanes only at a bank), each obstacle and its cost (snag, knee, veil, limb), the fan's clog and stall, the swarm in the wake and its catch, the charms and gas pockets shot for points and a cover burst, the hearts and the grade and the dice, endless lives, the drawing and the sounds, and bots that play it.
// Run with: node --test scripts/test-web-console-activities-ghoul-bogboat.mjs
import { test } from "node:test";
import assert from "node:assert/strict";
import * as ghoul from "../src/web-console/public/activities/ghoul.js";
import { skipBossIntro } from "./ghoul-test-helpers.mjs";
import * as bz from "../src/web-console/public/activities/ghoul-bogboat.js";
import { ANSWERS, EVENT_VOICE, LOOKS as BOAT_LOOKS, LOSE_SOUNDS, LOSE_WORDS, TELEGRAPH_WORDS, VOICES as BOAT_VOICES, telegraphMarks, telegraphs } from "../src/web-console/public/activities/ghoul-bogboat-draw.js";
import * as ghoulSfx from "../src/web-console/public/activities/ghoul-sfx.js";
import { BOGBOAT_SFX } from "../src/web-console/public/activities/ghoul-sfx-bogboat.js";
import { LOOKS, VOICES, bonusTick, react } from "../src/web-console/public/activities/ghoul-draw.js";
import { BONUS_FLOOR, diceFor, endBonus, makeBonus } from "../src/web-console/public/activities/ghoul-bonus.js";
const steady = () => 0.5;
// The pack draws no random number: a run on this fails on the first draw.
const never = () => {
throw new Error("the bog runner drew a random number");
};
const events = (round, type) => round.events.filter((e) => e.type === type);
function through(round) {
round.phase = "clear";
round.phaseMs = 1;
ghoul.advance(round, 4, steady);
}
// A round in the Bog Runner reached the way play reaches it, nothing woken, the clocks long,
// the bonus round on (five hearts).
function boatRound(seed = 5) {
const round = ghoul.newRound(seed);
round.lives = 3;
round.dice = 0;
through(round);
round.offer = ["bog"];
round.phaseMs = 0;
ghoul.pickStage(round, 0);
while (round.spec.id !== "bogboat") through(round);
round.phase = "play";
for (const st of round.spawns) st.over = true;
round.monsters.length = 0;
round.hordeMs = Infinity;
round.timeMs = 1e9;
round.bonus = 1e9;
round.events.length = 0;
return round;
}
const NONE = { runner: "bogboat", time: 1e9, finish: 1e6, banks: [], snags: [], knees: [], veils: [], limbs: [], props: [], gas: [], checks: [] };
// The same round over a ride of its own (a plain channel to measure the boat on).
function synth(ride) {
const round = boatRound();
round.spec = { ...round.spec, start: 10, ground: [[0, 1e6, 9]], ride: { ...NONE, ...ride } };
round.runner = null;
bz.BOGBOAT.place[0](round, {});
return round;
}
// The boat at `x` in `lane`, on the water.
function at(round, x, lane = 0, { safe = false } = {}) {
Object.assign(round.runner, { lane, from: lane, swMs: 0, h: 0, vy: 0, air: false, v: lane ? bz.FLATS_V : bz.BOGBOAT_V, stall: 0, clog: 0 });
Object.assign(round.you, { x, y: bz.LANE_Y[lane], vy: 0, state: "run", shelf: -1, face: 1, out: 0, safeMs: safe ? 1e9 : 0, ducking: false });
round.camX = Math.max(0, Math.min(round.spec.length - ghoul.FIELD_W, x - 24));
}
function run(round, ms, keys = {}, random = steady) {
Object.assign(round.input, keys);
for (let t = 0; t < ms; t += 4) ghoul.advance(round, 4, random);
for (const k of Object.keys(keys)) round.input[k] = typeof keys[k] === "number" ? 0 : false;
}
function until(round, done, ms = 6000, random = steady) {
let t = 0;
for (; t < ms && !done(); t += 4) ghoul.advance(round, 4, random);
return t;
}
const press = (round) => {
round.input.jump = ghoul.JUMP_BUFFER_MS;
round.input.up = true;
};
const heard = (e, extra = {}) => {
const played = [];
const noop = () => {};
const kit = { tone: (name) => played.push(name), burst: noop, float: noop, ring: noop, banner: () => null, shake: noop, flash: noop, glow: noop, splat: noop, fx: { clock: 1e6 }, monsters: ghoul.MONSTERS, powers: ghoul.POWERS, bosses: ghoul.BOSSES, g: {}, floorAt: () => 6, ...extra };
react({ x: 10, y: 9, tx: 20, ty: 9, ...e }, kit);
return { played };
};
const ROOM = ghoul.roomById("bogboat");
const R = ROOM.ride;
const V = bz.BOGBOAT_V;
const things = () => [
...R.snags.map(([x, lane], i) => ({ id: `s${i}`, kind: "snag", lane, x })),
...R.knees.map(([x, lane], i) => ({ id: `k${i}`, kind: "knee", lane, x })),
...R.veils.map(([x0, x1, lane], i) => ({ id: `v${i}`, kind: "veil", lane, x: (x0 + x1) / 2 })),
...R.limbs.map(([x0, x1, lane], i) => ({ id: `l${i}`, kind: "limb", lane, x: (x0 + x1) / 2 })),
...R.props.map(([x, lane], i) => ({ id: `p${i}`, kind: "prop", lane, x })),
...R.gas.map(([x, lane], i) => ({ id: `g${i}`, kind: "gas", lane, x })),
];
const HARMFUL = new Set(["snag", "knee", "veil", "limb"]);
/* -------------------------------------------------------------- the room */
test("Ghoul Rush's Bog Runner is Gallows Bog's fourth room, between the Stilt House and the Drowning Pool: lit, no key, no boss, a ride about a minute long, a bonus round that plays its own track", () => {
const st = ghoul.stageById("bog");
assert.deepEqual(st.rooms, ["boardwalk", "hollow", "stilts", "bogboat", "drowning"]);
assert.deepEqual([ROOM.title, ROOM.sub], ["The Bog Runner", "Something swims in your wake"]);
assert.equal(ROOM.dark, false, "a moonlit night, always lit");
assert.equal(ROOM.key, null);
assert.equal(ROOM.boss, null);
assert.equal(ROOM.bonus, true, "a bonus round");
assert.equal(R.runner, "bogboat");
assert.ok(ROOM.length >= 2400 && ROOM.length <= 3000, `${ROOM.length} units long`);
assert.equal(ghoul.ROOM_MUSIC.bogboat, "ghoulBoatRide");
assert.ok(ghoulSfx.default.music.ghoulBoatRide, "its own track");
assert.deepEqual(Object.keys(bz.BOGBOAT.monsters), [], "no new monster kinds");
assert.equal(LOOKS.bogboat, BOAT_LOOKS.bogboat);
assert.equal(LOOKS.bogboat.pack, "bogboat");
assert.ok(Object.isFrozen(R) && Object.isFrozen(R.snags) && Object.isFrozen(R.snags[0]), "frozen all the way down");
assert.ok(ROOM.horde.length === 0 && ROOM.spawns.length === 0 && ROOM.items.length === 0, "no monsters or pickups: the things on the water are the pack's own");
assert.deepEqual(ROOM.ground.map((g) => g.slice()), [[0, ROOM.length, bz.LANE_Y[0]]], "one flat floor under the water");
assert.ok(R.finish < ROOM.door && ROOM.door > ROOM.length - 20, "the door at the room's end, past the finish");
assert.ok(ghoul.groundAt(ROOM, ROOM.door - 2) > -Infinity, "floor to walk out on");
const secs = (R.finish - ROOM.start) / V;
assert.ok(secs >= 56 && secs <= 80, `${secs.toFixed(1)} s at BOGBOAT_V`);
assert.equal(ghoul.timeFor(ROOM), R.time, "its own clock");
assert.ok(R.time / 1000 > secs * 1.4, "a clock with room to spare");
assert.equal(ghoul.STAGES.find((s) => s.id === "bog").rooms.length, 5);
assert.equal(R.banks.length, 11);
assert.equal(R.checks.length, 4);
assert.ok(R.props.length >= 16 && R.gas.length >= 14, "enough to shoot");
assert.ok(R.snags.length && R.knees.length && R.veils.length && R.limbs.length, "one of each thing to dodge");
});
test("Ghoul Rush's Bog Runner: every thing is in lane 0 or 1, off the ends, spaced for a player, and clear of the banks", () => {
const all = things();
assert.ok(all.length >= 70 && all.length <= 130, `${all.length} things`);
for (const t of all) {
assert.ok(t.lane === 0 || t.lane === 1, `${t.id} lane`);
assert.ok(t.x >= 120 && t.x < R.finish - 40, `${t.id} at ${t.x}`);
}
for (const lane of [0, 1]) assert.ok(all.filter((t) => t.lane === lane && HARMFUL.has(t.kind)).length >= 12, `plenty to dodge in lane ${lane}`);
// The same lane: 36 between any two (a jump and a duck need 38 at the full speed, so the slots never share).
for (const lane of [0, 1]) {
const xs = all.filter((t) => t.lane === lane).map((t) => t.x).sort((a, b) => a - b);
for (let i = 1; i < xs.length; i++) assert.ok(xs[i] - xs[i - 1] >= 36, `lane ${lane}: ${xs[i - 1]} and ${xs[i]}`);
}
// Banks: 16 wide, 200 apart, in order, and nothing within the hop of one.
R.banks.forEach(([a, b], i) => {
assert.equal(b - a, 16);
if (i) assert.equal(a - R.banks[i - 1][0], 200, "banks are spaced out");
for (const t of all) assert.ok(t.x < a - 6 || t.x > b + 22, `${t.id} at ${t.x} is near the bank ${a}`);
});
for (const [x0, x1] of R.veils) assert.equal(x1 - x0, 8);
for (const [x0, x1] of R.limbs) assert.equal(x1 - x0, 6);
// The channel is the thicker lane and the flats hold most of the gas.
const dense = (lane) => all.filter((t) => t.lane === lane && HARMFUL.has(t.kind)).length;
assert.ok(dense(0) > dense(1) * 1.5, `${dense(0)} to dodge in the channel, ${dense(1)} on the flats`);
});
test("Ghoul Rush's Bog Runner: every jump is clearable and every duck passable, at the speed of either lane, and the checkpoints sit clear of the banks", () => {
const clearFor = (h, speed) => (2 * Math.sqrt(bz.JUMP_V ** 2 - 2 * bz.GRAVITY * h) / bz.GRAVITY) * speed;
for (const speed of [bz.BOGBOAT_V, bz.FLATS_V]) {
assert.ok(clearFor(bz.SNAG_H, speed) >= bz.SNAG_W + ghoul.HIT_W + 8, `a snag at ${speed}`);
assert.ok(clearFor(bz.KNEE_H, speed) >= bz.KNEE_W + ghoul.HIT_W + 8, `knees at ${speed}`);
}
assert.ok(bz.SNAG_H < (bz.JUMP_V ** 2) / (2 * bz.GRAVITY) - 4, "a snag is well under the jump's peak");
assert.ok(ghoul.DUCK_H < bz.LOW_Y && ghoul.HIT_H > bz.LOW_Y, "a ducked Planny fits under a low and a standing one does not");
R.checks.forEach((x, i) => {
if (i) assert.ok(x - R.checks[i - 1] >= 400);
assert.ok(R.banks.every(([a, b]) => x < a - 4 || x > b + 4));
});
});
/* ---------------------------------------------------------------- the boat */
test("Ghoul Rush's Bog Runner rolls at BOGBOAT_V on the channel whatever is pressed, slower on the flats, and DOWN eases the throttle in either; the camera leads it", () => {
const round = synth({});
assert.equal(round.runner.id, "bogboat");
assert.equal(round.camLead, bz.CAM_AHEAD);
assert.equal(round.you.y, bz.LANE_Y[0]);
const x0 = round.you.x;
run(round, 1000);
assert.ok(Math.abs(round.you.x - x0 - V) < 0.5, `${round.you.x - x0} in a second`);
for (const keys of [{ left: true }, { fire: true }]) {
const a = round.you.x;
run(round, 500, keys);
assert.ok(Math.abs(round.you.x - a - V / 2) < 0.5, JSON.stringify(keys));
}
assert.equal(round.you.face, 1);
// Left and right do nothing off a bank.
run(round, 400, { right: true });
assert.equal(round.runner.lane, 0);
assert.equal(round.you.y, bz.LANE_Y[0]);
const speedOf = (lane, keys) => {
const r = synth({});
at(r, 100, lane);
run(r, 1500, keys);
return r.runner.v;
};
assert.ok(Math.abs(speedOf(0, {}) - bz.BOGBOAT_V) < 0.3);
assert.ok(Math.abs(speedOf(0, { down: true }) - bz.EASE_V) < 0.3);
assert.ok(Math.abs(speedOf(1, {}) - bz.FLATS_V) < 0.3);
assert.ok(Math.abs(speedOf(1, { down: true }) - bz.FLATS_EASE_V) < 0.3);
});
test("Ghoul Rush's Bog Runner jumps about 13 high for about three quarters of a second, a press saved for a landing jumps on it, and it cannot jump in the air", () => {
const round = synth({});
at(round, 100, 0, { safe: true });
let peak = 0;
let ms = 0;
press(round);
ghoul.advance(round, 4, steady);
round.input.up = false;
assert.equal(round.runner.air, true);
while (round.runner.air && ms < 2000) {
ghoul.advance(round, 4, steady);
peak = Math.max(peak, round.you.y - bz.LANE_Y[0]);
ms += 4;
}
assert.ok(peak > 12 && peak < 15, `${peak} high`);
assert.ok(ms > 650 && ms < 850, `${ms} ms`);
assert.equal(round.you.y, bz.LANE_Y[0]);
assert.equal(events(round, "bogboatJump").length, 1);
assert.equal(events(round, "bogboatLand").length, 1);
// A press in the air does not double jump, but waits for the landing.
const again = synth({});
at(again, 100, 0, { safe: true });
press(again);
ghoul.advance(again, 4, steady);
run(again, 400);
press(again);
run(again, 100);
assert.ok(again.runner.vy <= 0 || again.runner.air, "no second jump in mid-air");
until(again, () => !again.runner.air, 1000);
press(again);
ghoul.advance(again, 4, steady);
assert.equal(again.runner.air, true, "a press saved for the landing jumps on it");
});
test("Ghoul Rush's Bog Runner: DOWN ducks, a ducked Planny passes under a veil or a limb and a standing one hits it (causes veil and limb), at the cost of a heart", () => {
for (const [key, cause, ride] of [["veils", "veil", { veils: [[300, 308, 0]] }], ["limbs", "limb", { limbs: [[300, 306, 0]] }]]) {
const standing = synth(ride);
at(standing, 270, 0);
run(standing, 1500);
assert.equal(standing.bonusRound.hearts, 4, `${key}: a standing boat is hit`);
assert.equal(events(standing, "lose").map((e) => e.cause).join(), cause);
const ducked = synth(ride);
at(ducked, 270, 0);
run(ducked, 1500, { down: true });
assert.equal(ducked.bonusRound.hearts, 5, `${key}: a ducked boat passes`);
assert.equal(events(ducked, "bogboatDuck").length, 1);
assert.equal(events(ducked, "lose").length, 0);
}
});
test("Ghoul Rush's Bog Runner: a snag or cypress knees stop a boat that does not jump (causes snag and knee); a jump clears each; each costs only once", () => {
for (const [cause, ride] of [["snag", { snags: [[300, 0]] }], ["knee", { knees: [[300, 0]] }]]) {
const hit = synth(ride);
at(hit, 270, 0);
run(hit, 1500);
assert.equal(hit.bonusRound.hearts, 4, cause);
assert.equal(events(hit, "lose").map((e) => e.cause).join(), cause, "one heart, once");
assert.equal(events(hit, "bogboatCrash").length, 1);
const jumped = synth(ride);
at(jumped, 270, 0);
let pressed = false;
until(jumped, () => {
if (!pressed && jumped.you.x >= 300 - 14) {
press(jumped);
pressed = true;
}
return jumped.you.x > 340;
}, 3000);
assert.equal(jumped.bonusRound.hearts, 5, `${cause}: a jump clears it`);
assert.equal(jumped.bonusRound.perf.hits.length, 0);
}
// The things in the other lane do not touch a boat.
const other = synth({ snags: [[300, 1]], knees: [[300, 1]], veils: [[330, 338, 1]], limbs: [[360, 366, 1]] });
at(other, 270, 0);
run(other, 2400);
assert.equal(other.bonusRound.hearts, 5);
});
test("Ghoul Rush's Bog Runner switches lanes only inside a bank: LEFT is the channel, RIGHT the flats, in SWITCH_MS, with no jump or duck in the hop; the boat slows to the flats' speed and comes back up to the channel's", () => {
const round = synth({ banks: [[300, 316], [500, 516]] });
at(round, 301, 0, { safe: true });
run(round, 200, { right: true });
assert.equal(round.runner.lane, 1);
assert.equal(events(round, "bogboatSwitch").length, 1);
assert.equal(events(round, "bogboatSwitch")[0].to, 1);
assert.ok(round.runner.swMs > 0, "mid-hop");
assert.equal(round.you.state, "run");
// No jump or duck in the hop.
press(round);
ghoul.advance(round, 4, steady);
assert.equal(round.runner.air, false);
round.input.up = false;
run(round, bz.SWITCH_MS);
assert.equal(round.runner.swMs, 0);
assert.equal(round.you.y, bz.LANE_Y[1], "up on the flats");
assert.ok(round.runner.v < bz.BOGBOAT_V - 5, "slowed");
// Not outside a bank.
run(round, 400, { left: true });
assert.equal(round.runner.lane, 1, "off a bank nothing changes");
// Back down at the next one.
at(round, 496, 1, { safe: true });
run(round, 600, { left: true });
assert.equal(round.runner.lane, 0);
assert.equal(round.you.y, bz.LANE_Y[0]);
// Not in the air.
const air = synth({ banks: [[300, 316]] });
at(air, 304, 0, { safe: true });
press(air);
run(air, 40);
run(air, 40, { right: true });
assert.equal(air.runner.lane, 0, "no switch in the air");
});
test("Ghoul Rush's Bog Runner: the fan clogs on the flats at full throttle (a warning at CLOG_WARN, a stall at CLOG_MAX that stops the boat for STALL_MS), an ease or the channel clears it", () => {
const round = synth({});
at(round, 100, 1, { safe: true });
run(round, 1000);
assert.ok(Math.abs(round.runner.clog - bz.CLOG_RISE) < 2, `${round.runner.clog} after a second`);
until(round, () => events(round, "bogboatClog").length > 0, 4000);
assert.ok(round.runner.clog >= bz.CLOG_WARN - 1);
until(round, () => round.runner.stall > 0, 4000);
assert.equal(events(round, "bogboatStall").length, 1);
run(round, 800);
assert.ok(round.runner.v < 3, `coasting to a stop (${round.runner.v})`);
const x = round.you.x;
until(round, () => round.runner.stall === 0, 2000);
assert.equal(round.runner.stall, 0);
assert.ok(round.runner.clog >= bz.CLOG_RESTART && round.runner.clog < bz.CLOG_WARN, `restarted at ${round.runner.clog}`);
assert.ok(round.you.x - x < 6, "hardly moved while stalled");
// Eased, the flats cool the fan.
const eased = synth({});
at(eased, 100, 1, { safe: true });
run(eased, 1200);
const hot = eased.runner.clog;
run(eased, 1000, { down: true });
assert.ok(eased.runner.clog < hot, "an ease cools it");
// And the channel does.
const channel = synth({});
at(channel, 100, 0, { safe: true });
channel.runner.clog = 80;
run(channel, 1000);
assert.ok(Math.abs(channel.runner.clog - (80 - bz.CLOG_COOL)) < 0.5, `${channel.runner.clog}`);
// A stalled fan stops the boat, so the swarm gains on it.
const lost = synth({});
at(lost, 100, 1, { safe: true });
Object.assign(lost.runner, { clog: bz.CLOG_MAX - 0.1, gap: bz.GAP_MAX });
until(lost, () => lost.runner.stall > 0, 1000);
const gap = lost.runner.gap;
run(lost, 1000);
assert.ok(lost.runner.gap < gap - 10, `${gap} to ${lost.runner.gap}`);
});
test("Ghoul Rush's Bog Runner's wake: it opens on clean riding, closes when the boat is eased or on the flats, a hit shoves it HIT_CLOSE closer, and PANIC_ON boils it until PANIC_OFF", () => {
const round = synth({});
at(round, 100, 0, { safe: true });
run(round, 500);
assert.ok(round.runner.gap > bz.GAP_START, "opening");
run(round, 2000);
assert.equal(round.runner.gap, bz.GAP_MAX, "never over GAP_MAX");
const eased = synth({});
at(eased, 100, 0, { safe: true });
eased.runner.gap = 30;
run(eased, 2000, { down: true });
assert.ok(eased.runner.gap < 30, "the ease loses ground");
const flats = synth({});
at(flats, 100, 1, { safe: true });
flats.runner.gap = 30;
run(flats, 500, { down: true });
assert.ok(flats.runner.gap < 30, "the eased flats lose ground");
// A hit shoves it closer.
const hit = synth({ snags: [[300, 0]] });
at(hit, 280, 0);
hit.runner.gap = 30;
run(hit, 500);
assert.ok(hit.runner.gap <= 30 - bz.HIT_CLOSE + (V - bz.WAKE_V) * 0.5 + 1, `${hit.runner.gap}`);
assert.equal(hit.bonusRound.hearts, 4);
// PANIC_ON: the swarm boils (an event, once), PANIC_OFF puts it out and it can boil again.
const panic = synth({});
at(panic, 100, 0, { safe: true });
panic.runner.gap = bz.PANIC_ON + 0.5;
panic.runner.v = 20;
run(panic, 200, { down: true });
assert.equal(panic.runner.panic, true);
assert.equal(events(panic, "bogboatPanic").length, 1);
run(panic, 4000);
assert.equal(panic.runner.panic, false);
assert.equal(panic.bonusRound.perf.steady, false, "a swarm that boiled loses the steady die");
assert.equal(panic.runner.panicked, true);
const clean = synth({});
at(clean, 100, 0, { safe: true });
run(clean, 3000);
assert.equal(clean.bonusRound.perf.steady, true);
});
test("Ghoul Rush's Bog Runner: at WAKE_CATCH the swarm has you, a heart (cause wake), and it falls back to WAKE_FALLBACK, once; a blinking boat is caught for free; the catch is counted for the grade", () => {
const round = synth({});
at(round, 100, 0);
round.runner.v = 20;
round.runner.gap = bz.WAKE_CATCH + 0.2;
run(round, 200, { down: true });
assert.equal(round.bonusRound.hearts, 4);
assert.equal(events(round, "lose").map((e) => e.cause).join(), "wake");
assert.equal(events(round, "bogboatCatch").length, 1);
assert.ok(round.runner.gap > bz.WAKE_FALLBACK - 3 && round.runner.gap <= bz.WAKE_FALLBACK + 2, `${round.runner.gap}`);
assert.equal(round.runner.catches, 1);
assert.equal(round.bonusRound.perf.total, 1);
assert.deepEqual(round.bonusRound.perf.hits, ["w1"]);
assert.equal(round.phase, "play", "the ride goes on");
const free = synth({});
at(free, 100, 0, { safe: true });
free.runner.v = 20;
free.runner.gap = bz.WAKE_CATCH + 0.2;
run(free, 200, { down: true });
assert.equal(free.bonusRound.hearts, 5);
assert.equal(events(free, "bogboatCatch").length, 1);
assert.equal(free.runner.gap > bz.WAKE_CATCH + 10, true, "still falls back");
});
/* ------------------------------------------------------------ shooting */
test("Ghoul Rush's Bog Runner: one bolt breaks a charm (60 points) and one bursts a gas pocket (90 points, the wake pushed back GAS_PUSH), each an act for the grade; a bolt at another height flies on; a pocket stays burst across a re-seat", () => {
const round = synth({ props: [[330, 0, 0], [380, 1, 1]], gas: [[420, 0], [470, 1]] });
at(round, 300, 0, { safe: true });
round.runner.gap = 20;
const score = round.score;
round.shots.push({ x: 328, y: bz.LANE_Y[0] + 2.4, vx: 130, vy: 0, gone: 0 });
ghoul.advance(round, 4, steady);
assert.equal(round.runner.props[0].state, "broken");
assert.equal(round.score - score, bz.PROP_POINTS);
assert.equal(round.bonusRound.perf.acts, 1);
assert.equal(events(round, "bogboatProp").length, 1);
assert.equal(events(round, "bogboatProp")[0].points, bz.PROP_POINTS);
// A bolt too high flies on, one in the wrong lane too.
round.shots.push({ x: 418, y: bz.LANE_Y[0] + 9, vx: 130, vy: 0, gone: 0 });
round.shots.push({ x: 468, y: bz.LANE_Y[0] + 2.4, vx: 130, vy: 0, gone: 0 });
ghoul.advance(round, 4, steady);
assert.equal(round.runner.gas[0].state, "up");
assert.equal(round.runner.gas[1].state, "up", "the flats' pocket needs a bolt at the flats' height");
const gap = round.runner.gap;
round.shots.push({ x: 418, y: bz.LANE_Y[0] + 2.4, vx: 130, vy: 0, gone: 0 });
ghoul.advance(round, 4, steady);
assert.equal(round.runner.gas[0].state, "burst");
assert.ok(round.runner.gap - gap >= bz.GAS_PUSH - 0.5, `pushed back ${round.runner.gap - gap}`);
assert.equal(round.bonusRound.perf.acts, 2);
assert.equal(events(round, "bogboatGas")[0].points, bz.GAS_POINTS);
// Burst, then spent; a second bolt through the cloud does nothing.
run(round, bz.GAS_BURST_MS + 20);
assert.equal(round.runner.gas[0].state, "spent");
const acts = round.bonusRound.perf.acts;
round.shots.push({ x: 418, y: bz.LANE_Y[0] + 2.4, vx: 130, vy: 0, gone: 0 });
ghoul.advance(round, 4, steady);
assert.equal(round.bonusRound.perf.acts, acts);
// A charm hit in the flats' height.
at(round, 340, 1, { safe: true });
round.shots.push({ x: 378, y: bz.LANE_Y[1] + 2.4, vx: 130, vy: 0, gone: 0 });
ghoul.advance(round, 4, steady);
assert.equal(round.runner.props[1].state, "broken");
// What was shot stays shot when the boat is put back (a re-seat in the same room), a pocket still bursting too.
Object.assign(round.runner.gas[1], { state: "burst", t: 300 });
bz.BOGBOAT.place[0](round, {});
assert.equal(round.runner.gas[0].state, "spent");
assert.equal(round.runner.props[0].state, "broken");
assert.equal(round.runner.props[1].state, "broken");
assert.equal(round.runner.gas[1].state, "spent", "a burst pocket is not revived");
const fresh = synth({ gas: [[420, 0]] });
assert.equal(fresh.runner.gas[0].state, "up");
});
/* --------------------------------------------------------------- the round */
test("Ghoul Rush's Bog Runner: 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 Drowning Pool", () => {
const round = boatRound();
round.dice = 2;
round.bonusRound.hearts = 1;
const first = things().filter((t) => t.lane === 0 && HARMFUL.has(t.kind)).sort((a, b) => a.x - b.x)[0];
at(round, first.x - 12, 0);
until(round, () => round.phase === "clear", 8000);
assert.equal(round.bonusRound.hearts, 0);
assert.equal(round.bonusRound.over, true);
assert.equal(round.bonusRound.won, false);
const end = events(round, "bonusEnd");
assert.equal(end.length, 1);
assert.equal(end[0].won, false);
assert.equal(end[0].dice, 0);
assert.equal(round.over, false, "no game over");
assert.equal(round.lives, 3);
assert.equal(round.dice, 2);
run(round, ghoul.CARD_LOST_MS + 100);
assert.equal(round.spec.id, "drowning");
assert.equal(round.bonusRound, null);
assert.equal(round.runner, null);
assert.equal(round.lives, 3);
assert.equal(round.dice, 2);
skipBossIntro(ghoul, round);
assert.equal(round.phase, "ready");
});
test("Ghoul Rush's Bog Runner: the checkpoints are passed in order (an event each) and the ride goes back to the last one after the last heart", () => {
const round = boatRound();
at(round, R.checks[0] - 6, 0, { safe: true });
until(round, () => round.runner.check >= 0, 3000);
assert.deepEqual(events(round, "bogboatCheck").map((e) => e.n).slice(0, 1), [1]);
const c0 = round.runner.check;
round.you.x = 1;
bz.BOGBOAT.place[0](round, {});
assert.equal(round.you.x, R.checks[c0]);
assert.equal(round.runner.check, c0);
assert.equal(round.runner.lane, 0);
assert.equal(round.camLead, bz.CAM_AHEAD);
const fresh = boatRound();
assert.equal(fresh.you.x, ROOM.start);
assert.equal(fresh.runner.check, -1);
// Past all four on a long ride.
const long = synth({ checks: R.checks });
long.you.safeMs = 1e9;
long.timeMs = 1e9;
run(long, 62000);
assert.equal(long.runner.check, R.checks.length - 1);
});
test("Ghoul Rush's Bog Runner: at the finish the fan is cut, the door opens, and walking out ends the round with 3 to 9 Lucky dice", () => {
const round = boatRound();
round.dice = 1;
at(round, R.finish - 8, 1, { safe: true });
until(round, () => round.runner.done, 3000);
assert.equal(round.runner.done, true);
assert.equal(events(round, "bogboatFinish").length, 1);
assert.equal(round.you.y, ghoul.groundAt(ROOM, round.you.x), "back down on the water's floor, from either lane");
assert.equal(round.hasKey, true, "the door opens");
assert.equal(round.bonusRound.hearts, 5);
assert.equal(round.phase, "play");
round.input.right = true;
until(round, () => round.phase === "clear", 20000);
round.input.right = false;
assert.equal(round.phase, "clear");
const end = events(round, "bonusEnd");
assert.equal(end.length, 1);
assert.equal(end[0].won, true);
assert.ok(end[0].dice >= BONUS_FLOOR && end[0].dice <= ghoul.MAX_DICE, `${end[0].dice} dice`);
assert.equal(round.dice, Math.min(ghoul.MAX_DICE, 1 + end[0].dice));
assert.equal(round.lives, 3);
run(round, ghoul.CARD_MS + 100);
assert.equal(round.spec.id, "drowning");
assert.equal(round.runner, null);
});
test("Ghoul Rush's Bog Runner: no random number is drawn in the room (a ride of 20 seconds, jumping, switching and shooting, on a draw that throws)", () => {
const round = boatRound();
round.you.safeMs = 1e9;
for (let t = 0; t < 20000; t += 16) {
round.input.fire = true;
round.input.right = t % 6000 < 3000;
round.input.left = !round.input.right;
round.input.down = t % 2500 < 400;
if (t % 1500 === 0) press(round);
ghoul.advance(round, 16, never);
round.input.up = false;
round.events.length = 0;
}
assert.ok(round.you.x > 300);
});
/* ----------------------------------------------------------- grade and dice */
test("Ghoul Rush's Bog Runner's grade: the obstacles the boat faced are the total, one passed in its lane counts and one dodged by a lane does not, shooting 8 things is the die, a swarm that never boiled is the die", () => {
const ride = { banks: [[300, 316]], snags: [[400, 0]], knees: [[460, 0], [460, 1]], gas: [[600, 1]] };
const round = synth(ride);
at(round, 250, 0, { safe: true });
assert.equal(round.bonusRound.perf.total, 0);
assert.equal(round.bonusRound.perf.goal, bz.ACTS_GOAL);
// Stay in the channel: the snag and the channel's knees are faced, not the flats' knees.
until(round, () => round.you.x > 480, 6000);
assert.equal(round.bonusRound.perf.total, 2);
// Switch away at the bank: the channel's things are dodged by the lane and not counted; the flats' are.
const away = synth(ride);
at(away, 296, 0, { safe: true });
away.input.right = true;
run(away, 500);
away.input.right = false;
assert.equal(away.runner.lane, 1);
until(away, () => away.you.x > 480, 8000);
const faced = Object.keys(away.runner.faced).filter((id) => id[0] !== "w");
assert.deepEqual(faced, ["k1"], "the flats' knees only: the channel's things were dodged by a lane");
assert.equal(away.bonusRound.perf.hits.filter((id) => id[0] !== "w").length, 0);
// A faced thing that cost a heart is a hit, counted once.
const hit = synth(ride);
at(hit, 385, 0);
run(hit, 800);
assert.deepEqual(hit.bonusRound.perf.hits, ["s0"]);
assert.equal(hit.bonusRound.perf.total, 1);
// The dice: the floor, hearts, clean passes, acts, a swarm that never boiled.
const b = makeBonus({ stats: { kills: 0 } });
b.perf = { total: 20, hits: [], acts: 0, goal: bz.ACTS_GOAL, steady: false, kills0: 0 };
assert.equal(diceFor(b), BONUS_FLOOR + 2 + 2);
b.perf.steady = true;
assert.equal(diceFor(b), 9 - 1);
b.perf.acts = bz.ACTS_GOAL;
assert.equal(diceFor(b), 9);
b.perf.acts = bz.ACTS_GOAL - 1;
assert.equal(diceFor(b), 8);
b.hearts = 1;
assert.equal(diceFor(b), 6);
b.perf.hits = Array.from({ length: 20 }, (_, i) => `x${i}`);
assert.equal(diceFor(b), BONUS_FLOOR + 0 + 0 + 0 + 1);
b.perf.steady = false;
assert.equal(diceFor(b), BONUS_FLOOR);
});
const CAUSES = {
snag: { snags: [[300, 0]] },
knee: { knees: [[300, 0]] },
veil: { veils: [[300, 308, 0]] },
limb: { limbs: [[300, 306, 0]] },
};
test("Ghoul Rush's Bog Runner: endless lives (round.infinite) spare the hearts for every cause, through the same lose path", () => {
for (const [cause, ride] of Object.entries(CAUSES)) {
const round = synth(ride);
round.infinite = true;
at(round, 270, 0);
run(round, 1800);
assert.ok(events(round, "lose").some((e) => e.cause === cause), `${cause} was lost to`);
assert.equal(round.bonusRound.hearts, 5, `${cause} cost nothing`);
assert.equal(round.lives, 3);
assert.equal(round.phase, "play");
}
const wake = synth({});
wake.infinite = true;
at(wake, 100, 0);
wake.runner.v = 20;
wake.runner.gap = bz.WAKE_CATCH + 0.2;
run(wake, 200, { down: true });
assert.ok(events(wake, "lose").some((e) => e.cause === "wake"), "the wake was lost to");
assert.equal(wake.bonusRound.hearts, 5);
});
test("Ghoul Rush's Bog Runner: every cause costs exactly one heart", () => {
for (const [cause, ride] of Object.entries(CAUSES)) {
const round = synth(ride);
at(round, 270, 0);
run(round, 1800);
assert.equal(round.bonusRound.hearts, 4, cause);
assert.equal(events(round, "lose").map((e) => e.cause).join(), cause);
assert.equal(round.lives, 3);
}
});
test("Ghoul Rush's Bog Runner: the Garlic shield takes a hit instead of a heart", () => {
const round = synth({ snags: [[300, 0]] });
round.you.garlic = true;
at(round, 285, 0);
round.you.garlic = true;
run(round, 800);
assert.equal(round.bonusRound.hearts, 5);
assert.equal(round.you.garlic, false);
});
/* ---------------------------------------------------------------- voices */
test("Ghoul Rush's Bog Runner: every event has a voice that plays, every cause has words and a sound, and the voices are tones that exist (none over 1.2 s)", () => {
assert.deepEqual(Object.keys(EVENT_VOICE).sort(), [...bz.EVENTS].sort(), "a voice for every event and no more");
const tones = ghoulSfx.default.tones;
for (const [event, [kind, act]] of Object.entries(EVENT_VOICE)) {
const name = BOAT_VOICES[kind] && BOAT_VOICES[kind][act];
assert.ok(name, `${event} has a ${kind}.${act} voice`);
assert.ok(tones[name], `${name} exists`);
assert.equal(VOICES[kind][act], name, "joined to the game's voices");
const played = heard({ type: event, what: "snag", kind: 0, points: 50, to: 1 }).played;
assert.ok(played.includes(name), `${event} plays ${name}`);
}
for (const [name, def] of Object.entries(BOGBOAT_SFX.tones)) {
assert.ok(tones[name], name);
for (const l of def.layers) assert.ok(l.seconds > 0 && l.seconds + (l.delay || 0) <= 1.2, `${name} is short`);
}
for (const cause of ["snag", "knee", "veil", "limb", "wake"]) {
assert.ok(LOSE_WORDS[cause], `${cause} has words`);
assert.ok(LOSE_SOUNDS[cause] && LOSE_SOUNDS[cause].length === 3, `${cause} has a sound`);
assert.ok(heard({ type: "lose", cause, hearts: 3 }).played.length > 0, `${cause} sounds`);
}
assert.equal(heard({ type: "bogboatJump" }).played.length, 1);
assert.equal(heard({ type: "bogboatGas", points: 90 }).played.length, 1);
});
test("Ghoul Rush's Bog Runner: its music has the room's level of voices, bars of sixteen steps, and a track for the room", () => {
const track = ghoulSfx.default.music.ghoulBoatRide;
assert.equal(track, BOGBOAT_SFX.music.ghoulBoatRide);
const playing = Object.entries(track.voices).filter(([, v]) => (v.from ?? 0) <= 0.7);
assert.ok(playing.length >= 4);
for (const [name, p] of Object.entries(track.patterns)) {
for (const [voice, line] of Object.entries(p)) {
assert.ok(track.voices[voice], `${name}.${voice} is a voice`);
for (const bar of line.split("|")) assert.equal(bar.trim().split(/\s+/).length, 16, `${name}.${voice}`);
}
}
for (const name of track.order) assert.ok(track.patterns[name]);
});
test("Ghoul Rush's Bog Runner: the room's own names do not collide with the game's (hazards, events, kinds)", () => {
for (const e of bz.EVENTS) assert.ok(e.startsWith("bogboat"), e);
assert.ok(!bz.EVENTS.some((e) => e.startsWith("bogboatboat")), "no bogboatboat names");
assert.deepEqual(Object.keys(bz.BOGBOAT).filter((key) => ["hazards", "bosses", "boss"].includes(key)), []);
assert.equal(typeof ghoul.ROOM_MUSIC.bogboat, "string");
assert.equal(ghoul.roomById("bogboat").ride.runner, "bogboat");
for (const kind of Object.keys(BOAT_VOICES)) assert.ok(kind.startsWith("bogboat"), kind);
});
/* --------------------------------------------------------------- drawing */
test("Ghoul Rush's Bog Runner draws: the room in a lit and a dark one, the boat on each lane, in the air, ducking and switching, each thing in each state, the swarm far and close, the clog and the stall, a crash, the finish and the cards", () => {
const ctx = new Proxy({}, { get: (t, name) => (name in t ? t[name] : () => {}), set: (t, name, value) => ((t[name] = value), true) });
const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } });
g.resize(900, 900);
g.key("action");
g.tick(16);
const r = g.round;
through(r);
r.offer = ["bog"];
r.phaseMs = 0;
ghoul.pickStage(r, 0);
while (r.spec.id !== "bogboat") through(r);
r.lives = 99;
const spots = [ROOM.start + 40, R.snags[0][0] - 10, R.limbs[0][0] - 5, R.veils[0][0] - 5, R.gas[0][0] - 10, R.checks[0], R.banks[0][0] + 2, R.finish - 40];
for (const dark of [true, false]) {
for (const x of spots) {
r.dark = dark;
r.phase = "play";
for (const st of r.spawns) st.over = true;
r.hordeMs = Infinity;
r.monsters.length = 0;
for (const lane of [0, 1]) {
at(r, x, lane, { safe: true });
r.runner.props = r.runner.props.map((p, i) => ({ ...p, state: i % 3 ? "up" : "broken" }));
r.runner.gas = r.runner.gas.map((p, i) => ({ ...p, state: ["up", "burst", "spent"][i % 3], t: 300 }));
for (const air of [false, true]) {
if (air) Object.assign(r.runner, { air: true, h: 5, vy: 20, gap: 12, panic: true, clog: 90 });
if (air) Object.assign(r.you, { state: "air", vy: 20, y: r.you.y + 5 });
if (!air) Object.assign(r.runner, { gap: 30, panic: false, clog: 20 });
r.you.ducking = !air && lane === 0;
r.runner.stall = air ? 800 : 0;
r.shots.push({ x: x + 6, y: r.you.y + 2.4, vx: 130, vy: 0, gone: 0 });
for (let k = 0; k < 4; k++) g.tick(16);
r.monsters.length = 0;
r.you.safeMs = 1e9;
at(r, x, lane, { safe: true });
}
}
}
}
// A switch in progress, mid-hop.
at(r, R.banks[0][0] + 2, 0, { safe: true });
r.input.right = true;
for (let k = 0; k < 12; k++) g.tick(16);
r.input.right = false;
assert.equal(r.spec.id, "bogboat");
// Crashes: a snag.
r.you.safeMs = 0;
at(r, R.snags[0][0] - 3, R.snags[0][1]);
for (let k = 0; k < 30; k++) g.tick(16);
assert.ok(r.bonusRound.hearts < r.bonusRound.max || r.phase !== "play", "the crash draws too");
const done = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } });
done.resize(900, 900);
done.key("action");
done.tick(16);
const d = done.round;
through(d);
d.offer = ["bog"];
d.phaseMs = 0;
ghoul.pickStage(d, 0);
while (d.spec.id !== "bogboat") through(d);
d.phase = "play";
d.runner.done = true;
d.runner.restX = R.finish + 10;
Object.assign(d.you, { x: R.finish + 20, y: 9, state: "run" });
d.camX = R.finish - 40;
for (let k = 0; k < 10; k++) done.tick(16);
for (const won of [true, false]) {
endBonus(d, won, { ROOM_POINTS: 300, award: (rd, pts) => (rd.score += pts) });
d.bonusRound.over = true;
for (let k = 0; k < 10; k++) {
done.tick(16);
bonusTick(d, { tone() {}, fx: {} });
}
d.bonusRound.over = false;
}
// The stage select goes straight into it.
const pick = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } });
pick.resize(900, 900);
pick.stageSelect();
const p = pick.round;
const at2 = ghoul.STAGES.findIndex((s) => s.id === "bog");
for (let i = 0; i < at2; i++) ghoul.steerSelect(p, 1, 0);
for (let i = 0; i < 3; i++) ghoul.steerSelect(p, 0, 1);
assert.equal(p.select.room, 3);
pick.tick(16);
ghoul.takeSelect(p);
assert.equal(p.spec.id, "bogboat");
assert.equal(p.runner.lane, 0);
assert.equal(p.you.y, bz.LANE_Y[0]);
pick.tick(16);
});
/* ----------------------------------------------------------- the bots */
// A bot that rides well: it keeps to the channel, jumps 9 to 15 short of a snag or cypress knees, ducks under
// every veil and limb, and holds the blaster. `miss` is the share of things it fails to dodge (by a hash).
const mix = (a, b) => {
let h = Math.imul(a + 0x9e37, 0x85ebca6b) ^ Math.imul(b + 0x7f4a, 0xc2b2ae35);
h ^= h >>> 13;
h = Math.imul(h, 0x5bd1e995);
h ^= h >>> 15;
return (h >>> 0) / 4294967296;
};
function goodBot(round, seed, miss = 0.04, shoot = true) {
const { you, runner: c, input: inp } = round;
inp.left = inp.right = inp.down = false;
inp.fire = shoot;
if (round.phase !== "play" || !c || c.done) {
inp.up = false;
return;
}
const ok = (x) => mix(seed, Math.round(x)) >= miss;
const look = 9 + (seed % 7);
const lane = c.lane;
const bank = R.banks.find(([a, b]) => you.x >= a && you.x <= b);
if (bank) inp.left = true;
let jump = false;
const ahead = (x) => x - you.x > 6 && x - you.x < look;
for (const [x, l] of R.snags) if (l === lane && ahead(x) && ok(x)) jump = true;
for (const [x, l] of R.knees) if (l === lane && ahead(x) && ok(x)) jump = true;
for (const [x0, x1, l] of [...R.veils, ...R.limbs]) if (l === lane && you.x > x0 - 10 && you.x < x1 + 3 && ok(x0)) inp.down = true;
if (jump && !inp.down && !c.air) press(round);
else inp.up = false;
}
function idleBot(round) {
const inp = round.input;
inp.left = inp.right = inp.down = false;
inp.up = false;
inp.fire = true;
}
function rideWith(seed, bot, limit = 100000) {
const round = boatRound(seed);
const lost = [];
let t = 0;
for (; t < limit && round.phase !== "clear" && !round.over; t += 16) {
bot(round);
if (round.runner && round.runner.done && round.phase === "play") round.input.right = true;
ghoul.advance(round, 16, steady);
for (const e of round.events) if (e.type === "lose") lost.push(e.cause);
if (round.runner && !round.runner.done) {
const off = round.you.x - round.camX;
assert.ok(off > 4 && off < 70, `the boat 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 Bog Runner: a bot that rides well finishes the whole channel in 57 to 75 seconds, with 5 to 9 dice, a few hearts lost at most, past every checkpoint", () => {
const dice = [];
const gone = [];
for (let seed = 1; seed <= 12; seed++) {
const { round, lost, ms } = rideWith(seed, (r) => goodBot(r, seed));
const b = round.bonusRound;
assert.equal(b.won, true, `seed ${seed} finished (lost ${lost.join(",")})`);
assert.ok(ms > 57000 && ms < 76000, `${ms} ms`);
assert.ok(b.dice >= 5 && b.dice <= ghoul.MAX_DICE, `${b.dice} dice`);
assert.equal(round.lives, 3, "never a run life");
dice.push(b.dice);
gone.push(lost.length);
}
assert.ok(dice.reduce((a, b) => a + b, 0) / dice.length >= 5.5, `${dice.join(",")}`);
assert.ok(gone.every((n) => n <= 4), `${gone.join(",")}`);
});
test("Ghoul Rush's Bog Runner: a bot that misses a quarter of the things loses, and a bot that never dodges (holding fire) loses all five hearts before 40% of the room, ends with 0 dice and the run goes on", () => {
let finished = 0;
for (let seed = 1; seed <= 6; seed++) if (rideWith(seed, (r) => goodBot(r, seed, 0.25)).round.bonusRound.won) finished++;
assert.ok(finished <= 3, `${finished} of 6 finished missing a quarter`);
for (let seed = 1; seed <= 6; seed++) {
const { round, lost } = rideWith(seed, idleBot);
const b = 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}`);
assert.equal(round.lives, 3);
assert.equal(round.over, false);
}
});
/* ------------------------------------------------------------ telegraphs */
test("Ghoul Rush's Bog Runner telegraphs: JUMP over snags and knees, DUCK under veils and limbs, SHOOT at the first gas pockets, for the boat's lane only, words on the first three of each kind, the same every time", () => {
const marks = telegraphMarks(R);
const gasMarks = marks.filter((m) => m.kind === "gas");
assert.ok(gasMarks.length >= 1 && gasMarks.length < R.gas.length, "only the first pockets are marked");
assert.equal(marks.length, R.snags.length + R.knees.length + R.veils.length + R.limbs.length + gasMarks.length);
for (const m of marks) assert.equal(m.answer, ANSWERS[m.kind], m.kind);
assert.equal(ANSWERS.snag, "JUMP");
assert.equal(ANSWERS.knee, "JUMP");
assert.equal(ANSWERS.veil, "DUCK");
assert.equal(ANSWERS.limb, "DUCK");
assert.equal(ANSWERS.gas, "SHOOT");
const first = R.limbs[0];
const m = marks.find((q) => q.kind === "limb" && q.x === (first[0] + first[1]) / 2);
const lane = first[2];
const xs = [m.lead - 45, m.lead - 41, m.lead - 36, m.lead - 30, m.lead - 10, m.lead, m.lead + 3, m.lead + 7];
const alphaOf = (x) => (telegraphs(R, x, lane).find((t) => t.kind === "limb" && t.lead === m.lead) || { alpha: 0 }).alpha;
const a = xs.map(alphaOf);
assert.equal(a[0], 0, "not yet in view");
assert.ok(a[2] > 0 && a[2] < 1, "fading in 40 to 30 ahead");
assert.equal(a[3], 1);
assert.equal(a[4], 1);
assert.ok(a[6] > 0 && a[6] < 1, "fading as it passes");
assert.equal(a[7], 0, "gone once passed");
assert.deepEqual(telegraphs(R, m.lead - 33, lane), telegraphs(R, m.lead - 33, lane), "deterministic");
for (const kind of ["snag", "knee", "veil", "limb", "gas"]) {
const of = marks.filter((q) => q.kind === kind).sort((p, q) => p.lead - q.lead);
assert.ok(of.length >= 1, kind);
of.forEach((q, i) => {
assert.equal(q.n, kind === "gas" ? q.n : i);
const shown = telegraphs(R, q.lead - 32, q.lane).find((t) => t.lead === q.lead && t.kind === kind);
assert.ok(shown, `${kind} ${i} shows`);
assert.equal(shown.words, q.n < TELEGRAPH_WORDS, `${kind} ${i}`);
});
}
// In the other lane a thing shows nothing.
const s = marks.find((q) => q.kind === "snag");
assert.ok(!telegraphs(R, s.lead - 32, 1 - s.lane).some((t) => t.lead === s.lead && t.kind === "snag"));
});
test("Ghoul Rush's Bog Runner's intro banner says the controls plainly", () => {
assert.match(R.how, /LEFT or RIGHT at a bank/);
assert.match(R.how, /UP jump, DOWN duck/);
assert.match(R.how, /SPACE shoot/);
assert.ok(R.how.length <= 72);
});
@@ -0,0 +1,303 @@
// Web console tests, Ghoul Rush's boss intro cards: every boss room has an entry (the boss's exact name, an epithet, no em dash, never the hero's name), the card shows when a boss room is entered (after the bonus ride too) and in no other room, not again on a retry, any fresh move key, fire or click moves it on after the lockout (repeats and early presses never do), it never moves on by itself, a pause holds it, and it draws for every boss on a fake canvas (through the boss's own art, with a fallback when the art throws or is missing).
import { test } from "node:test";
import assert from "node:assert/strict";
import * as ghoul from "../src/web-console/public/activities/ghoul.js";
import { BOSS_INTROS, MAX_EPITHET, bossIntroFor } from "../src/web-console/public/activities/ghoul-boss-intros.js";
import { BOSS_HINT, BOSS_TITLE, beatAt, landAt, shakeAt, bossIntroArt } from "../src/web-console/public/activities/ghoul-bossintro-draw.js";
import { INTROS } from "../src/web-console/public/activities/ghoul-intros.js";
import { toneNames } from "../src/web-console/public/tones.js";
import { skipBossIntro } from "./ghoul-test-helpers.mjs";
const steady = () => 0.5;
const DASH = String.fromCharCode(0x2014);
function fakeCtx(texts) {
return new Proxy({}, {
get: (t, name) => (name in t ? t[name] : name === "fillText" ? (s) => texts.push(s) : () => {}),
set: (t, name, value) => ((t[name] = value), true),
});
}
function newGame(texts = [], opts = {}) {
const ctx = fakeCtx(texts);
const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx }, ...opts });
g.resize(900, 900);
g.key("action");
g.round.dice = 0;
return g;
}
// A game on the stage select, straight into room `room` of the stage at `at` (a boss room is the last).
function selectInto(at, room, texts = [], opts = {}) {
const g = newGame(texts, opts);
g.round.phase = "select";
g.round.select = { at, room };
g.round.practice = true;
g.key("action");
return g;
}
const bossRooms = ghoul.ROOMS.filter((r) => r.boss);
// A round at the stage pick, the offer settled, then into `id`'s first room (the stage's intro card skipped).
function inStage(id) {
const r = ghoul.newRound(3);
r.dice = 0;
r.phase = "clear";
r.phaseMs = 1;
ghoul.advance(r, 4, steady);
r.offer = [id];
r.phaseMs = 0;
assert.equal(ghoul.pickStage(r, 0), true);
r.introMs = ghoul.INTRO_MIN_MS;
assert.equal(ghoul.takeIntro(r), true);
return r;
}
const through = (round) => {
round.phase = "clear";
round.phaseMs = 1;
ghoul.advance(round, 4, steady);
};
test("Ghoul Rush boss intros: every boss room has an entry with the boss's exact name and a short epithet, no em dash, never the hero's name", () => {
assert.ok(bossRooms.length >= 10, "the boss rooms are found");
const ids = new Set(bossRooms.map((r) => r.boss));
for (const id of ids) {
const info = bossIntroFor(id);
assert.ok(info, `the boss "${id}" needs an entry in ghoul-boss-intros.js (BOSS_INTROS)`);
assert.equal(info.name, ghoul.BOSSES[id].name, `${id}: the name is the boss's own`);
assert.ok(typeof info.epithet === "string" && info.epithet.length >= 8 && info.epithet.length <= MAX_EPITHET, `${id}: an epithet of 8 to ${MAX_EPITHET} characters`);
for (const text of [info.name, info.epithet]) {
assert.ok(!text.includes(DASH), `${id}: no em dash`);
assert.ok(!/planny/i.test(text), `${id}: never the hero's name`);
}
if (info.accent) assert.match(info.accent, /^#[0-9a-f]{6}$/i);
}
for (const id of Object.keys(BOSS_INTROS)) assert.ok(ids.has(id), `${id} is no boss of any room`);
for (const st of ghoul.STAGES) {
assert.ok(INTROS[st.id], st.id);
assert.equal(INTROS[st.id].boss, bossIntroFor(st.boss).name, `${st.id}: the stage card and the boss card agree on the name`);
assert.equal(ghoul.roomById(st.rooms.at(-1)).boss, st.boss, `${st.id}: its last room holds its boss`);
}
assert.equal(bossIntroFor("nobody"), null);
assert.ok(toneNames().includes("ghoulBossIntro"), "the sting is a real tone");
});
test("Ghoul Rush boss intros: a new boss room added without an entry would fail (the check reads every room)", () => {
const missing = [...ghoul.ROOMS, { id: "fake", boss: "newfiend" }].filter((r) => r.boss && !bossIntroFor(r.boss)).map((r) => r.boss);
assert.deepEqual(missing, ["newfiend"]);
});
test("Ghoul Rush boss intros: every stage's boss room opens on the card, after the bonus ride too, and no other room does", () => {
for (const st of ghoul.STAGES) {
const r = inStage(st.id);
for (let i = 0; i < st.rooms.length; i++) {
const id = st.rooms[i];
assert.equal(r.spec.id, id);
const boss = Boolean(ghoul.roomById(id).boss);
if (i === st.rooms.length - 1) {
assert.ok(boss, `${st.id}: the last room is the boss room`);
assert.ok(ghoul.roomById(st.rooms[i - 1]).bonus, `${st.id}: the bonus ride comes right before the boss`);
}
if (!boss) {
assert.notEqual(r.phase, "bossintro", `${st.id}/${id}: no card here`);
assert.equal(r.phase, "ready", `${st.id}/${id}`);
assert.equal(r.events.some((e) => e.type === "bossIntro"), false);
r.events.length = 0;
through(r);
continue;
}
assert.equal(r.phase, "bossintro", `${st.id}: the boss room opens on its card`);
assert.deepEqual(r.events.filter((e) => e.type === "bossIntro").map((e) => [e.boss, e.stage]), [[st.boss, st.id]]);
assert.equal(r.events.some((e) => e.type === "room" && e.room === r.room), false, "the room's announcement waits for the card");
assert.ok(r.boss && r.boss.kind === st.boss, "the boss room is set up behind the card");
assert.equal(r.boss.state, "sleep");
// Nothing moves while the card is up.
const at = r.you.x;
r.input.right = true;
ghoul.advance(r, 600, steady);
assert.equal(r.you.x, at);
assert.equal(r.phase, "bossintro");
r.input.right = false;
// The lockout, then a press.
ghoul.advance(r, ghoul.INTRO_MIN_MS - 650, steady);
assert.equal(ghoul.takeIntro(r), false, "not before the lockout");
ghoul.advance(r, 100, steady);
r.events.length = 0;
assert.equal(ghoul.takeIntro(r), true);
assert.equal(r.phase, "ready");
assert.equal(r.phaseMs, ghoul.READY_MS);
assert.equal(r.events.filter((e) => e.type === "room").length, 1, "the boss room is announced now");
assert.equal(ghoul.takeIntro(r), false, "taken once");
ghoul.advance(r, ghoul.READY_MS + 20, steady);
assert.equal(r.phase, "play");
}
}
});
test("Ghoul Rush boss intros: the last room's door shows the card, a retry inside the boss room never does", () => {
const r = inStage("manor");
while (!ghoul.roomById(r.spec.id).boss) through(r);
assert.equal(r.phase, "bossintro");
skipBossIntro(ghoul, r);
ghoul.advance(r, ghoul.READY_MS + 20, steady);
assert.equal(r.phase, "play");
r.lives = 9;
r.you.safeMs = 0;
for (let n = 0; n < 3; n++) {
r.events.length = 0;
ghoul.lose(r, "zombie");
for (let ms = 0; ms < ghoul.CRASH_MS + 400 && r.phase !== "ready" && r.phase !== "over"; ms += 16) {
ghoul.advance(r, 16, steady);
assert.notEqual(r.phase, "bossintro", "no card on a retry");
}
assert.equal(r.phase, "ready", `retry ${n + 1} restarts the room`);
assert.equal(r.events.some((e) => e.type === "bossIntro"), false, "no card event on a retry");
ghoul.advance(r, ghoul.READY_MS + 20, steady);
r.you.safeMs = 0;
}
});
test("Ghoul Rush boss intros: the stage select shows the card for a boss room only, like the stage's card on its first room", () => {
ghoul.STAGES.forEach((st, at) => {
const g = selectInto(at, st.rooms.length - 1);
assert.equal(g.round.phase, "bossintro", `${st.id}: straight into the boss room`);
assert.equal(g.round.stage, st.id);
const mid = selectInto(at, 2);
assert.equal(mid.round.phase, "ready", `${st.id}: a mid-stage room has no card`);
const bonus = selectInto(at, st.rooms.length - 2);
assert.equal(bonus.round.phase, "ready", `${st.id}: the bonus ride has none`);
});
});
test("Ghoul Rush boss intros: with the window's keys, a held fire never skips it, a fresh press does after the lockout, a click works, and a pause holds it", () => {
const sounds = [];
const texts = [];
const g = selectInto(0, ghoul.STAGES[0].rooms.length - 1, texts, { tone: (name) => sounds.push(name) });
assert.equal(g.round.phase, "bossintro");
for (let k = 0; k < 5; k++) g.key("action", true);
g.key("action");
assert.equal(g.round.phase, "bossintro", "too soon, and repeats never count");
assert.equal(g.round.input.fire, false, "no shot fired at the card");
g.tick(16);
assert.ok(sounds.includes("ghoulBossIntro"), "the sting plays when the card opens");
for (let ms = 0; ms < 3000; ms += 16) g.tick(16);
texts.length = 0;
g.tick(16);
const info = bossIntroFor(ghoul.STAGES[0].boss);
assert.ok(texts.includes(BOSS_HINT), "the hint shows");
assert.match(BOSS_HINT, /any move key or fire to start the fight/);
assert.ok(BOSS_TITLE.split("").every((ch) => ch === " " || texts.includes(ch)), "every letter of BOSS FIGHT is drawn");
assert.ok(texts.includes(info.name.toUpperCase()), "the boss's name is drawn");
assert.ok(texts.includes(info.epithet), "the epithet is drawn");
g.pause();
const held = g.round.introMs;
for (let k = 0; k < 20; k++) g.tick(16);
assert.equal(g.round.introMs, held, "a pause holds the card");
texts.length = 0;
g.tick(16);
g.resume();
g.key("action", true);
assert.equal(g.round.phase, "bossintro", "a repeat still does nothing");
g.release("action");
g.key("action");
assert.equal(g.round.phase, "ready", "a fresh press starts the fight");
assert.equal(g.round.input.fire, false);
// Each of the other keys, and a click.
for (const name of ["left", "right", "up", "down", "action"]) {
const k = selectInto(3, ghoul.STAGES[3].rooms.length - 1);
k.key(name);
assert.equal(k.round.phase, "bossintro", `${name}: an early press is ignored`);
for (let ms = 0; ms < ghoul.INTRO_MIN_MS + 100; ms += 16) k.tick(16);
k.key(name, true);
assert.equal(k.round.phase, "bossintro", `${name}: a repeat is ignored`);
k.release(name);
k.key(name);
assert.equal(k.round.phase, "ready", `${name}: a fresh press moves on`);
assert.equal(k.round.input.fire, false, "no shot fired at the card");
}
const h = selectInto(5, ghoul.STAGES[5].rooms.length - 1);
h.pointer("down", 10, 10);
assert.equal(h.round.phase, "bossintro", "a click before the lockout is ignored");
for (let ms = 0; ms < 1300; ms += 16) h.tick(16);
h.pointer("down", 10, 10);
assert.equal(h.round.phase, "ready", "a click moves on");
});
test("Ghoul Rush boss intros: it never moves on by itself, not after a minute and not after an hour", () => {
const q = inStage("manor");
while (!ghoul.roomById(q.spec.id).boss) through(q);
assert.equal(q.phase, "bossintro");
for (const ms of [15000, 60000, 3600000]) {
ghoul.advance(q, ms, steady);
assert.equal(q.phase, "bossintro", `still waiting after ${ms} ms more`);
}
assert.equal(q.boss.state, "sleep", "the boss has not woken");
assert.equal(ghoul.takeIntro(q), true, "a press still works after any wait");
const g = selectInto(2, ghoul.STAGES[2].rooms.length - 1);
for (let ms = 0; ms < 120000; ms += 100) g.tick(100);
assert.equal(g.round.phase, "bossintro");
});
test("Ghoul Rush boss intros: the card draws for every boss at many moments, through that boss's own art", () => {
const sizes = { W: 96, H: 54 };
for (const room of bossRooms) {
const id = room.boss;
const st = ghoul.STAGES.find((s) => s.boss === id);
const calls = [];
const BOSS_ART = new Proxy({}, { get: (t, k) => (k === id ? (ctx, pic, b) => calls.push([pic, b]) : undefined) });
const texts = [];
const ctx = fakeCtx(texts);
const draw = bossIntroArt({ label: (c, text) => c.fillText(text), circle: () => {}, BOSS_ART, drawGourdFire: () => {}, GOLD: "#fc0", BONE: "#eee" });
const v = { g: { FIELD_W: sizes.W, FIELD_H: sizes.H }, round: { spec: { boss: id }, stage: st ? st.id : null, introMs: 0 }, bosses: ghoul.BOSSES };
for (let t = 0; t <= 6000; t += 37) {
v.round.introMs = t;
draw(ctx, v);
}
assert.ok(calls.length > 50, `${id}: the boss's art was called`);
assert.ok(calls.every(([pic, b]) => b.kind === id && b.w === ghoul.BOSSES[id].w && b.h === ghoul.BOSSES[id].h), `${id}: drawn as itself`);
assert.ok(texts.includes(bossIntroFor(id).name.toUpperCase()), `${id}: the name`);
assert.ok(texts.includes(bossIntroFor(id).epithet), `${id}: the epithet`);
// The same through the game's own drawing, with the real art.
const g2texts = [];
const g = selectInto(ghoul.STAGES.findIndex((s) => s.boss === id), ghoul.STAGES.find((s) => s.boss === id).rooms.length - 1, g2texts);
assert.equal(g.round.phase, "bossintro", id);
for (let ms = 0; ms < 5000; ms += 80) {
g.round.introMs = ms;
g.tick(1);
}
assert.ok(g2texts.includes(bossIntroFor(id).name.toUpperCase()), `${id}: the game draws the card`);
}
});
test("Ghoul Rush boss intros: a boss whose art throws or is missing still gets its card, with a silhouette and its name", () => {
const v = { g: { FIELD_W: 96, FIELD_H: 54 }, round: { spec: { boss: "bones" }, stage: "wing", introMs: 3000 }, bosses: ghoul.BOSSES };
for (const BOSS_ART of [{ bones: () => { throw new Error("broken art"); } }, {}, { bones: "not a function" }]) {
const texts = [];
let shapes = 0;
const ctx = new Proxy({}, {
get: (t, name) => (name in t ? t[name] : name === "fillText" ? (s) => texts.push(s) : name === "ellipse" ? () => shapes++ : () => {}),
set: (t, name, value) => ((t[name] = value), true),
});
const draw = bossIntroArt({ label: (c, text) => c.fillText(text), circle: () => {}, BOSS_ART, drawGourdFire: () => {}, GOLD: "#fc0", BONE: "#eee" });
assert.doesNotThrow(() => draw(ctx, v));
assert.ok(shapes > 0, "a silhouette is drawn");
assert.ok(texts.includes("OLD RATTLEBONES"));
}
// A card for a room that holds no boss (or one with no entry) draws nothing and does not throw.
const draw = bossIntroArt({ label: () => {}, circle: () => {}, BOSS_ART: {}, drawGourdFire: () => {}, GOLD: "#fc0", BONE: "#eee" });
assert.doesNotThrow(() => draw(fakeCtx([]), { g: { FIELD_W: 96, FIELD_H: 54 }, round: { spec: { boss: null }, introMs: 10 }, bosses: ghoul.BOSSES }));
assert.doesNotThrow(() => draw(fakeCtx([]), { g: { FIELD_W: 96, FIELD_H: 54 }, round: { spec: { boss: "newfiend" }, introMs: 10 }, bosses: ghoul.BOSSES }));
});
test("Ghoul Rush boss intros: the letters land one after another, each jolting the card, and the heartbeat thumps twice a second apart", () => {
const lands = [...BOSS_TITLE].map((ch, i) => (ch === " " ? null : landAt(i))).filter((x) => x !== null);
assert.deepEqual(lands, [...lands].sort((a, b) => a - b));
assert.ok(lands.at(-1) < 1800, "the title is in before the name");
assert.equal(shakeAt(0), 0);
assert.ok(shakeAt(lands[0] + 10) > 0.5, "a jolt on a landing");
assert.ok(shakeAt(lands[0] + 400) < shakeAt(lands[0] + 10), "which dies away");
assert.ok(beatAt(0) > 0.9 && beatAt(120) < beatAt(0) && beatAt(200) > beatAt(120), "a thump, then a softer one");
for (let t = 0; t < 5000; t += 17) assert.ok(beatAt(t) >= 0 && beatAt(t) <= 1.0001 && shakeAt(t) < 6);
});
@@ -157,7 +157,7 @@ test("Ghoul Rush's Midnight Carnival is a stage of three rooms, the dark ride (a
assert.equal(st.boss, "ringmaster");
assert.equal(st.title, "The Midnight Carnival");
assert.equal(st.sub, "Every game is rigged in its favor");
assert.equal(ghoul.STAGES.at(-2), st, "the last stage in the list but the Frozen Lake");
assert.equal(ghoul.STAGES.at(-3), st, "the last stage in the list but the Frozen Lake and Gallows Bog");
for (const kind of Object.keys(cv.MONSTERS)) assert.equal(ghoul.MONSTERS[kind], cv.MONSTERS[kind], `${kind} is a monster`);
assert.deepEqual(Object.keys(cv.MONSTERS).sort(), ["balloon", "circushound", "grinner", "marionette", "mirror", "strongman"]);
assert.equal(ghoul.BOSSES.ringmaster, cv.BOSSES.ringmaster);
@@ -2002,7 +2002,7 @@ test("Ghoul Rush's stage select lists the Carnival and takes you straight into e
const r = g.round;
assert.equal(r.phase, "select");
const at = ghoul.STAGES.findIndex((s) => s.id === "carnival");
assert.equal(at, ghoul.STAGES.length - 2);
assert.equal(at, ghoul.STAGES.length - 3);
for (let i = 0; i < at; i++) ghoul.steerSelect(r, 1, 0);
for (let i = 0; i < 4; i++) ghoul.steerSelect(r, 0, 1);
assert.equal(r.select.at, at);
@@ -3,6 +3,7 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import * as ghoul from "../src/web-console/public/activities/ghoul.js";
import { skipBossIntro } from "./ghoul-test-helpers.mjs";
import * as ct from "../src/web-console/public/activities/ghoul-cart.js";
import { EVENT_VOICE, LOSE_SOUNDS, LOSE_WORDS, LOOKS as CART_LOOKS, VOICES as CART_VOICES } from "../src/web-console/public/activities/ghoul-cart-draw.js";
import * as ghoulSfx from "../src/web-console/public/activities/ghoul-sfx.js";
@@ -1118,6 +1119,8 @@ test("Ghoul Rush's bonus round: the fifth lost heart ends it with no dice and no
assert.equal(round.cart, null);
assert.equal(round.lives, 3);
assert.equal(round.dice, 2);
assert.equal(round.phase, "bossintro", "the boss room opens on its card");
skipBossIntro(ghoul, round);
assert.equal(round.phase, "ready");
// A life lost there is a run life as always, and the dice roll for it.
round.phase = "play";
@@ -82,7 +82,7 @@ const heard = (e, extra = {}) => {
test("Ghoul Rush's Chapel is a stage of three rooms and the Choir's, its monsters and boss joined to the game's, with Holy Water and a place for each kind", () => {
const st = ghoul.stageById("chapel");
assert.deepEqual(st.rooms, ["nave", "tower", "loft", "choir"]);
assert.deepEqual(st.rooms, ["nave", "tower", "loft", "pew", "choir"], "the bonus ride (Holy Roller) sits before the Choir");
assert.equal(st.boss, "choirmaster");
assert.equal(st.title, "The Chapel");
assert.equal(st.sub, "Service is still in session");
@@ -90,7 +90,7 @@ test("Ghoul Rush's Chapel is a stage of three rooms and the Choir's, its monster
assert.equal(ghoul.BOSSES.choirmaster, ch.BOSSES.choirmaster);
assert.equal(ch.BOSSES.choirmaster.sub, "Silence the pipes one by one");
for (const id of st.rooms) assert.ok(ghoul.ROOM_MUSIC[id], `${id} has music`);
const [nave, tower, loft, choir] = st.rooms.map((id) => ghoul.roomById(id));
const [nave, tower, loft, choir] = st.rooms.filter((id) => id !== "pew").map((id) => ghoul.roomById(id));
for (const room of [nave, tower, loft]) {
assert.ok(room.key, `${room.id}: a key`);
assert.ok(room.sky.length && room.candy.length && room.items.length && room.horde.length, `${room.id}: sky treasures, candy, items and a horde`);
@@ -785,7 +785,7 @@ test("Every column of notes can be passed: for each gap a surface in the arena (
test("Every column can be reached from the one before: the next gap is the same height or one step either side, over a long fight", () => {
const round = choirFight();
const gaps = [];
const rand = ghoul.seeded(11);
const rand = ghoul.seeded(2);
round.boss.act = "idle";
round.boss.wait = 0;
for (let t = 0; t < 70000; t += 4) {
@@ -832,7 +832,7 @@ test("A jump from the floor clears the third gap too, with a window of about a f
/* ----------------------------------------------------------- the rage */
test("The Choirmaster at half his hp: a rage that is told, silenced pipes sounding again one at a time every 6 s (guarding him again), faster notes, and now and then two columns close together", () => {
test("The Choirmaster at half his hp: a rage that is told, and no pipe comes back for it alone", () => {
const round = choirFight();
const b = round.boss;
b.pipes.forEach((p) => {
@@ -846,17 +846,202 @@ test("The Choirmaster at half his hp: a rage that is told, silenced pipes soundi
assert.equal(events(round, "choirRage").length, 1, "the rage is told");
assert.equal(b.raged, true);
assert.deepEqual(b.pipes.map((p) => p.on), [false, false, false, false], "none yet");
// One every 6 s, one at a time.
const sounds = log(round, ch.RESOUND_MS * 4 + 200, "pipeSound");
assert.equal(sounds.length, 4, "all four, one by one");
for (let i = 1; i < sounds.length; i++) assert.ok(Math.abs(sounds[i][0] - sounds[i - 1][0] - ch.RESOUND_MS) < 60, `${sounds[i][0] - sounds[i - 1][0]} apart`);
assert.equal(new Set(sounds.map((s) => s[1].pipe)).size, 4, "a different pipe each time");
assert.ok(b.pipes.every((p) => p.on && p.hp === p.max), "each at full hp");
// While any sounds, he is guarded again.
// He is held to no columns, so the pipes stay down however long it takes.
run(round, 30000);
assert.equal(events(round, "pipeSound").length, 0);
assert.ok(b.pipes.every((p) => !p.on));
});
/* ------------------------------------------- the pipes drop back in */
// A fight with all four pipes shot silent, his next cue due now.
function openFight() {
const round = choirFight();
const b = round.boss;
until(round, () => b.x === round.spec.length - ch.HOME_FROM_END, 4000);
hold(round);
for (const p of b.pipes) {
p.hp = 1;
round.shots.push({ x: p.x - 3, y: p.y + 4, vx: 80, vy: 0, gone: 0 });
run(round, 60);
}
assert.ok(b.pipes.every((p) => !p.on));
Object.assign(b, { act: "idle", wait: 0 });
round.events.length = 0;
return round;
}
// Runs a fight until `n` columns are away, you kept safe and the bell off.
function columns(round, n, random = steady) {
const flownSoFar = () => events(round, "notes").filter((e) => !e.pair).length;
const want = flownSoFar() + n;
for (let t = 0; t < 60000 && (flownSoFar() < want || round.boss.act !== "idle"); t += 4) {
ghoul.advance(round, 4, random);
round.you.safeMs = 1e9;
round.twist.next = 1e9;
round.monsters.length = 0;
}
}
test("The Choirmaster's pipes drop back in: with all four silent he stays open for four columns, warns on the third, and the fourth brings all of them back at full hp", () => {
const round = openFight();
const b = round.boss;
assert.equal(ch.PIPES_BACK, 4);
columns(round, 2);
assert.ok(b.pipes.every((p) => !p.on), "still open after two");
assert.equal(events(round, "pipesStir").length, 0);
columns(round, 1);
assert.ok(b.pipes.every((p) => !p.on), "still open after three");
assert.equal(b.quiet, 1, "one column left");
assert.equal(events(round, "pipesStir").length, 1, "and it warns you");
const hp = b.hp;
round.shots.push({ x: b.x - b.w / 2 - 0.2, y: b.y + 5, vx: 80, vy: 0, gone: 0 });
run(round, 20);
assert.equal(b.hp, hp);
ghoul.advance(round, 4, steady);
assert.equal(b.hp, hp - 1, "and still to be hurt");
columns(round, 1);
assert.ok(b.pipes.every((p) => p.on && p.hp === p.max), "all four, at full hp");
assert.ok(b.pipes.every((p) => p.dropMs > 0), "falling");
// Guarded from the moment they start to fall.
const now = b.hp;
round.shots.push({ x: b.x - b.w / 2 - 0.2, y: b.y + 5, vx: 80, vy: 0, gone: 0 });
ghoul.advance(round, 4, steady);
assert.equal(b.hp, now, "guarded again");
});
test("A falling pipe cannot be shot and spews nothing; each lands in turn with its sound, and then has to be silenced all over again, which starts the count anew", () => {
const round = openFight();
const b = round.boss;
columns(round, ch.PIPES_BACK);
const [first, , , last] = b.pipes;
assert.equal(last.dropMs - first.dropMs, 3 * ch.PIPE_DROP_STAGGER_MS, "one after another");
hold(round);
// A bolt passes through a pipe still in the air.
round.events.length = 0;
round.shots.push({ x: first.x - 3, y: first.y + 4, vx: 80, vy: 0, gone: 0 });
run(round, 60);
assert.equal(first.hp, first.max);
assert.equal(events(round, "pipeHit").length, 0);
assert.equal(events(round, "pipeSpew").length, 0);
// They land one at a time.
const lands = log(round, ch.PIPE_DROP_MS + 4 * ch.PIPE_DROP_STAGGER_MS, "pipeSound");
assert.deepEqual(lands.map(([, e]) => e.pipe), [0, 1, 2, 3]);
assert.ok(b.pipes.every((p) => !(p.dropMs > 0)));
// Landed: shots count again, and silencing all four opens him and starts over.
for (const p of b.pipes) {
p.hp = 1;
p.spewIn = 1e9;
round.shots.push({ x: p.x - 3, y: p.y + 4, vx: 80, vy: 0, gone: 0 });
run(round, 60);
}
assert.ok(b.pipes.every((p) => !p.on), "silenced again");
assert.ok(events(round, "choirOpen").length >= 1);
run(round, 8);
assert.equal(b.quiet, ch.PIPES_BACK, "the count starts over");
});
test("The pipes only come back once all four are silent: columns flown with one still sounding count for nothing, and the rage changes none of it", () => {
const round = choirFight();
const b = round.boss;
b.pipes.forEach((p, i) => (p.on = i === 0));
Object.assign(b, { act: "idle", wait: 0 });
columns(round, ch.PIPES_BACK + 2);
assert.deepEqual(b.pipes.map((p) => p.on), [true, false, false, false]);
assert.equal(b.quiet, null);
const mad = openFight();
mad.boss.hp = mad.boss.max * 0.4;
columns(mad, ch.PIPES_BACK - 1, ghoul.seeded(3));
assert.ok(mad.boss.pipes.every((p) => !p.on), "not yet");
columns(mad, 1, ghoul.seeded(4));
assert.ok(mad.boss.pipes.every((p) => p.on), "back in the rage too");
});
/* --------------------------------------- each column at its own speed */
// A long fight from a seed, every column as { at, v, pair, end }: `end` when it
// reaches the arena's far end. Bolts, ghosts and the bell kept out of it.
function flown(seed, raged) {
const round = choirFight();
const b = round.boss;
until(round, () => b.x === round.spec.length - ch.HOME_FROM_END, 4000);
hold(round);
if (raged) {
b.hp = b.max * 0.4;
b.raged = true;
}
Object.assign(b, { act: "idle", wait: 0, gap: 1 });
const random = ghoul.seeded(seed);
const end = round.spec.arena - 6;
const got = [];
for (let t = 0; t < 120000; t += 4) {
ghoul.advance(round, 4, random);
round.you.safeMs = 1e9;
round.twist.next = 1e9;
b.pipes.forEach((p) => (p.spewIn = 1e9));
round.monsters.length = 0;
for (const e of round.events) if (e.type === "notes") got.push({ at: round.clock, v: e.v, pair: e.pair, gap: e.gap, end: round.clock + ((e.x - end) / e.v) * 1000 });
round.events.length = 0;
}
return { round, got };
}
test("Every column of notes flies at its own speed: the whole column together, some far faster than usual and some far slower, in no fixed order", () => {
const { got } = flown(7, false);
assert.ok(got.length >= 25, `${got.length} columns`);
const vs = got.map((c) => c.v);
assert.ok(Math.min(...vs) <= ch.NOTE_V * 0.6, `some slow (${Math.min(...vs).toFixed(1)})`);
assert.ok(Math.max(...vs) >= ch.NOTE_V * 1.3, `some fast (${Math.max(...vs).toFixed(1)})`);
assert.ok(new Set(vs.map((v) => v.toFixed(1))).size >= 5, "many speeds");
// One launch: every note in it alike, with the edge the art draws from.
const round = choirFight();
Object.assign(round.boss, { act: "idle", wait: 0 });
run(round, ch.CUE_MS + 20);
const notes = round.hazards.filter((h) => h.kind === "note");
assert.equal(notes.length, 4);
assert.equal(new Set(notes.map((n) => n.v)).size, 1, "a column flies together");
assert.ok(notes.every((n) => n.pace === 1), "the middle draw is the usual speed");
// Different draws, different speeds: the table's ends are real.
for (const [draw, pace] of [[0, ch.NOTE_PACE[0]], [0.999, ch.NOTE_PACE.at(-1)]]) {
const r = choirFight();
Object.assign(r.boss, { act: "cue", wait: 0, gap: 1, second: null });
ghoul.advance(r, 4, () => draw);
const n = r.hazards.find((h) => h.kind === "note");
assert.ok(Math.abs(n.v - ch.NOTE_V * pace) < 1e-9, `draw ${draw}`);
}
});
test("No column ever catches the one ahead: wherever you stand you get time between two gaps, a pair keeps its spacing, and even the slowest crosses the arena", () => {
for (const raged of [false, true]) {
for (const seed of [1, 2, 3, 4]) {
const { got } = flown(seed, raged);
assert.ok(got.length >= 20);
for (let i = 1; i < got.length; i++) {
const gap = got[i].end - got[i - 1].end;
const least = got[i].pair ? ch.PAIR_MS : ch.NOTE_SEP_MS;
assert.ok(gap >= least - 20, `seed ${seed}, column ${i}: ${gap.toFixed(0)} ms behind at the far end`);
// Launched later and arriving later, so it is behind at every spot between.
assert.ok(got[i].at > got[i - 1].at);
}
if (raged) assert.ok(got.some((c) => c.pair), "pairs in the rage");
for (let i = 1; i < got.length; i++) if (got[i].pair) assert.equal(got[i].v, got[i - 1].v, "a pair flies as one");
}
}
// The slowest note lives long enough to leave by the far end.
const round = choirFight();
const b = round.boss;
until(round, () => b.x === round.spec.length - ch.HOME_FROM_END, 4000);
hold(round);
Object.assign(b, { act: "cue", wait: 0, gap: 1, second: null });
ghoul.advance(round, 4, () => 0);
hold(round);
const note = round.hazards.find((h) => h.kind === "note");
let lowest = note.x;
for (let t = 0; t < 12000 && round.hazards.includes(note); t += 4) {
ghoul.advance(round, 4, steady);
round.you.safeMs = 1e9;
round.twist.next = 1e9;
lowest = Math.min(lowest, note.x);
}
assert.ok(lowest <= round.spec.arena - 5.5, `reached ${lowest.toFixed(1)}`);
});
test("The Choirmaster in his rage conducts faster: notes at NOTE_V_RAGE, a column every 2.3 s, and sometimes a second column 1.1 s behind the first, its gap next to the first's", () => {
@@ -865,7 +1050,6 @@ test("The Choirmaster in his rage conducts faster: notes at NOTE_V_RAGE, a colum
b.pipes.forEach((p) => (p.on = false));
b.hp = b.max * 0.5 - 1;
b.raged = true;
b.resoundIn = 1e9;
const random = ghoul.seeded(5);
Object.assign(b, { act: "idle", wait: 0, gap: 1 });
const pairs = [];
@@ -894,9 +1078,13 @@ test("The Choirmaster in his rage conducts faster: notes at NOTE_V_RAGE, a colum
spaced++;
}
assert.ok(spaced >= 5);
// Faster notes.
assert.equal(speed, ch.NOTE_V_RAGE * round.spec.pace);
// Faster notes: the same draw flies faster in the rage.
assert.ok(speed > 0);
assert.ok(ch.NOTE_V_RAGE > ch.NOTE_V && ch.COLUMN_RAGE_MS < ch.COLUMN_MS);
const mad = choirFight();
Object.assign(mad.boss, { hp: mad.boss.max * 0.4, raged: true, act: "cue", wait: 0, gap: 1, second: null });
ghoul.advance(mad, 4, steady);
assert.equal(mad.hazards.find((h) => h.kind === "note").v, ch.NOTE_V_RAGE * mad.spec.pace);
// Without the rage, the same draws give no pairs.
const calm = choirFight();
Object.assign(calm.boss, { act: "idle", wait: 0, gap: 1 });
@@ -1039,6 +1227,7 @@ test("Ghoul Rush's Chapel: every new kind has a voice for every act and every ne
// Every new event says something (a float, a banner or a sound).
assert.deepEqual(heard({ type: "toll", ms: 1000 }).floats, ["Frozen!"]);
assert.deepEqual(heard({ type: "pipeSilence", kind: "choirmaster", left: 0 }).floats, ["Silent!"]);
assert.deepEqual(heard({ type: "pipesStir", kind: "choirmaster" }).floats, ["The pipes stir!"]);
});
test("Ghoul Rush's Chapel: every new way to die has its words and its own sound", () => {
@@ -1088,6 +1277,14 @@ test("Ghoul Rush's Chapel draws: every room, every monster in every act, the Cho
r.stunMs = 500;
g.tick(16);
r.stunMs = 0;
// The pipes rattling, then falling back in; notes of every speed.
if (r.boss.pipes) {
Object.assign(r.boss, { act: "idle", wait: 1e9, quiet: 1 });
g.tick(16);
r.boss.pipes.forEach((p, i) => Object.assign(p, { on: true, dropMs: 300 + i * 100 }));
r.hazards.push({ kind: "note", x: r.you.x + 24, y: 10, w: 1.6, h: 1.6, v: 0, pace: 1.75, live: 1, life: 5000, row: 1, cause: "note" }, { kind: "note", x: r.you.x + 28, y: 10, w: 1.6, h: 1.6, v: 0, pace: 0.55, live: 1, life: 5000, row: 1, cause: "note" });
g.tick(16);
}
}
for (let k = 0; k < 20; k++) g.tick(16);
r.you.safeMs = 1e9;
@@ -164,18 +164,22 @@ test("Ghoul Rush: a death with dice holds and rolls just one; a six saves Planny
assert.equal(round.lives, 3, "no life lost yet");
assert.equal(round.dice, 2, "the die is in hand");
assert.equal(events(round, "diceStart").length, 1);
assert.equal(events(round, "diceRoll").length, 1);
assert.equal(events(round, "diceRoll").length, 0, "the die is still flying in from the HUD");
assert.equal(events(round, "lose").length, 0, "not lost");
const random = rolls(SIX);
// The lead-in: the die flies in, then the rattle starts.
ghoul.advance(round, ghoul.LEAD_MS + 8, random);
assert.equal(events(round, "diceRoll").length, 1);
assert.equal(events(round, "diceFace").length, 0);
// Half way through: tumbling, no face yet.
ghoul.advance(round, ghoul.TUMBLE_MS / 2, random);
ghoul.advance(round, (ghoul.TUMBLE_MS - ghoul.LEAD_MS) / 2, random);
assert.equal(round.phase, "roll");
assert.equal(events(round, "diceFace").length, 0);
// It lands, and holds its beat.
ghoul.advance(round, ghoul.TUMBLE_MS / 2 + 8, random);
ghoul.advance(round, (ghoul.TUMBLE_MS - ghoul.LEAD_MS) / 2, random);
assert.deepEqual(events(round, "diceFace").map((e) => e.face), [6]);
assert.equal(round.phase, "roll");
ghoul.advance(round, ghoul.ROLL_MS - ghoul.TUMBLE_MS, random);
ghoul.advance(round, ghoul.ROLL_MS - ghoul.TUMBLE_MS + 8, random);
assert.equal(events(round, "diceRoll").length, 1, "no second die");
assert.equal(events(round, "diceSaved").length, 1);
assert.equal(events(round, "diceFail").length, 0);
@@ -125,7 +125,7 @@ test("Ghoul Rush's Frozen Lake is a stage of three rooms and the Widow's Web, it
assert.equal(st.boss, "frostwidow");
assert.equal(st.title, "The Frozen Lake");
assert.equal(st.sub, "The ice remembers who fell through");
assert.equal(ghoul.STAGES.at(-1), st, "the last stage in the list");
assert.equal(ghoul.STAGES.at(-2), st, "the last stage in the list but Gallows Bog");
for (const kind of Object.keys(fz.MONSTERS)) assert.equal(ghoul.MONSTERS[kind], fz.MONSTERS[kind], `${kind} is a monster`);
assert.deepEqual(Object.keys(fz.MONSTERS).sort(), ["frozen", "hand", "icewraith", "shade"]);
assert.equal(ghoul.BOSSES.frostwidow, fz.BOSSES.frostwidow);
@@ -848,6 +848,13 @@ test("Ghoul Rush's barrels: a bolt kicks a standing one the way it flew, it roll
const round = widowFight({ x: 120 });
const barrel = round.hazards.find((h) => h.kind === "barrel" && h.x === round.spec.arena + 30);
// From the left: it rolls right.
// A stray bolt does not topple it: it takes BARREL_HITS of them.
for (let i = 0; i < fz.BARREL_HITS - 1; i++) {
round.shots.push({ x: barrel.x - 4, y: 7.5, vx: 130, vy: 0, gone: 0 });
run(round, 60);
assert.equal(barrel.state, "still", `bolt ${i + 1} only knocks it`);
}
assert.equal(events(round, "barrelKnock").length, fz.BARREL_HITS - 1);
round.shots.push({ x: barrel.x - 4, y: 7.5, vx: 130, vy: 0, gone: 0 });
run(round, 60);
assert.equal(barrel.state, "roll");
@@ -860,14 +867,14 @@ test("Ghoul Rush's barrels: a bolt kicks a standing one the way it flew, it roll
// From the right: it rolls left.
const left = widowFight({ x: 190 });
const b2 = left.hazards.find((h) => h.kind === "barrel" && h.x === left.spec.arena + 66);
left.shots.push({ x: b2.x + 4, y: 7.5, vx: -130, vy: 0, gone: 0 });
left.shots.push({ x: b2.x + 4, y: 7.5, vx: -130, vy: 0, gone: 0, arm: "stake", t: 0, spin: 0, dmg: 4, bossDmg: 4, pierce: true });
run(left, 40);
assert.equal(b2.vx, -fz.BARREL_V);
// It hurts what it rolls through, once each.
const hit = widowFight({ x: 120 });
const b3 = hit.hazards.find((h) => h.kind === "barrel" && h.x === hit.spec.arena + 30);
const z = put(hit, "zombie", b3.x + 8);
hit.shots.push({ x: b3.x - 4, y: 7.5, vx: 130, vy: 0, gone: 0 });
Object.assign(b3, { state: "roll", vx: fz.BARREL_V, life: fz.BARREL_LIFE_MS });
run(hit, 600);
assert.equal(z.hp, z.max - fz.BARREL_DMG >= 0 ? z.max - fz.BARREL_DMG : z.hp);
assert.ok(z.dead || z.hp < z.max, "burned by the barrel");
@@ -875,7 +882,7 @@ test("Ghoul Rush's barrels: a bolt kicks a standing one the way it flew, it roll
const wall = widowFight({ x: 120 });
const b4 = wall.hazards.find((h) => h.kind === "barrel" && h.x === wall.spec.arena + 66);
wall.boss.x = 120;
wall.shots.push({ x: b4.x - 4, y: 7.5, vx: 130, vy: 0, gone: 0 });
wall.shots.push({ x: b4.x - 4, y: 7.5, vx: 130, vy: 0, gone: 0, arm: "stake", t: 0, spin: 0, dmg: 4, bossDmg: 4, pierce: true });
run(wall, 1500);
assert.ok(!wall.hazards.includes(b4));
assert.ok(events(wall, "barrelBurst").length >= 1);
@@ -901,7 +908,7 @@ test("Ghoul Rush's veil melts to a rolling barrel (or a flare's fire) when she i
const barrel = round.hazards.find((h) => h.kind === "barrel" && h.x === round.spec.arena + 48);
// Shot from the left, 4 away from her: it rolls into her.
barrel.x = 150;
round.shots.push({ x: 146, y: 7.5, vx: 130, vy: 0, gone: 0 });
round.shots.push({ x: 146, y: 7.5, vx: 130, vy: 0, gone: 0, arm: "stake", t: 0, spin: 0, dmg: 4, bossDmg: 4, pierce: true });
until(round, () => !b.veil, 1500);
assert.equal(b.veil, false, "melted");
const melt = events(round, "veilMelt")[0];
@@ -1209,7 +1216,7 @@ test("Ghoul Rush's web spit: a slow glob that lands as a patch 5 wide for 6 s, s
assert.ok(!shot.hazards.some((h) => h.kind === "webGlob" || h.kind === "webPatch"), "shot down");
});
test("Ghoul Rush's Frost Widow's rage at half her hp: the veil grows back sooner, the barrels are set out new, two ice wraiths come (never more than two alive) and she is quicker; endless lives spare her touch", () => {
test("Ghoul Rush's Frost Widow's rage at half her hp: the veil grows back sooner, the barrels are set out new, an ice wraith comes (never more than WRAITH_CAP alive, and not again for a while) and she is quicker; endless lives spare her touch", () => {
const round = widowFight({ x: 125 });
const b = round.boss;
round.hazards = round.hazards.filter((h) => h.kind !== "barrel").concat([{ kind: "barrel", x: 140, y: 6, spot: 99, state: "roll", vx: 5, roll: 0, life: 9999, hit: [], w: 3, h: 3.4, live: 0, cause: "" }]);
@@ -1222,19 +1229,19 @@ test("Ghoul Rush's Frost Widow's rage at half her hp: the veil grows back sooner
assert.equal(barrels.length, 3, "a new set of three");
assert.ok(barrels.every((h) => h.state === "still"));
const wraiths = round.monsters.filter((m) => m.kind === "icewraith");
assert.equal(wraiths.length, 2);
assert.equal(events(round, "wraithCall").length, 2);
// Never more than two alive, a drop or not.
assert.equal(wraiths.length, fz.WRAITH_CAP);
assert.equal(events(round, "wraithCall").length, fz.WRAITH_CAP);
// Never more than the cap alive, a drop or not.
b.act = "hang";
b.wait = 1;
b.spikeIn = 1e9;
b.spitIn = 1e9;
run(round, 16);
assert.equal(round.monsters.filter((m) => m.kind === "icewraith").length, 2);
assert.equal(round.monsters.filter((m) => m.kind === "icewraith").length, fz.WRAITH_CAP);
// The veil grows back in VEIL_DOWN_RAGE_MS.
Object.assign(b, { act: "low", y: 6, x: 160, lowMs: 1e9, wait: 0 });
round.hazards.find((h) => h.kind === "barrel").x = 150;
round.shots.push({ x: 146, y: 7.5, vx: 130, vy: 0, gone: 0 });
round.shots.push({ x: 146, y: 7.5, vx: 130, vy: 0, gone: 0, arm: "stake", t: 0, spin: 0, dmg: 4, bossDmg: 4, pierce: true });
until(round, () => !b.veil, 1500);
assert.equal(events(round, "veilDown").at(-1).ms, fz.VEIL_DOWN_RAGE_MS);
// Quicker waits: a fight at half hp has shorter hangs.
@@ -1472,7 +1479,7 @@ test("Ghoul Rush's stage select lists the Frozen Lake and takes you straight int
const r = g.round;
assert.equal(r.phase, "select");
const at = ghoul.STAGES.findIndex((s) => s.id === "frozen");
assert.equal(at, ghoul.STAGES.length - 1);
assert.equal(at, ghoul.STAGES.length - 2);
for (let i = 0; i < at; i++) ghoul.steerSelect(r, 1, 0);
for (let i = 0; i < 4; i++) ghoul.steerSelect(r, 0, 1);
assert.equal(r.select.at, at);
@@ -2,6 +2,7 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import * as ghoul from "../src/web-console/public/activities/ghoul.js";
import { skipStory } from "../src/web-console/public/activities/ghoul-story.js";
import { dropAt, gameOverBanner, OVER_WORD } from "../src/web-console/public/activities/ghoul-gameover-draw.js";
import { toneNames } from "../src/web-console/public/tones.js";
@@ -35,6 +36,7 @@ function playTo(end) {
const h = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx }, tone: (name) => sounds.push(name) });
h.resize(900, 900);
h.key("action");
skipStory(h.round);
for (let k = 0; k < 40; k++) h.tick(16);
end(h);
for (let k = 0; k < 300 && h.state === "running"; k++) h.tick(16);
@@ -45,9 +45,9 @@ function run(round, ms, keys = {}) {
for (const k of Object.keys(keys)) round.input[k] = false;
}
test("Ghoul Rush's Graveyard is a stage of three rooms and Mother Mourning's, its monsters and boss joined to the game's", () => {
test("Ghoul Rush's Graveyard is a stage of three rooms, the Midnight Hearse bonus ride (its own suite: ghoul-hearse) and Mother Mourning's, its monsters and boss joined to the game's", () => {
const st = ghoul.stageById("graveyard");
assert.deepEqual(st.rooms, ["lychgate", "graves", "mausoleums", "angel"]);
assert.deepEqual(st.rooms, ["lychgate", "graves", "mausoleums", "hearse", "angel"]);
assert.equal(st.boss, "angel");
for (const kind of Object.keys(gy.MONSTERS)) assert.equal(ghoul.MONSTERS[kind], gy.MONSTERS[kind], `${kind} is a monster`);
assert.equal(ghoul.BOSSES.angel, gy.BOSSES.angel);
@@ -61,14 +61,17 @@ function until(round, done, ms = 4000) {
// A bolt arriving from the left at height `y` on the monster `m`.
const bolt = (round, m, y) => round.shots.push({ x: m.x - m.w / 2 - 0.3, y, vx: 80, vy: 0, gone: 0 });
test("Ghoul Rush's Grounds is a stage of three rooms and the Groundskeeper's, its monsters and boss joined to the game's, with shears and a place for each kind", () => {
test("Ghoul Rush's Grounds is a stage of three rooms, a bonus ride and the Groundskeeper's, its monsters and boss joined to the game's, with shears and a place for each kind", () => {
const st = ghoul.stageById("grounds");
assert.deepEqual(st.rooms, ["maze", "topiary", "gazebo", "yard"]);
assert.deepEqual(st.rooms, ["maze", "topiary", "gazebo", "mower", "yard"]);
assert.equal(st.boss, "keeper");
for (const kind of Object.keys(gr.MONSTERS)) assert.equal(ghoul.MONSTERS[kind], gr.MONSTERS[kind], `${kind} is a monster`);
assert.equal(ghoul.BOSSES.keeper, gr.BOSSES.keeper);
for (const id of st.rooms) assert.ok(ghoul.ROOM_MUSIC[id], `${id} has music`);
const [maze, garden, gazebo, yard] = st.rooms.map((id) => ghoul.roomById(id));
const [maze, garden, gazebo, mower, yard] = st.rooms.map((id) => ghoul.roomById(id));
// The Gardener's Revenge, the bonus ride before the boss, has its own suite (ghoul-mower).
assert.equal(mower.bonus, true);
assert.equal(mower.id, "mower");
for (const room of [maze, garden, gazebo]) {
assert.ok(room.key, `${room.id}: a key`);
assert.ok(room.sky.length && room.candy.length && room.items.length && room.horde.length, `${room.id}: sky treasures, candy, items and a horde`);
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,226 @@
// Web console tests, Ghoul Rush's stage intro cards: every stage has one (3 or 4 lines, short, no em dash, never the hero's name), the card shows when a stage is entered and not before the pick, any move key or fire moves it on after the minimum (repeats and early presses never do) and it never moves on by itself, and it draws on a fake canvas.
import { test } from "node:test";
import assert from "node:assert/strict";
import * as ghoul from "../src/web-console/public/activities/ghoul.js";
import { INTROS, MAX_LINE, introFor } from "../src/web-console/public/activities/ghoul-intros.js";
import { INTRO_HINT, LINE_SIZE, TITLE_SIZE, dropAt, titleLayout } from "../src/web-console/public/activities/ghoul-intro-draw.js";
import { toneNames } from "../src/web-console/public/tones.js";
const steady = () => 0.5;
const DASH = String.fromCharCode(0x2014);
function fakeCtx(texts) {
return new Proxy({}, {
get: (t, name) => (name in t ? t[name] : name === "fillText" ? (s) => texts.push(s) : () => {}),
set: (t, name, value) => ((t[name] = value), true),
});
}
// A round at the stage pick, the offer settled.
function atPick(seed = 3) {
const r = ghoul.newRound(seed);
r.dice = 0;
r.phase = "clear";
r.phaseMs = 1;
ghoul.advance(r, 4, steady);
ghoul.advance(r, ghoul.PICK_HOLD_MS, steady);
return r;
}
test("Ghoul Rush intros: every stage has a card of 3 or 4 short lines, no em dash, YOU and never Planny", () => {
const field = ghoul.FIELD_W;
for (const st of ghoul.STAGES) {
const info = introFor(st.id);
assert.ok(info, `${st.id} has an intro`);
assert.ok(info.title && info.kicker && info.boss, `${st.id} has a title, a kicker and a boss`);
assert.ok(info.lines.length >= 3 && info.lines.length <= 4, `${st.id} has 3 or 4 lines`);
assert.ok(/^#[0-9a-f]{6}$/i.test(info.palette.a) && /^#[0-9a-f]{6}$/i.test(info.palette.b) && /^#[0-9a-f]{6}$/i.test(info.palette.glow), `${st.id} has a palette`);
assert.equal(info.title, st.title, `${st.id} keeps the stage's title`);
assert.equal(info.kicker, st.sub, `${st.id} keeps the stage's tagline`);
assert.equal(info.boss, ghoul.BOSSES[st.boss].name, `${st.id} names its boss`);
const text = [info.title, info.kicker, info.boss, ...info.lines].join("\n");
assert.ok(!text.includes(DASH), `${st.id} has no em dash`);
assert.ok(!/planny|the player/i.test(text), `${st.id} never names the hero`);
assert.ok(info.lines.some((l) => l.includes("YOU")), `${st.id} speaks to YOU`);
for (const line of info.lines) {
assert.ok(line.length <= MAX_LINE, `${st.id}: "${line}" is ${line.length} characters`);
// The same width guess the field's label helper uses (0.62 em a letter).
assert.ok(line.length * LINE_SIZE * 0.62 <= field - 1, `${st.id}: "${line}" fits the field`);
}
const { size, xs } = titleLayout(info.title);
assert.ok(size > 0 && size <= TITLE_SIZE, `${st.id}'s title has a size`);
assert.ok(Math.abs(xs[0]) < field / 2 && Math.abs(xs[xs.length - 1]) < field / 2, `${st.id}'s title fits the field`);
}
assert.deepEqual(Object.keys(INTROS).sort(), ghoul.STAGES.map((st) => st.id).sort(), "no intro for a stage that does not exist");
assert.equal(new Set(ghoul.STAGES.flatMap((st) => introFor(st.id).lines)).size, ghoul.STAGES.reduce((n, st) => n + introFor(st.id).lines.length, 0), "no line used twice");
assert.ok(toneNames().includes("ghoulStageIntro"));
});
test("Ghoul Rush intros: the card shows when a stage is entered and not before the pick, and holds the room back", () => {
const r = ghoul.newRound(3);
assert.equal(r.phase, "play", "the hall has no card");
const p = atPick();
assert.equal(p.phase, "pick");
assert.equal(p.events.some((e) => e.type === "intro"), false, "no card before the pick");
const want = p.offer[p.pick];
p.events.length = 0;
assert.equal(ghoul.pickStage(p), true);
assert.equal(p.phase, "intro");
assert.deepEqual(p.events.filter((e) => e.type === "intro").map((e) => e.stage), [want]);
assert.equal(p.events.some((e) => e.type === "room"), false, "the room's announcement waits for the card");
assert.equal(p.spec.id, ghoul.stageById(want).rooms[0], "the first room is set up behind it");
// Nothing in the room moves while the card is up.
const at = p.you.x;
p.input.right = true;
ghoul.advance(p, 600, steady);
assert.equal(p.you.x, at);
assert.equal(p.phase, "intro");
});
test("Ghoul Rush intros: fire, jump or a click moves on after the minimum, and nothing moves it on alone", () => {
const p = atPick();
ghoul.pickStage(p);
assert.equal(ghoul.takeIntro(p), false, "not at once");
ghoul.advance(p, ghoul.INTRO_MIN_MS - 50, steady);
assert.equal(ghoul.takeIntro(p), false, "not before the minimum");
assert.equal(p.phase, "intro");
ghoul.advance(p, 60, steady);
p.events.length = 0;
assert.equal(ghoul.takeIntro(p), true);
assert.equal(p.phase, "ready");
assert.equal(p.phaseMs, ghoul.READY_MS);
assert.equal(p.events.filter((e) => e.type === "room").length, 1, "the room is announced now");
ghoul.advance(p, ghoul.READY_MS + 20, steady);
assert.equal(p.phase, "play");
// It never advances on its own: not after a minute, not after an hour.
const q = atPick(5);
ghoul.pickStage(q);
for (const ms of [15000, 60000, 3600000]) {
ghoul.advance(q, ms, steady);
assert.equal(q.phase, "intro", `still waiting after ${ms} ms more`);
}
assert.equal(ghoul.INTRO_MAX_MS, undefined, "the auto-advance timeout is gone");
assert.ok(ghoul.INTRO_MIN_MS >= 1000 && ghoul.INTRO_MIN_MS <= 2000);
assert.equal(ghoul.takeIntro(q), true, "a press still works after any wait");
});
test("Ghoul Rush intros: with the window's keys, a held fire never skips it, a fresh press does, and a pause holds it", () => {
const texts = [];
const sounds = [];
const ctx = fakeCtx(texts);
const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx }, tone: (name) => sounds.push(name) });
g.resize(900, 900);
g.key("action");
g.round.dice = 0;
g.round.phase = "clear";
g.round.phaseMs = 1;
for (let ms = 0; ms < ghoul.PICK_HOLD_MS + 200; ms += 16) g.tick(16);
assert.equal(g.round.phase, "pick");
g.key("action");
assert.equal(g.round.phase, "intro");
for (let k = 0; k < 5; k++) g.key("action", true);
g.key("action");
assert.equal(g.round.phase, "intro", "too soon, and repeats never count");
assert.equal(g.round.input.fire, false, "no shot fired at the card");
g.tick(16);
assert.ok(sounds.includes("ghoulStageIntro"), "the stinger plays when the card opens");
const title = introFor(g.round.stage).title;
// The card is on screen, paused too.
for (let ms = 0; ms < 3000; ms += 16) g.tick(16);
texts.length = 0;
g.tick(16);
assert.ok(texts.includes(INTRO_HINT), "the hint shows");
assert.match(INTRO_HINT, /any move key or fire/);
assert.ok(title.split("").every((ch) => ch === " " || texts.includes(ch)), "every letter of the title is drawn");
const line = introFor(g.round.stage).lines[0];
assert.ok(texts.includes(line), "the flavor text is drawn");
g.pause();
const held = g.round.introMs;
for (let k = 0; k < 20; k++) g.tick(16);
assert.equal(g.round.introMs, held, "a pause holds the card");
g.resume();
g.key("up");
assert.equal(g.round.phase, "ready", "jump moves on too");
// Each of the other keys, and fire, moves a card on once the lockout has passed; a repeat or an early press never does.
for (const name of ["left", "right", "up", "down", "action"]) {
const k = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } });
k.resize(900, 900);
k.key("action");
k.round.dice = 0;
k.round.phase = "clear";
k.round.phaseMs = 1;
for (let ms = 0; ms < ghoul.PICK_HOLD_MS + 200; ms += 16) k.tick(16);
k.key("action");
assert.equal(k.round.phase, "intro", name);
k.key(name);
assert.equal(k.round.phase, "intro", `${name}: an early press is ignored`);
for (let ms = 0; ms < ghoul.INTRO_MIN_MS + 100; ms += 16) k.tick(16);
k.key(name, true);
assert.equal(k.round.phase, "intro", `${name}: a repeat is ignored`);
k.release(name);
k.key(name);
assert.equal(k.round.phase, "ready", `${name}: a fresh press moves on`);
assert.equal(k.round.input.fire, false, "no shot fired at the card");
}
// A click works as well.
const h = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } });
h.resize(900, 900);
h.key("action");
h.round.dice = 0;
h.round.phase = "clear";
h.round.phaseMs = 1;
for (let ms = 0; ms < ghoul.PICK_HOLD_MS + 200; ms += 16) h.tick(16);
h.key("action");
for (let ms = 0; ms < 1300; ms += 16) h.tick(16);
h.pointer("down", 10, 10);
assert.equal(h.round.phase, "ready", "a click moves on");
});
test("Ghoul Rush intros: the stage select shows the card on a stage's first room only", () => {
const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => fakeCtx([]) } });
g.resize(900, 900);
g.key("action");
const r = g.round;
r.phase = "select";
r.select = { at: 3, room: 0 };
r.practice = true;
g.key("action");
assert.equal(r.phase, "intro", "the first room opens on the card");
assert.equal(r.stage, ghoul.STAGES[3].id);
const s = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => fakeCtx([]) } });
s.resize(900, 900);
s.key("action");
s.round.phase = "select";
s.round.select = { at: 3, room: 2 };
s.round.practice = true;
s.key("action");
assert.equal(s.round.phase, "ready", "a room mid-stage has no card");
});
test("Ghoul Rush intros: every card draws on a fake canvas at every moment without throwing", () => {
for (const st of ghoul.STAGES) {
const texts = [];
const ctx = fakeCtx(texts);
const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } });
g.resize(900, 900);
g.key("action");
g.round.phase = "select";
g.round.select = { at: ghoul.STAGES.indexOf(st), room: 0 };
g.key("action");
assert.equal(g.round.phase, "intro", st.id);
for (let ms = 0; ms < 5000; ms += 80) {
g.round.introMs = ms;
g.tick(1);
}
assert.ok(texts.includes(`BOSS: ${introFor(st.id).boss.toUpperCase()}`), `${st.id} names its boss`);
}
});
test("Ghoul Rush intros: the title's letters fall once and bounce", () => {
assert.equal(dropAt(-1), 1);
assert.equal(dropAt(10000), 0);
assert.ok(dropAt(100) < 1 && dropAt(100) > 0.5);
let peak = 0;
for (let t = 330; t < 520; t += 10) peak = Math.max(peak, dropAt(t));
assert.ok(peak > 0 && peak < 0.2, "one small bounce");
});
@@ -135,7 +135,7 @@ test("Ghoul Rush's Deep Seam Mine is a stage of three rooms and the Seam, always
assert.equal(st.boss, "tommy");
assert.equal(st.title, "The Deep Seam Mine");
assert.equal(st.sub, "They are still knocking");
assert.equal(ghoul.STAGES.at(-3), st, "the last stage in the list but the Carnival and the Frozen Lake");
assert.equal(ghoul.STAGES.at(-4), st, "the last stage in the list but the Carnival, the Frozen Lake and Gallows Bog");
for (const kind of Object.keys(mn.MONSTERS)) assert.equal(ghoul.MONSTERS[kind], mn.MONSTERS[kind], `${kind} is a monster`);
assert.equal(ghoul.BOSSES.tommy, mn.BOSSES.tommy);
assert.equal(mn.BOSSES.tommy.sub, "Follow the knocking, not the light");
@@ -1556,7 +1556,7 @@ test("Ghoul Rush's stage select lists the Mine and takes you straight into each
const r = g.round;
assert.equal(r.phase, "select");
const at = ghoul.STAGES.findIndex((s) => s.id === "mine");
assert.equal(at, ghoul.STAGES.length - 3);
assert.equal(at, ghoul.STAGES.length - 4);
for (let i = 0; i < at; i++) ghoul.steerSelect(r, 1, 0);
for (let i = 0; i < 4; i++) ghoul.steerSelect(r, 0, 1);
assert.equal(r.select.at, at);
@@ -0,0 +1,945 @@
// Web console tests, Ghoul Rush's Gardener's Revenge (the Grounds' bonus round, between the Gazebo and the Groundskeeper's Yard): its shape (every pond and ditch clears with a jump and swallows a mower that does not jump, every low can be ducked), the mower's motion, each obstacle's cost and cause, the blades (cutting, the heat, the jam, the lawn cut), the topiary beasts, the hearts, the checkpoints, the finish and the dice, endless lives, the art on a fake canvas, and the two bots (one that plays well finishes in time, one that never dodges loses).
// Run with: node --test scripts/test-web-console-activities-ghoul-mower.mjs
import { test } from "node:test";
import assert from "node:assert/strict";
import * as ghoul from "../src/web-console/public/activities/ghoul.js";
import { skipBossIntro } from "./ghoul-test-helpers.mjs";
import * as mw from "../src/web-console/public/activities/ghoul-mower.js";
import * as ct from "../src/web-console/public/activities/ghoul-cart.js";
import { ANSWERS, EVENT_VOICE, LOSE_SOUNDS, LOSE_WORDS, LOOKS as MOWER_LOOKS, VOICES as MOWER_VOICES, telegraphMarks, telegraphs } from "../src/web-console/public/activities/ghoul-mower-draw.js";
import { MOWER_SFX } from "../src/web-console/public/activities/ghoul-sfx-mower.js";
import * as ghoulSfx from "../src/web-console/public/activities/ghoul-sfx.js";
import { LOOKS, VOICES, bonusTick, react } from "../src/web-console/public/activities/ghoul-draw.js";
import { BONUS_FLOOR, diceFor, endBonus } from "../src/web-console/public/activities/ghoul-bonus.js";
const steady = () => 0.5;
// The pack draws no random number: a run on this fails on the first draw.
const never = () => {
throw new Error("the mower drew a random number");
};
const events = (round, type) => round.events.filter((e) => e.type === type);
function through(round) {
round.phase = "clear";
round.phaseMs = 1;
ghoul.advance(round, 4, steady);
}
// A round in the Gardener's Revenge reached the way play reaches it, nothing woken, the clocks long,
// the bonus round on (five hearts).
function mowerRound(seed = 5) {
const round = ghoul.newRound(seed);
round.lives = 3;
round.dice = 0;
through(round);
round.offer = ["grounds"];
round.phaseMs = 0;
ghoul.pickStage(round, 0);
while (round.spec.id !== "mower") through(round);
round.phase = "play";
for (const st of round.spawns) st.over = true;
round.monsters.length = 0;
round.hordeMs = Infinity;
round.timeMs = 1e9;
round.bonus = 1e9;
round.events.length = 0;
return round;
}
const NONE = { runner: "mower", time: 1e9, finish: 1e6, track: [], gaps: [], junk: [], lows: [], hedges: [], beasts: [], grass: [], weeds: [], checks: [] };
// The same round over a ride of its own (a plain lawn to measure the mower on).
function synth(ride) {
const round = mowerRound();
round.spec = { ...round.spec, start: 10, ground: [[0, 5, 0]], ride: { ...NONE, ...ride } };
round.runner = null;
mw.MOWER.place[0](round, {});
return round;
}
const FLAT = [[[0, 20], [4000, 20]]];
// The mower on line `line` of the ride at `x`, at speed `v`.
function mowerAt(round, x, line, { v = mw.MOWER_V, safe = false } = {}) {
const y = ct.trackY(round.spec.ride, line, x);
assert.ok(y !== null, `line ${line} runs under ${x}`);
Object.assign(round.you, { x, y, vy: 0, state: "run", shelf: -1, face: 1, out: 0, safeMs: safe ? 1e9 : 0, ducking: false });
Object.assign(round.runner, { line, v, coyote: 0 });
round.camX = Math.max(0, Math.min(round.spec.length - ghoul.FIELD_W, x - 24));
}
function run(round, ms, keys = {}, random = steady) {
Object.assign(round.input, keys);
for (let t = 0; t < ms; t += 4) ghoul.advance(round, 4, random);
for (const k of Object.keys(keys)) round.input[k] = typeof keys[k] === "number" ? 0 : false;
}
function until(round, done, ms = 6000, random = steady) {
let t = 0;
for (; t < ms && !done(); t += 4) ghoul.advance(round, 4, random);
return t;
}
const press = (round) => {
round.input.jump = ghoul.JUMP_BUFFER_MS;
round.input.up = true;
};
const heard = (e, extra = {}) => {
const played = [];
const noop = () => {};
const kit = { tone: (name) => played.push(name), burst: noop, float: noop, ring: noop, banner: () => null, shake: noop, flash: noop, glow: noop, splat: noop, fx: { clock: 1e6 }, monsters: ghoul.MONSTERS, powers: ghoul.POWERS, bosses: ghoul.BOSSES, g: {}, floorAt: () => 6, ...extra };
react({ x: 10, y: 6, tx: 20, ty: 6, ...e }, kit);
return { played };
};
const ROOM = ghoul.roomById("mower");
const R = ROOM.ride;
const lines = ct.linesOf(R);
const floorOf = (x) => ghoul.groundAt(ROOM, x);
const LANE = R.track[0][0][1];
/* -------------------------------------------------------------- the room */
test("Ghoul Rush's Gardener's Revenge is the Grounds' fourth room, between the Gazebo and the Groundskeeper's Yard: lit, no key, no boss, a ride about 60 to 70 seconds long, a bonus round that plays its own track", () => {
const st = ghoul.stageById("grounds");
assert.deepEqual(st.rooms, ["maze", "topiary", "gazebo", "mower", "yard"]);
assert.equal(st.boss, "keeper");
assert.deepEqual([ROOM.title, ROOM.sub], ["The Gardener's Revenge", "The lawn has not been mowed since 1893"]);
assert.equal(ROOM.dark, false);
assert.equal(ROOM.key, null);
assert.equal(ROOM.boss, null);
assert.equal(ROOM.bonus, true);
assert.equal(R.runner, "mower", "the shared ride slot, which the cart's place leaves alone");
assert.ok(ROOM.length >= 1800 && ROOM.length <= 3000, `${ROOM.length} units long`);
assert.equal(ghoul.ROOM_MUSIC.mower, "ghoulMowerRide");
assert.ok(ghoulSfx.default.music.ghoulMowerRide, "its own track");
assert.deepEqual(Object.keys(mw.MOWER.monsters), [], "no new monster kinds");
assert.equal(LOOKS.mower, MOWER_LOOKS.mower);
assert.equal(LOOKS.mower.pack, "mower");
assert.ok(Object.isFrozen(R) && Object.isFrozen(R.track) && Object.isFrozen(R.track[0][0]), "frozen all the way down");
assert.ok(ROOM.horde.length === 0 && ROOM.spawns.length === 0, "no monsters: the things on the lawn are the pack's own");
assert.equal(ROOM.ground.length, 2);
assert.equal(ROOM.ground[1][0], R.finish, "the lawn's end begins at the finish");
assert.ok(ROOM.door > R.finish && ROOM.door > ROOM.length - 14);
assert.ok(floorOf(ROOM.door - 2) > -Infinity, "floor to walk out on");
assert.equal(ct.trackY(R, 0, ROOM.start), floorOf(ROOM.start), "the mower starts on the lawn");
assert.equal(floorOf(R.finish + 1), LANE, "the lawn's end is level with the lawn");
// Every line is flat at one height, running left to right.
for (const L of lines) for (const [x, y] of L.pts) assert.equal(y, LANE, `a flat lawn at ${x}`);
const secs = (lines.at(-1).x1 - ROOM.start) / mw.MOWER_V;
assert.ok(secs >= 58 && secs <= 72, `${secs.toFixed(1)} s at MOWER_V`);
assert.equal(ghoul.timeFor(ghoul.roomFor("mower")), R.time);
assert.ok(R.time >= 1.5 * secs * 1000 && R.time <= 120000, `a ${R.time} ms clock for a ${secs.toFixed(0)} s ride`);
assert.equal(lines.at(-1).x1, R.finish);
assert.match(R.how, /UP to jump, DOWN to duck, hold space to shoot and mow/);
});
test("Ghoul Rush's Gardener's Revenge: every pond and ditch clears with a jump at the edge or a few units early, and a mower that never jumps drops into it", () => {
assert.equal(R.gaps.length, lines.length - 1);
assert.ok(R.gaps.includes(0) && R.gaps.includes(1), "ponds and ditches both");
for (let i = 0; i + 1 < lines.length; i++) {
const a = lines[i];
const b = lines[i + 1];
const gap = b.x0 - a.x1;
assert.ok(gap >= 7 && gap <= 12, `gap ${i} is ${gap} wide`);
for (const v of [mw.MOWER_V - mw.BOG, mw.MOWER_V]) {
assert.equal(mw.flight(R, a.x1, LANE, 0, v), null, `gap ${i}, no jump, at ${v}`);
for (const early of v === mw.MOWER_V ? [0, 4, 8] : [0, 4]) {
const x = a.x1 - early;
const s = mw.flight(R, x, LANE, mw.MOWER_JUMP_V, v);
assert.ok(s, `gap ${i}: a jump ${early} early at ${v} lands`);
assert.equal(s.line, i + 1, `gap ${i} cleared, at ${v}, ${early} early`);
}
}
}
});
test("Ghoul Rush's Gardener's Revenge: every thing is on the lawn, off the ends and off the gaps, spaced for a player (30 between jumps and 38 between a jump and a duck), a low's underside between a ducked box and a standing one", () => {
const onLawn = (x) => lines.some((L) => x > L.x0 + 3 && x < L.x1 - 3);
const hits = [];
for (const [x] of R.junk) hits.push({ x, kind: "jump" });
for (const x of R.hedges) hits.push({ x, kind: "jump" });
for (const x of R.beasts) hits.push({ x, kind: "jump" });
for (let i = 0; i + 1 < lines.length; i++) hits.push({ x: lines[i].x1, kind: "jump" });
for (const [x0, x1, y, kind] of R.lows) {
assert.ok(kind === 0 || kind === 1);
assert.equal(y, LANE + 3, "a low's underside 3.0 over the lawn");
assert.ok(y > LANE + ghoul.DUCK_H && y < LANE + ghoul.HIT_H, "between a ducked box and a standing one");
assert.ok(x0 < x1);
hits.push({ x: x0, x1, kind: "duck" });
}
for (const h of hits) if (h.kind === "jump" && h.x < lines.at(-1).x1) assert.ok(h.x > ROOM.start + 30, `${h.x} is past the start`);
for (const [x] of R.junk) assert.ok(onLawn(x), `junk at ${x}`);
for (const x of [...R.hedges, ...R.beasts]) assert.ok(onLawn(x), `a hedge or beast at ${x}`);
hits.sort((p, q) => p.x - q.x);
for (let i = 0; i + 1 < hits.length; i++) {
const a = hits[i];
const b = hits[i + 1];
const need = a.kind === "jump" && b.kind === "jump" ? 30 : a.kind === "duck" && b.kind === "duck" ? 20 : a.kind === "jump" ? 38 : 24;
const gap = b.x - (a.x1 ?? a.x);
assert.ok(gap >= need, `${a.kind} at ${a.x} then ${b.kind} at ${b.x}: ${gap} between (${need} wanted)`);
}
// Counts: the room's graded obstacles and the mow targets.
assert.equal(R.junk.length + R.lows.length + R.hedges.length + R.beasts.length + R.gaps.length, 36);
assert.equal(R.checks.length, 5);
for (const x of R.checks) assert.ok(onLawn(x), `checkpoint ${x}`);
for (const [x0, x1] of R.grass) assert.ok(x1 > x0 && x0 >= 0 && x1 <= R.finish);
assert.ok(mw.totalCells(R) > 600, `${mw.totalCells(R)} cells`);
// Candy and items are on the lawn.
assert.ok(ROOM.candy.length > 50);
for (const [x, y] of ROOM.candy) assert.ok(y > LANE, `candy ${x} over the lawn`);
});
/* ------------------------------------------------------------ the mower */
test("Ghoul Rush's Gardener's Revenge rolls at MOWER_V, no key changes it, and it bogs down a little after a cut", () => {
const flat = synth({ track: FLAT });
assert.equal(flat.runner.v, mw.MOWER_V);
assert.equal(flat.runner.id, "mower");
run(flat, 2000);
assert.ok(Math.abs(flat.runner.v - mw.MOWER_V) < 0.01);
run(flat, 1500, { right: true });
run(flat, 1500, { left: true });
assert.ok(Math.abs(flat.runner.v - mw.MOWER_V) < 0.01, "right and left do nothing");
assert.ok(Math.abs(flat.you.x - (10 + (2000 + 1500 + 1500) / 1000 * mw.MOWER_V)) < 1, "rides on at MOWER_V");
assert.equal(flat.you.face, 1);
assert.equal(flat.you.state, "run");
assert.equal(flat.you.y, 20);
const grass = synth({ track: FLAT, grass: [[40, 80]] });
grass.input.fire = true;
let low = mw.MOWER_V;
until(grass, () => (low = Math.min(low, grass.runner.v)) < 0 || grass.you.x > 90, 4000);
assert.ok(low < mw.MOWER_V - 2 && low >= mw.MOWER_V - mw.BOG - 0.01, `${low} while cutting`);
});
test("Ghoul Rush's Gardener's Revenge jumps about 11 high for about 0.7 s (22 across), a press saved for a landing jumps on it, one just after a line's end still jumps", () => {
const round = synth({ track: FLAT });
let top = 0;
press(round);
const t = until(round, () => {
top = Math.max(top, round.you.y - 20);
return round.you.state === "run" && round.you.y === 20 && round.you.vy === 0 && top > 1;
}, 3000);
assert.ok(Math.abs(top - (mw.MOWER_JUMP_V * mw.MOWER_JUMP_V) / (2 * mw.MOWER_G)) < 0.4, `${top.toFixed(1)} high`);
assert.ok(t > 600 && t < 800, `${t} ms in the air`);
assert.equal(events(round, "mowerJump").length, 1);
assert.equal(events(round, "mowerLand").length, 1);
const across = round.you.x - 10;
assert.ok(across > 20 && across < 25, `${across.toFixed(1)} across`);
const buf = synth({ track: FLAT });
press(buf);
run(buf, 600);
press(buf);
until(buf, () => events(buf, "mowerJump").length >= 2, 1500);
assert.equal(events(buf, "mowerJump").length, 2, "the saved press jumped again at the landing");
const edge = synth({ track: [[[0, 20], [60, 20]], [[100, 20], [300, 20]]] });
mowerAt(edge, 58.5, 0);
run(edge, 60);
assert.equal(edge.runner.line, -1, "off the end");
press(edge);
run(edge, 4);
assert.equal(events(edge, "mowerJump").length, 1, "coyote");
const late = synth({ track: [[[0, 20], [60, 20]], [[100, 20], [300, 20]]] });
mowerAt(late, 58.5, 0);
run(late, 60 + mw.COYOTE_MS);
press(late);
run(late, 4);
assert.equal(events(late, "mowerJump").length, 0);
});
test("Ghoul Rush's Gardener's Revenge: down ducks (and a press of up jumps instead of ducking), a ducked Planny passes under a hedge arch or a line of gloves and a standing one hits it (causes arch and line), at the cost of a heart", () => {
const round = synth({ track: FLAT, lows: [[60, 66, 23, 0]] });
const you = round.you;
assert.equal(you.ducking, false);
run(round, 20, { down: true });
assert.equal(events(round, "mowerDuck").length, 1);
round.input.down = true;
until(round, () => you.x > 75, 3000);
round.input.down = false;
assert.equal(round.bonusRound.hearts, 5);
assert.equal(round.lives, 3);
for (const [kind, cause] of [[0, "arch"], [1, "line"]]) {
const hit = synth({ track: FLAT, lows: [[60, 66, 23, kind]] });
until(hit, () => hit.bonusRound.hearts < 5, 3000);
assert.equal(hit.bonusRound.hearts, 4, `${cause} costs a heart`);
assert.equal(events(hit, "lose")[0].cause, cause);
assert.equal(hit.lives, 3);
assert.ok(hit.you.safeMs > 0, "Planny blinks safe");
assert.deepEqual(hit.bonusRound.perf.hits, ["l0"]);
run(hit, 800);
assert.equal(hit.bonusRound.hearts, 4, "the safe moment spares the rest of it");
assert.equal(hit.runner.done, false, "the mower rolls on");
}
const jump = synth({ track: FLAT, lows: [[60, 66, 23, 0]] });
mowerAt(jump, 52, 0);
press(jump);
run(jump, 8);
assert.equal(jump.you.ducking, false);
assert.equal(events(jump, "mowerJump").length, 1);
});
test("Ghoul Rush's Gardener's Revenge: a gnome, a wheelbarrow and a flowerpot are cleared by a jump and cost a heart otherwise (causes gnome, barrow and pot), each only once", () => {
for (const [kind, cause] of [[0, "gnome"], [1, "barrow"], [2, "pot"]]) {
const hit = synth({ track: FLAT, junk: [[60, kind]] });
until(hit, () => hit.bonusRound.hearts < 5, 3000);
assert.equal(hit.bonusRound.hearts, 4, `${cause} costs a heart`);
assert.equal(events(hit, "lose")[0].cause, cause);
assert.equal(events(hit, "mowerCrash")[0].what, cause);
assert.deepEqual(hit.bonusRound.perf.hits, ["j0"]);
run(hit, 500);
assert.equal(hit.bonusRound.hearts, 4);
for (const from of [60 - 16, 60 - 12, 60 - 9, 60 - 6]) {
const clear = synth({ track: FLAT, junk: [[60, kind]] });
mowerAt(clear, from, 0);
press(clear);
until(clear, () => clear.you.x > 80, 3000);
assert.equal(clear.bonusRound.hearts, 5, `${cause} jumped from ${from}`);
}
}
assert.equal(mw.JUNK.length, 3);
});
test("Ghoul Rush's Gardener's Revenge: a pond or a ditch with no jump is a heart (causes pond and ditch), the mower goes back on the lawn ahead at MOWER_V and rolls on; a jump over it costs nothing", () => {
for (const [kind, cause] of [[0, "pond"], [1, "ditch"]]) {
const gap = synth({ track: [[[0, 20], [60, 20]], [[72, 20], [400, 20]]], gaps: [kind] });
mowerAt(gap, 30, 0);
until(gap, () => events(gap, "lose").length > 0, 3000);
assert.equal(events(gap, "lose")[0].cause, cause);
assert.equal(events(gap, "mowerCrash")[0].what, cause);
assert.equal(gap.bonusRound.hearts, 4);
assert.deepEqual(gap.bonusRound.perf.hits, ["g0"]);
assert.equal(gap.runner.line, 1, "back on the next lawn");
assert.equal(gap.you.y, 20);
assert.equal(gap.runner.v, mw.MOWER_V);
run(gap, 600);
assert.equal(gap.bonusRound.hearts, 4);
const over = synth({ track: [[[0, 20], [60, 20]], [[72, 20], [400, 20]]], gaps: [kind] });
mowerAt(over, 56, 0);
press(over);
until(over, () => over.you.x > 100, 3000);
assert.equal(over.bonusRound.hearts, 5, `${cause} jumped`);
}
});
/* ------------------------------------------------------------- the blades */
test("Ghoul Rush's Gardener's Revenge: holding fire lowers the blades, which cut every grass cell within BLADE_REACH ahead (GRASS_POINTS each) and nothing behind or out of reach; let go, nothing is cut", () => {
const dry = synth({ track: FLAT, grass: [[30, 60]] });
run(dry, 1500);
assert.equal(dry.runner.cut, 0, "no fire, no cut");
assert.equal(dry.runner.blade, false);
const round = synth({ track: FLAT, grass: [[40, 70]] });
mowerAt(round, 29, 0);
const score = round.score;
round.input.fire = true;
run(round, 24);
assert.equal(round.runner.blade, true);
assert.equal(round.runner.cut, 0, "nothing in reach yet");
until(round, () => round.runner.cut > 0, 1000);
const cells = round.runner.cut;
assert.ok(cells >= 1);
const row = round.runner.grass[0];
assert.ok(row[0] && !row[mw.BLADE_REACH + 3], "the nearest cells first, none beyond the zone");
assert.ok(round.you.x + mw.BLADE_REACH >= 40);
assert.equal(round.score - score >= cells * mw.GRASS_POINTS, true);
const ev = events(round, "mowerGrass");
assert.ok(ev.length >= 1 && ev[0].points === ev[0].n * mw.GRASS_POINTS);
until(round, () => round.you.x > 62, 2000);
assert.equal(round.runner.cut, 30, "the whole strip, 30 cells");
assert.equal(round.runner.cells, 30);
assert.ok(Math.abs(round.runner.lawn - 1) < 1e-9);
});
test("Ghoul Rush's Gardener's Revenge: a thorn hedge is cut by the blades (HEDGE_POINTS, an act) before it can hurt, or jumped; uncut it costs a heart (cause thorns); a weed patch is cut for WEED_POINTS and counts WEED_CELLS", () => {
const cut = synth({ track: FLAT, hedges: [80] });
mowerAt(cut, 60, 0);
cut.input.fire = true;
const score = cut.score;
until(cut, () => cut.you.x > 95, 3000);
assert.equal(cut.bonusRound.hearts, 5, "cut, not hit");
assert.equal(cut.runner.hedges[0], true);
assert.equal(events(cut, "mowerHedge").length, 1);
assert.ok(cut.score - score >= mw.HEDGE_POINTS, "the points (and any souls on the way)");
assert.equal(events(cut, "mowerHedge")[0].points, mw.HEDGE_POINTS);
assert.equal(cut.bonusRound.perf.acts, 1);
const hit = synth({ track: FLAT, hedges: [80] });
until(hit, () => hit.bonusRound.hearts < 5, 4000);
assert.equal(hit.bonusRound.hearts, 4);
assert.equal(events(hit, "lose")[0].cause, "thorns");
assert.deepEqual(hit.bonusRound.perf.hits, ["h0"]);
for (const from of [80 - 16, 80 - 10, 80 - 6]) {
const jump = synth({ track: FLAT, hedges: [80] });
mowerAt(jump, from, 0);
press(jump);
until(jump, () => jump.you.x > 100, 3000);
assert.equal(jump.bonusRound.hearts, 5, `jumped from ${from}`);
assert.equal(jump.runner.hedges[0], false, "left standing");
}
const weeds = synth({ track: FLAT, weeds: [60, 90], grass: [[120, 130]] });
assert.equal(weeds.runner.cells, 2 * mw.WEED_CELLS + 10);
mowerAt(weeds, 40, 0);
weeds.input.fire = true;
const s0 = weeds.score;
until(weeds, () => weeds.you.x > 100, 4000);
assert.deepEqual(weeds.runner.weeds, [true, true]);
assert.ok(weeds.score - s0 >= 2 * mw.WEED_POINTS);
assert.equal(weeds.bonusRound.perf.acts, 2);
assert.equal(weeds.runner.cut, 2 * mw.WEED_CELLS);
assert.equal(events(weeds, "mowerWeed").length, 2);
});
test("Ghoul Rush's Gardener's Revenge: the blades heat while fire is held (HEAT_UP a second), cool when let go (COOL), and at full heat jam for JAM_MS, cutting nothing, then restart at JAM_RESUME", () => {
const round = synth({ track: FLAT });
round.input.fire = true;
run(round, 1000);
assert.ok(Math.abs(round.runner.heat - mw.HEAT_UP) < 0.02, `${round.runner.heat} after a second`);
round.input.fire = false;
run(round, 500);
assert.ok(Math.abs(round.runner.heat - (mw.HEAT_UP - mw.COOL * 0.5)) < 0.03, `${round.runner.heat} after cooling`);
run(round, 2000);
assert.equal(round.runner.heat, 0);
// Held to the end: a jam.
const jam = synth({ track: FLAT, grass: [[40, 900]], hedges: [] });
jam.input.fire = true;
const t = until(jam, () => jam.runner.jam > 0, 4000);
assert.ok(Math.abs(t - 1000 / mw.HEAT_UP) < 60, `jammed after ${t} ms`);
assert.equal(events(jam, "mowerJam").length, 1);
assert.equal(jam.runner.blade, false);
const cut = jam.runner.cut;
run(jam, mw.JAM_MS / 2);
assert.equal(jam.runner.cut, cut, "nothing is cut while jammed, though fire is held");
assert.ok(jam.runner.heat < 1 && jam.runner.heat > mw.JAM_RESUME);
until(jam, () => jam.runner.jam === 0, 2000);
assert.ok(Math.abs(jam.runner.heat - mw.JAM_RESUME) < 0.02 || jam.runner.heat > mw.JAM_RESUME);
run(jam, 100);
assert.equal(jam.runner.blade, true, "the blades come down again");
assert.ok(jam.runner.cut > cut);
// A thorn hedge met while jammed is not cut.
const hedge = synth({ track: FLAT, hedges: [100] });
hedge.runner.jam = 5000;
hedge.input.fire = true;
until(hedge, () => hedge.bonusRound.hearts < 5 || hedge.you.x > 120, 5000);
assert.equal(events(hedge, "lose")[0].cause, "thorns");
});
test("Ghoul Rush's Gardener's Revenge: the lawn cut is the grade's steady die (LAWN_GOAL), the cut stays cut after a restart, and ACTS_GOAL cuts and shots are the acts die", () => {
const round = synth({ track: FLAT, grass: [[40, 80]] });
mowerAt(round, 28, 0);
const b = round.bonusRound;
assert.equal(b.perf.steady, false);
assert.equal(b.perf.goal, mw.ACTS_GOAL);
round.input.fire = true;
until(round, () => round.runner.lawn >= mw.LAWN_GOAL - 0.0001 && round.runner.lawn < 1, 3000);
assert.equal(b.perf.steady, true, "60% is the die");
// Below the goal, no die.
const low = synth({ track: FLAT, grass: [[40, 80]] });
mowerAt(low, 28, 0);
low.input.fire = true;
until(low, () => low.runner.lawn > 0.4, 3000);
low.input.fire = false;
run(low, 200);
assert.ok(low.runner.lawn < mw.LAWN_GOAL);
assert.equal(low.bonusRound.perf.steady, false);
// The lawn cut survives the same room's restart.
const cutBefore = round.runner.grass[0].slice();
mw.MOWER.place[0](round, {});
assert.deepEqual(round.runner.grass[0], cutBefore);
assert.equal(round.runner.cut, cutBefore.filter(Boolean).length);
// The dice formula with and without the die.
const make = (steadyDie, acts) => ({ hearts: 5, max: 5, perf: { total: 36, hits: [], acts, goal: mw.ACTS_GOAL, steady: steadyDie, kills0: 0 } });
assert.equal(diceFor(make(true, mw.ACTS_GOAL)), 9);
assert.equal(diceFor(make(false, mw.ACTS_GOAL)), 8);
assert.equal(diceFor(make(true, 0)), 8);
assert.equal(diceFor(make(false, 0)), 7);
const bad = make(false, 0);
bad.hearts = 1;
bad.perf.hits = Array.from({ length: 36 }, (_, i) => `x${i}`);
assert.equal(diceFor(bad), BONUS_FLOOR);
});
/* -------------------------------------------------------- topiary beasts */
test("Ghoul Rush's Gardener's Revenge: a topiary beast shivers when the mower is BEAST_NEAR short, lunges into the lane for BEAST_UP_MS, snaps (cause snap) if you meet it, and a jump clears it", () => {
const round = synth({ track: FLAT, beasts: [120] });
const b = round.runner.beasts[0];
assert.equal(b.state, "idle");
until(round, () => b.state === "warn", 3000);
assert.ok(Math.abs(120 - round.you.x - mw.BEAST_NEAR) < 2, `woke ${120 - round.you.x} short`);
assert.equal(events(round, "mowerBeastWarn").length, 1);
until(round, () => b.state === "snap", 1000);
assert.equal(events(round, "mowerBeastSnap").length, 1);
until(round, () => round.bonusRound.hearts < 5, 3000);
assert.equal(round.bonusRound.hearts, 4);
assert.equal(events(round, "lose")[0].cause, "snap");
assert.equal(events(round, "mowerCrash")[0].what, "snap");
assert.deepEqual(round.bonusRound.perf.hits, ["b0"]);
for (const from of [120 - 16, 120 - 10, 120 - 6]) {
const jump = synth({ track: FLAT, beasts: [120] });
mowerAt(jump, from, 0);
jump.runner.beasts[0].state = "snap";
jump.runner.beasts[0].t = mw.BEAST_UP_MS;
press(jump);
until(jump, () => jump.you.x > 140, 3000);
assert.equal(jump.bonusRound.hearts, 5, `jumped from ${from}`);
}
// It goes back to being a bush if it is not met.
const away = synth({ track: FLAT, beasts: [120] });
mowerAt(away, 100, 0, { safe: true });
until(away, () => away.runner.beasts[0].state === "spent", 6000);
assert.equal(away.runner.beasts[0].state, "spent");
});
test("Ghoul Rush's Gardener's Revenge: BEAST_HP bolts break a lunging beast (150 points, an act, mowerBeastHit then mowerBeastBreak); a sleeping one is not hit, and what was shot stays shot after a restart", () => {
const round = synth({ track: FLAT, beasts: [120] });
const b = round.runner.beasts[0];
const shoot = () => {
const y = 20 + 2.4;
round.shots.push({ x: 119, y, vx: 130, vy: 0, gone: 0 });
run(round, 12);
};
shoot();
assert.equal(b.hp, mw.BEAST_HP, "a sleeping beast takes no bolt");
b.state = "snap";
b.t = mw.BEAST_UP_MS;
round.you.safeMs = 1e9;
const score = round.score;
shoot();
assert.equal(b.hp, mw.BEAST_HP - 1);
assert.equal(events(round, "mowerBeastHit").length, 1);
assert.equal(b.state, "snap");
shoot();
assert.equal(b.state, "broken");
assert.equal(events(round, "mowerBeastBreak").length, 1);
assert.equal(round.score - score, mw.BEAST_POINTS);
assert.equal(round.bonusRound.perf.acts, 1);
mw.MOWER.place[0](round, {});
assert.equal(round.runner.beasts[0].state, "broken");
});
/* ------------------------------------------------------------ the rounds */
test("Ghoul Rush's Gardener's Revenge: 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 Groundskeeper's Yard", () => {
const round = mowerRound();
round.dice = 2;
round.bonusRound.hearts = 1;
mowerAt(round, lines[0].x1 - 6, 0);
round.you.safeMs = 0;
until(round, () => round.phase === "clear", 6000);
assert.equal(round.bonusRound.hearts, 0);
assert.equal(round.bonusRound.over, true);
assert.equal(round.bonusRound.won, false);
const end = events(round, "bonusEnd");
assert.equal(end.length, 1);
assert.equal(end[0].won, false);
assert.equal(end[0].dice, 0);
assert.equal(round.over, false, "no game over");
assert.equal(round.lives, 3);
assert.equal(round.dice, 2);
run(round, ghoul.CARD_LOST_MS + 100);
assert.equal(round.spec.id, "yard");
assert.equal(round.bonusRound, null);
assert.equal(round.runner, null, "the slot is empty in any other room");
assert.equal(round.lives, 3);
assert.equal(round.dice, 2);
assert.equal(round.phase, "bossintro", "the boss room opens on its card");
skipBossIntro(ghoul, round);
assert.equal(round.phase, "ready");
});
test("Ghoul Rush's Gardener's Revenge: the checkpoints are passed in order (an event each) and the ride goes back to the last one after a restart", () => {
const round = mowerRound();
round.you.safeMs = 1e9;
mowerAt(round, R.checks[0] - 3, lines.findIndex((L) => L.x1 > R.checks[0] - 3 && L.x0 < R.checks[0] - 3), { safe: true });
until(round, () => round.runner.check >= 0, 1000);
assert.equal(round.runner.check, 0);
const ev = events(round, "mowerCheck");
assert.equal(ev.length, 1);
assert.equal(ev[0].n, 1);
round.you.x = R.checks[2] + 1;
round.you.y = LANE;
round.runner.line = lines.findIndex((L) => L.x1 > R.checks[2] + 1 && L.x0 < R.checks[2] + 1);
until(round, () => round.runner.check >= 2, 1000);
assert.equal(round.runner.check, 2, "all passed on the way");
mw.MOWER.place[0](round, {});
assert.equal(round.you.x, R.checks[2], "back at the last one");
assert.equal(round.runner.check, 2);
});
test("Ghoul Rush's Gardener's Revenge: rolling onto the lawn's end stops the mower (mowerFinish), the door opens, and walking out ends the round with 3 to 9 Lucky dice", () => {
const round = mowerRound();
round.dice = 1;
const last = lines.length - 1;
mowerAt(round, lines[last].x1 - 12, last, { safe: true });
until(round, () => round.runner.done, 4000);
assert.equal(round.runner.done, true);
const fin = events(round, "mowerFinish");
assert.equal(fin.length, 1);
assert.ok(round.you.x >= R.finish && round.you.x < R.finish + 2, `${round.you.x} stopped`);
assert.equal(round.you.y, floorOf(round.you.x));
assert.equal(round.hasKey, true, "the door opens");
assert.equal(round.bonusRound.hearts, 5);
assert.equal(round.phase, "play");
round.input.right = true;
until(round, () => round.phase === "clear", 20000);
round.input.right = false;
assert.equal(round.phase, "clear");
const end = events(round, "bonusEnd");
assert.equal(end.length, 1);
assert.equal(end[0].won, true);
assert.ok(end[0].dice >= BONUS_FLOOR && end[0].dice <= ghoul.MAX_DICE, `${end[0].dice} dice`);
assert.equal(round.dice, Math.min(ghoul.MAX_DICE, 1 + end[0].dice));
assert.equal(round.lives, 3);
run(round, ghoul.CARD_MS + 100);
assert.equal(round.spec.id, "yard");
assert.equal(round.runner, null);
});
test("Ghoul Rush's Gardener's Revenge: no random number is drawn in the room (a ride of 20 seconds, jumping, mowing and shooting, on a draw that throws)", () => {
const round = mowerRound();
mowerAt(round, 120, 0, { safe: true });
round.input.fire = true;
for (let t = 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 > 500);
});
test("Ghoul Rush's Gardener's Revenge: endless lives (round.infinite) spare the hearts for every cause, through the same lose path", () => {
const tries = [
{ junk: [[60, 0]] }, { junk: [[60, 1]] }, { junk: [[60, 2]] }, { lows: [[56, 62, 23, 0]] }, { lows: [[56, 66, 23, 1]] }, { hedges: [[60]].map((r) => r[0]) }, { beasts: [60] },
];
for (const t of tries) {
const r = synth({ track: FLAT, ...t });
r.infinite = true;
if (t.beasts) mowerAt(r, 20, 0);
until(r, () => events(r, "lose").length > 0, 4000);
assert.ok(events(r, "lose").length > 0, JSON.stringify(Object.keys(t)));
assert.equal(r.bonusRound.hearts, 5, JSON.stringify(Object.keys(t)));
assert.equal(r.lives, 3);
}
for (const kind of [0, 1]) {
const gap = synth({ track: [[[0, 20], [60, 20]], [[72, 20], [400, 20]]], gaps: [kind] });
gap.infinite = true;
mowerAt(gap, 30, 0);
until(gap, () => events(gap, "lose").length > 0, 3000);
assert.equal(gap.bonusRound.hearts, 5);
assert.equal(gap.lives, 3);
}
});
test("Ghoul Rush's Gardener's Revenge: the Garlic shield takes a hit instead of a heart", () => {
const round = synth({ track: FLAT, junk: [[60, 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 Gardener's Revenge: every event has a voice that plays, every cause has words and a sound, the voices borrow tones that exist, and the tones are short", () => {
assert.deepEqual(Object.keys(EVENT_VOICE).sort(), [...mw.EVENTS].sort(), "a voice for every event and no more");
const tones = ghoulSfx.default.tones;
for (const [event, [kind, act]] of Object.entries(EVENT_VOICE)) {
const name = MOWER_VOICES[kind] && MOWER_VOICES[kind][act];
assert.ok(name, `${event} has a ${kind}.${act} voice`);
assert.ok(tones[name], `${name} exists`);
assert.equal(VOICES[kind][act], name, "joined to the game's voices");
assert.ok(heard({ type: event, what: "pond", points: 50 }).played.includes(name), `${event} plays ${name}`);
}
for (const cause of ["gnome", "barrow", "pot", "arch", "line", "thorns", "snap", "pond", "ditch"]) {
assert.ok(LOSE_WORDS[cause], `${cause} has words`);
assert.ok(LOSE_SOUNDS[cause] && LOSE_SOUNDS[cause].length === 3, `${cause} has a sound`);
assert.ok(heard({ type: "lose", cause, hearts: 3 }).played.length > 0, `${cause} sounds`);
}
assert.equal(heard({ type: "mowerJump" }).played.length, 1);
assert.equal(heard({ type: "mowerHedge", points: 80 }).played.length, 1);
for (const [name, tone] of Object.entries(MOWER_SFX.tones)) {
for (const layer of tone.layers) assert.ok((layer.delay || 0) + layer.seconds <= 1.2, `${name} is under 1.2 s`);
}
const music = MOWER_SFX.music.ghoulMowerRide;
for (const [key, p] of Object.entries(music.patterns)) {
for (const [voice, text] of Object.entries(p)) {
assert.ok(music.voices[voice], `${key}.${voice} is a voice`);
const bars = text.split("|").map((s) => s.trim().split(/\s+/).length);
assert.deepEqual(bars, [16, 16, 16, 16], `${key}.${voice}: four bars of 16 steps`);
}
}
for (const key of music.order) assert.ok(music.patterns[key]);
});
test("Ghoul Rush's Gardener's Revenge: the room's own names do not collide with the game's (events, kinds)", () => {
for (const e of mw.EVENTS) assert.ok(e.startsWith("mower"), e);
const other = new Set(ct.EVENTS || []);
for (const e of mw.EVENTS) assert.ok(!other.has(e), `${e} is the mower's alone`);
assert.deepEqual(Object.keys(mw.MOWER).filter((key) => ["hazards", "bosses", "boss"].includes(key)), []);
for (const name of Object.keys(MOWER_SFX.tones)) assert.ok(name.startsWith("ghoulMower"), name);
});
/* --------------------------------------------------------------- drawing */
test("Ghoul Rush's Gardener's Revenge draws: the room in a lit and a dark one, the mower on the lawn, in the air and ducking, with the blades up, down and jammed, each thing (grass cut and uncut, weeds, hedges, junk, arches, lines, beasts in each state, ponds, ditches), a crash, the finish and the cards", () => {
const ctx = new Proxy({}, { get: (t, name) => (name in t ? t[name] : () => {}), set: (t, name, value) => ((t[name] = value), true) });
const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } });
g.resize(900, 900);
g.key("action");
g.tick(16);
const r = g.round;
through(r);
r.offer = ["grounds"];
r.phaseMs = 0;
ghoul.pickStage(r, 0);
while (r.spec.id !== "mower") through(r);
r.lives = 99;
const spots = [ROOM.start + 40, R.junk[0][0] - 10, R.lows[0][0] - 5, R.lows[1][0] - 5, R.hedges[0] - 10, R.beasts[0] - 20, R.checks[0], lines[0].x1 - 10, R.finish - 40];
for (const dark of [true, false]) {
for (const x of spots) {
r.dark = dark;
r.phase = "play";
for (const st of r.spawns) st.over = true;
r.hordeMs = Infinity;
r.monsters.length = 0;
const line = Math.max(0, lines.findIndex((L) => x >= L.x0 && x <= L.x1));
mowerAt(r, x, line, { safe: true });
r.runner.beasts = r.runner.beasts.map((b, i) => ({ ...b, state: ["idle", "warn", "snap", "sink", "spent", "broken"][i % 6], t: 600 }));
r.runner.grass = r.runner.grass.map((row, i) => row.map((_, j) => (i + j) % 3 === 0));
r.runner.hedges = r.runner.hedges.map((_, i) => i % 2 === 0);
r.runner.weeds = r.runner.weeds.map((_, i) => i % 2 === 0);
for (const mode of ["up", "down", "jam"]) {
r.input.fire = mode === "down";
r.runner.jam = mode === "jam" ? 900 : 0;
r.runner.heat = mode === "jam" ? 0.7 : 0.4;
for (const air of [false, true]) {
if (air) Object.assign(r.you, { state: "air", vy: 20, y: r.you.y + 4 });
if (air) r.runner.line = -1;
r.you.ducking = x === R.lows[0][0] - 5 && !air;
r.shots.push({ x: x + 6, y: r.you.y + 2.4, vx: 130, vy: 0, gone: 0 });
for (let k = 0; k < 3; k++) g.tick(16);
r.monsters.length = 0;
r.you.safeMs = 1e9;
mowerAt(r, x, line, { safe: true });
}
}
}
}
r.input.fire = false;
assert.equal(r.spec.id, "mower");
// A crash, then the stop and the lost and won cards.
r.you.safeMs = 0;
mowerAt(r, R.junk[0][0] - 3, 0);
for (let k = 0; k < 30; k++) g.tick(16);
assert.ok(r.bonusRound.hearts < r.bonusRound.max || r.phase !== "play", "the crash draws too");
const done = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } });
done.resize(900, 900);
done.key("action");
done.tick(16);
const d = done.round;
through(d);
d.offer = ["grounds"];
d.phaseMs = 0;
ghoul.pickStage(d, 0);
while (d.spec.id !== "mower") through(d);
d.phase = "play";
d.runner.done = true;
d.runner.restX = R.finish + 1;
Object.assign(d.you, { x: R.finish + 30, y: LANE, state: "run" });
d.camX = R.finish - 40;
for (let k = 0; k < 10; k++) done.tick(16);
for (const won of [true, false]) {
endBonus(d, won, { ROOM_POINTS: 300, award: (rd, pts) => (rd.score += pts) });
d.bonusRound.over = true;
for (let k = 0; k < 10; k++) {
done.tick(16);
bonusTick(d, { tone() {}, fx: {} });
}
d.bonusRound.over = false;
}
// The stage select goes straight into it.
const pick = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } });
pick.resize(900, 900);
pick.stageSelect();
const p = pick.round;
const at = ghoul.STAGES.findIndex((s) => s.id === "grounds");
for (let i = 0; i < at; i++) ghoul.steerSelect(p, 1, 0);
for (let i = 0; i < 3; i++) ghoul.steerSelect(p, 0, 1);
assert.equal(p.select.room, 3);
pick.tick(16);
ghoul.takeSelect(p);
assert.equal(p.spec.id, "mower");
assert.equal(p.runner.line, 0);
assert.equal(p.you.y, LANE);
pick.tick(16);
});
/* ----------------------------------------------------------- the bots */
// A bot that plays well: it jumps at the end of a line, 6 to 15 short of junk or a snapping beast, ducks under
// every low, and works the blades: fire while there is grass, a weed or a thorn hedge in reach (and cool), a
// jump over a hedge when the blades are jammed. `miss` is the share of things it fails to dodge (by a hash).
const mix = (a, b) => {
let h = Math.imul(a + 0x9e37, 0x85ebca6b) ^ Math.imul(b + 0x7f4a, 0xc2b2ae35);
h ^= h >>> 13;
h = Math.imul(h, 0x5bd1e995);
h ^= h >>> 15;
return (h >>> 0) / 4294967296;
};
function goodBot(round, seed, miss = 0.04) {
const { you, runner: c, input: inp } = round;
inp.left = inp.right = inp.down = false;
if (round.phase !== "play" || !c || c.done) {
inp.up = false;
inp.fire = false;
return;
}
const ok = (x) => mix(seed, Math.round(x)) >= miss;
const look = 9 + (seed % 7);
let jump = false;
let fire = false;
if (c.line >= 0) {
if (lines[c.line].x1 - you.x < 2.2 && c.line < lines.length - 1 && ok(lines[c.line].x1)) jump = true;
const ahead = (x) => x - you.x > 6 && x - you.x < look;
for (const [x] of R.junk) if (ahead(x) && ok(x)) jump = true;
R.hedges.forEach((x, i) => {
if (c.hedges[i]) return;
const away = x - you.x;
if (away > -2 && away < mw.BLADE_REACH + 4) fire = true;
if (ahead(x) && (c.jam > 0 || c.heat > 0.85) && ok(x)) jump = true;
});
R.beasts.forEach((x, i) => {
const b = c.beasts[i];
if (b.state === "broken" || b.state === "spent" || b.state === "sink") return;
if (x - you.x > 0 && x - you.x < 36) fire = true;
if (b.state === "snap" && ahead(x) && x - you.x < 11 && ok(x)) jump = true;
});
for (const [x0, x1] of R.lows) if (you.x > x0 - 10 && you.x < x1 + 3 && ok(x0)) inp.down = true;
// Grass and weeds in reach.
R.grass.forEach((gr, i) => {
if (gr[1] > you.x && gr[0] < you.x + mw.BLADE_REACH && c.grass[i].some((cell) => !cell)) fire = true;
});
R.weeds.forEach((x, i) => {
if (!c.weeds[i] && x > you.x - 1 && x < you.x + mw.BLADE_REACH + 3) fire = true;
});
}
inp.fire = fire && c.heat < 0.93;
if (jump && !inp.down) press(round);
else inp.up = false;
}
function idleBot(round) {
const inp = round.input;
inp.left = inp.right = inp.down = false;
inp.up = false;
inp.fire = true;
}
function rideWith(seed, bot, limit = 100000) {
const round = mowerRound(seed);
const lost = [];
let t = 0;
for (; t < limit && round.phase !== "clear" && !round.over; t += 16) {
bot(round);
if (round.runner && round.runner.done && round.phase === "play") round.input.right = true;
ghoul.advance(round, 16, steady);
for (const e of round.events) if (e.type === "lose") lost.push(e.cause);
if (round.runner && !round.runner.done) {
const off = round.you.x - round.camX;
assert.ok(off > 4 && off < 70, `the mower 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 Gardener's Revenge: a bot that plays well finishes the whole lawn in 60 to 78 seconds, 7 to 9 dice, past every checkpoint, most of the lawn cut", () => {
const dice = [];
for (let seed = 1; seed <= 12; seed++) {
const { round, lost, ms } = rideWith(seed, (r) => goodBot(r, seed));
const b = round.bonusRound;
assert.equal(b.won, true, `seed ${seed} finished (lost ${lost.join(",")}, lawn ${(round.runner.lawn * 100).toFixed(0)}%)`);
assert.ok(ms > 60000 && ms < 78000, `${ms} ms`);
assert.ok(b.dice >= 6 && b.dice <= ghoul.MAX_DICE, `${b.dice} dice (lawn ${(round.runner.lawn * 100).toFixed(0)}%, acts ${b.perf.acts}, lost ${lost.join(",")})`);
assert.equal(round.lives, 3, "never a run life");
assert.equal(round.runner.check, R.checks.length - 1, "past every checkpoint");
assert.ok(round.runner.lawn >= mw.LAWN_GOAL, `lawn ${(round.runner.lawn * 100).toFixed(0)}%`);
dice.push(b.dice);
}
assert.ok(dice.reduce((a, b) => a + b, 0) / dice.length >= 7, `${dice.join(",")}`);
});
test("Ghoul Rush's Gardener's Revenge: a bot that dodges well but holds fire the whole way jams the blades again and again, cuts under the lawn goal (no steady die) and earns fewer dice than one that pulses them", () => {
for (let seed = 1; seed <= 4; seed++) {
let jams = 0;
let was = 0;
const holder = rideWith(seed, (r) => {
goodBot(r, seed);
r.input.fire = true;
if (r.runner) {
if (r.runner.jam > 0 && !was) jams++;
was = r.runner.jam > 0 ? 1 : 0;
// It jumps a thorn hedge it cannot cut while the blades are jammed.
if (r.runner.line >= 0) R.hedges.forEach((x, i) => (!r.runner.hedges[i] && x - r.you.x > 6 && x - r.you.x < 12 && r.runner.jam > 0 ? press(r) : null));
}
});
const pulser = rideWith(seed, (r) => goodBot(r, seed));
assert.ok(jams >= 8, `jammed ${jams} times`);
assert.equal(holder.round.bonusRound.won, true, `seed ${seed} finished`);
assert.ok(holder.round.runner.lawn < mw.LAWN_GOAL, `lawn ${holder.round.runner.lawn}`);
assert.equal(holder.round.bonusRound.perf.steady, false);
assert.ok(holder.round.bonusRound.dice < pulser.round.bonusRound.dice, `${holder.round.bonusRound.dice} dice to ${pulser.round.bonusRound.dice}`);
}
});
test("Ghoul Rush's Gardener's Revenge: 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 (let seed = 1; seed <= 6; seed++) {
const { round, lost } = rideWith(seed, idleBot);
const b = 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}`);
assert.equal(round.lives, 3);
assert.equal(round.over, false);
}
});
/* ------------------------------------------------------------ telegraphs */
test("Ghoul Rush's Gardener's Revenge telegraphs: DUCK over arches and lines, JUMP over ponds, ditches and junk, CUT over thorn hedges, none for beasts, weeds or grass, words only on the first three of each kind, the same every time", () => {
const marks = telegraphMarks(R);
assert.equal(marks.length, R.gaps.length + R.junk.length + R.hedges.length + R.lows.length);
for (const m of marks) assert.equal(m.answer, ANSWERS[m.kind], m.kind);
assert.deepEqual(new Set(marks.map((m) => m.kind)), new Set(["pond", "ditch", "junk", "hedge", "arch", "line"]));
R.lows.forEach(([x0, x1, y, kind]) => {
const m = marks.find((q) => q.x === (x0 + x1) / 2);
assert.equal(m.kind, kind ? "line" : "arch");
assert.equal(m.answer, "DUCK");
});
for (const x of R.hedges) assert.equal(marks.find((q) => q.kind === "hedge" && q.x === x).answer, "CUT");
const m = marks.find((q) => q.kind === "junk");
const xs = [m.lead - 45, m.lead - 41, m.lead - 36, m.lead - 30, m.lead - 10, m.lead, m.lead + 3, m.lead + 7];
const alphaOf = (x) => (telegraphs(R, x).find((t) => t.kind === "junk" && t.lead === m.lead) || { alpha: 0 }).alpha;
const a = xs.map(alphaOf);
assert.equal(a[0], 0, "not yet in view");
assert.ok(a[2] > 0 && a[2] < 1, "fading in 40 to 30 ahead");
assert.equal(a[3], 1);
assert.equal(a[4], 1);
assert.ok(a[6] > 0 && a[6] < 1, "fading as it passes");
assert.equal(a[7], 0, "gone once passed");
assert.deepEqual(telegraphs(R, m.lead - 33), telegraphs(R, m.lead - 33), "deterministic");
for (const kind of ["pond", "ditch", "junk", "hedge", "arch", "line"]) {
const of = marks.filter((q) => q.kind === kind).sort((p, q) => p.lead - q.lead);
assert.ok(of.length >= 3, kind);
of.forEach((q, i) => {
assert.equal(q.n, i);
const shown = telegraphs(R, q.lead - 32).find((t) => t.lead === q.lead);
assert.equal(shown.words, i < 3, `${kind} ${i}`);
});
}
});
test("Ghoul Rush's Gardener's Revenge's intro banner says the controls plainly", () => {
assert.match(R.how, /UP to jump, DOWN to duck/);
assert.match(R.how, /mow/);
});
File diff suppressed because it is too large. Load diff
@@ -4,6 +4,7 @@
import test from "node:test";
import assert from "node:assert/strict";
import * as ghoul from "../src/web-console/public/activities/ghoul.js";
import { skipStory as storySkip } from "../src/web-console/public/activities/ghoul-story.js";
import { MERCY_FAR, MERCY_NEAR, mercyKind, mercySpot, mix3 } from "../src/web-console/public/activities/ghoul-powers.js";
const steady = () => 0.5;
@@ -57,6 +58,13 @@ function die(round, cause = "zombie") {
const everyRoom = () => ghoul.STAGES.flatMap((st, si) => st.rooms.map((id, ri) => ({ st, si, ri, id })));
const special = (round) => Boolean(round.spec.ride || round.spec.bonus || round.bonusRound);
// Past the intro story at once (it has its own tests): a run opens on it, and the tests that play from the hall skip it.
function skipStory(g) {
if (g.round.phase !== "story") return;
storySkip(g.round);
g.tick(0);
}
test("Ghoul Rush retry mercy: the first attempt of a room spawns nothing, the second exactly one power-up a few steps ahead of Planny on the floor", () => {
const round = inRoom(-1, 0);
assert.equal(mercies(round).length, 0);
@@ -298,6 +306,7 @@ test("Ghoul Rush retry mercy: the game draws the pickup, its shimmer and its wor
const g = ghoul.default.create({ canvas });
g.resize(900, 900);
g.key("action");
skipStory(g);
g.round.dice = 0;
for (let ms = 0; ms < 4000; ms += 16) g.tick(16);
const r = g.round;
@@ -10,6 +10,7 @@ import { VOICES, react } from "../src/web-console/public/activities/ghoul-draw.j
const steady = () => 0.5;
const events = (round, type) => round.events.filter((e) => e.type === type);
// The four rooms that are walked, and the stage's five with the bonus gurney ride between the Theater and the Ward (its own suite: ghoul-gurney).
const ROOM_IDS = ["admissions", "baths", "theater", "ward"];
function through(round) {
@@ -84,7 +85,7 @@ const heard = (e, extra = {}) => {
test("Ghoul Rush's Blackmoor Sanatorium is a stage of three rooms and the Night Ward, its monsters and boss joined to the game's, with two power-ups of its own and a place for each kind", () => {
const st = ghoul.stageById("sanatorium");
assert.deepEqual(st.rooms, ROOM_IDS);
assert.deepEqual(st.rooms, ["admissions", "baths", "theater", "codeblue", "ward"]);
assert.equal(st.boss, "matron");
assert.equal(st.title, "Blackmoor Sanatorium");
assert.equal(st.sub, "Visiting hours ended in 1912");
@@ -92,7 +93,7 @@ test("Ghoul Rush's Blackmoor Sanatorium is a stage of three rooms and the Night
assert.equal(ghoul.BOSSES.matron, sn.BOSSES.matron);
assert.equal(sn.BOSSES.matron.sub, "Stay out of her lantern light");
for (const id of st.rooms) assert.ok(ghoul.ROOM_MUSIC[id], `${id} has music`);
const [admissions, baths, theater, ward] = st.rooms.map((id) => ghoul.roomById(id));
const [admissions, baths, theater, ward] = ROOM_IDS.map((id) => ghoul.roomById(id));
const returning = ["zombie", "crawl", "ghost", "spitter"];
for (const room of [admissions, baths, theater]) {
assert.ok(room.key, `${room.id}: a key`);
@@ -3,6 +3,7 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import * as ghoul from "../src/web-console/public/activities/ghoul.js";
import { skipBossIntro } from "./ghoul-test-helpers.mjs";
import * as sl from "../src/web-console/public/activities/ghoul-sled.js";
import * as ct from "../src/web-console/public/activities/ghoul-cart.js";
import { EVENT_VOICE, LOSE_SOUNDS, LOSE_WORDS, LOOKS as SLED_LOOKS, VOICES as SLED_VOICES, telegraphMarks, telegraphs } from "../src/web-console/public/activities/ghoul-sled-draw.js";
@@ -102,7 +103,7 @@ test("Ghoul Rush's Coffin Sled is the Frozen Lake's fourth room, between the Bla
const st = ghoul.stageById("frozen");
assert.deepEqual(st.rooms, ["huts", "lodge", "blackice", "sled", "widow"]);
assert.equal(st.boss, "frostwidow");
assert.equal(ghoul.STAGES.at(-1), st, "still the last stage in the list");
assert.equal(ghoul.STAGES.at(-2), st, "the last stage in the list but Gallows Bog");
assert.deepEqual([ROOM.title, ROOM.sub], ["Coffin Sled", "Hold on. The hill is longer than it looks"]);
assert.equal(ROOM.dark, false, "a moonlit night, always lit");
assert.equal(ROOM.key, null);
@@ -540,6 +541,8 @@ test("Ghoul Rush's Coffin Sled: the last heart gone ends the round with nothing
assert.equal(round.sled, null);
assert.equal(round.lives, 3);
assert.equal(round.dice, 2);
assert.equal(round.phase, "bossintro", "the boss room opens on its card");
skipBossIntro(ghoul, round);
assert.equal(round.phase, "ready");
});
@@ -0,0 +1,455 @@
// Web console tests, Ghoul Rush's intro story: 6 to 8 pages that fit the field, never name the hero, stay generic about stages (no names, no counts) and speak to YOU; a run opens on it and ends in The Long Hall; the lockout, the typing that finishes first, every key and a click, the skip by holding fire, a pause that holds it; never in the practice stage select, on a respawn or in a new room; every page draws on a fake canvas at many moments; every sound it asks for exists.
import { test } from "node:test";
import assert from "node:assert/strict";
import * as ghoul from "../src/web-console/public/activities/ghoul.js";
import ghoulSfx from "../src/web-console/public/activities/ghoul-sfx.js";
import { INTROS } from "../src/web-console/public/activities/ghoul-intros.js";
import {
CHAR_MS,
FINALE_TITLE,
LAST_HINT,
MAX_LINE,
PAGES,
RELOCK_MS,
REVEAL_AT_MS,
SKIP_HINT,
SKIP_HOLD_MS,
STORY_HINT,
STORY_LOCK_MS,
beginStory,
endStory,
lineAt,
pageChars,
pressStory,
releaseStory,
revealEnd,
shown,
skipStory,
stepStory,
takeStory,
typed,
} from "../src/web-console/public/activities/ghoul-story.js";
import { SCENE_H, TEXT_SIZE } from "../src/web-console/public/activities/ghoul-story-draw.js";
import { toneNames } from "../src/web-console/public/tones.js";
const steady = () => 0.5;
const DASH = String.fromCharCode(0x2014);
const ALL = PAGES.flatMap((p) => [p.chapter, ...p.lines]).join("\n");
function fakeCtx(texts) {
return new Proxy({}, {
get: (t, name) => (name in t ? t[name] : name === "fillText" ? (s) => texts.push(s) : () => {}),
set: (t, name, value) => ((t[name] = value), true),
});
}
// A window game with the story up (a real run's first press), and its sounds.
function openGame(extra = {}) {
const texts = [];
const sounds = [];
const hums = [];
const ctx = fakeCtx(texts);
const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx }, tone: (name) => sounds.push(name), hum: (id, name) => hums.push([id, name]), ...extra });
g.resize(900, 900);
g.key("action");
return { g, texts, sounds, hums };
}
const tick = (g, ms) => {
for (let t = 0; t < ms; t += 16) g.tick(16);
};
// To the point where a press counts on the page the game is on (and the typing is still going unless it is long past).
const lock = (g) => tick(g, STORY_LOCK_MS + 20);
// To the end of the typing.
const typedOut = (g) => tick(g, revealEnd(PAGES[g.round.story.page]) - g.round.story.ms + 40);
test("Ghoul Rush story: 6 to 8 pages, 2 to 4 short lines each, no em dash, never the hero's name, and YOU on every page", () => {
assert.ok(PAGES.length >= 6 && PAGES.length <= 8, `${PAGES.length} pages`);
assert.equal(new Set(PAGES.map((p) => p.id)).size, PAGES.length, "unique ids");
const field = ghoul.FIELD_W;
for (const p of PAGES) {
assert.ok(p.chapter && p.scene && p.pal.sky && p.pal.ground && p.pal.a && p.pal.glow, `${p.id} has a heading, a scene and colors`);
assert.ok(p.lines.length >= 2 && p.lines.length <= 4, `${p.id} has 2 to 4 lines`);
const text = [p.chapter, ...p.lines].join("\n");
assert.ok(!text.includes(DASH), `${p.id} has no em dash`);
assert.ok(!/planny|the player|the hero|\bhero\b/i.test(text), `${p.id} never names the hero`);
assert.ok(/\bYOU(R)?\b/.test(text), `${p.id} speaks to YOU`);
for (const line of p.lines) {
assert.ok(line.length <= MAX_LINE, `${p.id}: "${line}" is ${line.length} characters`);
// The same width guess the intro card's test uses (0.62 em a letter), at the story's own size.
assert.ok(line.length * TEXT_SIZE * 0.62 <= field - 1, `${p.id}: "${line}" fits the field`);
}
for (const [at, name, vol, rate] of p.cues) {
assert.ok(at >= 0 && at < 9000 && vol > 0 && vol <= 1 && rate > 0, `${p.id}: a cue is timed and audible`);
assert.ok(toneNames().includes(name) || Object.hasOwn(ghoulSfx.tones, name), `${p.id}: ${name} is a tone`);
}
}
assert.ok(ALL.includes("YOU"));
const lines = PAGES.flatMap((p) => p.lines);
assert.equal(new Set(lines).size, lines.length, "no line used twice");
const cards = new Set(Object.values(INTROS).flatMap((i) => i.lines));
assert.ok(lines.every((l) => !cards.has(l)), "no line copied from a stage's card");
assert.ok(PAGES[PAGES.length - 1].scene === "begin" && FINALE_TITLE === "THE RUN BEGINS", "the last page is the run beginning");
});
test("Ghoul Rush story: it names the house and the way in, and stays generic about stages (no names, no counts)", () => {
const text = ALL.toLowerCase();
assert.ok(text.includes("marrow manor"), "the house has a name");
assert.ok(text.includes("flashlight") && text.includes("flinch"), "what YOU carry, and what it does to the house");
assert.ok(text.includes("fright"), "what it eats");
assert.ok(text.includes("long hall"), "the way in");
assert.ok(text.includes("starves"), "what happens if YOU escape");
assert.ok(/inside/.test(text), "the places are inside the house");
// More stages will come: the story never names one (the house itself, Marrow Manor, is not the stage The Manor).
for (const st of ghoul.STAGES) {
const name = st.title.replace(/^The /, "").toLowerCase();
if (name === "manor") continue;
assert.ok(!text.includes(name), `the story does not name the stage ${st.title}`);
}
const named = ["east wing", "graveyard", "grounds", "chapel", "sanatorium", "blackmoor", "hollow end", "deep seam", "midnight carnival", "frozen lake", "pit beneath"];
for (const n of named) assert.ok(!text.includes(n), `the story does not name ${n}`);
assert.ok((text.match(/carnival/g) || []).length <= 1, "at most one passing example of a place");
});
test("Ghoul Rush story: no page names a count of stages, rooms, doors or keepers", () => {
const count = /\b(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|twenty|\d+)\b[\s-]+(\w+\s+)?(stages?|rooms?|doors?|keepers?|levels?|places?|worlds?|bosses)\b/i;
for (const p of PAGES) {
for (const line of [p.chapter, ...p.lines]) {
assert.ok(!/\d/.test(line), p.id + ": no digit in " + line);
assert.ok(!count.test(line), p.id + ": " + line + " names a count");
}
}
assert.ok(!/\b(ten|all ten|every one of the)\b/i.test(ALL), "no ten anywhere in the story");
// The check itself catches what it should.
assert.ok(count.test("Ten rooms, ten keepers") && count.test("seven doors") && count.test("3 stages") && !count.test("Door after door"));
});
test("Ghoul Rush story: the typing, the lines and the page numbers add up", () => {
const pg = PAGES[2];
assert.equal(pageChars(pg), pg.lines.reduce((n, l) => n + l.length, 0));
assert.equal(shown(pg, 0), 0);
assert.equal(shown(pg, REVEAL_AT_MS), 0);
assert.equal(shown(pg, REVEAL_AT_MS + CHAR_MS * 5), 5);
assert.equal(shown(pg, 1e9), pageChars(pg));
assert.equal(shown(pg, 0, true), pageChars(pg), "full shows everything at once");
assert.equal(revealEnd(pg), REVEAL_AT_MS + pageChars(pg) * CHAR_MS);
assert.ok(revealEnd(pg) < 9000, "a page types out in a few seconds");
assert.deepEqual(typed(pg, 0), pg.lines.map(() => ""));
assert.deepEqual(typed(pg, pageChars(pg)), pg.lines);
const half = typed(pg, pg.lines[0].length + 3);
assert.equal(half[0], pg.lines[0]);
assert.equal(half[1], pg.lines[1].slice(0, 3));
assert.equal(lineAt(pg, 0), 0);
assert.equal(lineAt(pg, pg.lines[0].length), 1);
assert.equal(lineAt(pg, pageChars(pg)), pg.lines.length - 1);
});
test("Ghoul Rush story: a run opens on it with the hall behind it, and it ends in The Long Hall, announced then", () => {
const r = ghoul.newRound(3);
assert.equal(r.phase, "play", "the round itself still starts in the hall (the window adds the story)");
assert.equal(r.story, undefined);
beginStory(r);
assert.equal(r.phase, "story");
assert.equal(r.story.page, 0);
assert.equal(r.spec.id, "hall", "the hall is set up behind it");
assert.deepEqual(r.events.filter((e) => e.type === "storyPage").map((e) => e.page), [0]);
assert.equal(r.events.some((e) => e.type === "room"), false, "no room is announced yet");
// Nothing in the hall moves while it is up.
r.input.right = true;
const x = r.you.x;
ghoul.advance(r, 2000, steady);
assert.equal(r.you.x, x);
assert.equal(r.phase, "story");
r.events.length = 0;
endStory(r);
assert.equal(r.phase, "play");
assert.equal(r.story, null);
assert.equal(r.spec.id, "hall", "the run's first room is the hall");
assert.equal(r.room, 1);
assert.deepEqual(r.events.filter((e) => e.type === "room").map((e) => e.room), [1]);
assert.ok(r.events.some((e) => e.type === "storyEnd"));
});
test("Ghoul Rush story: a press turns a page only after the lockout, typing finishes first, and the last page enters the hall", () => {
const r = ghoul.newRound(3);
beginStory(r);
assert.equal(takeStory(r), false, "not at once");
ghoul.advance(r, STORY_LOCK_MS - 40, steady);
assert.equal(takeStory(r), false, "not before the lockout");
assert.equal(r.story.page, 0);
ghoul.advance(r, 60, steady);
// Typing still going: the first press finishes it, the page stays.
assert.ok(r.story.ms < revealEnd(PAGES[0]));
assert.equal(takeStory(r), true);
assert.equal(r.story.page, 0, "the page has not turned");
assert.equal(r.story.full, true, "the typing is done");
assert.equal(takeStory(r), false, "a second press right on top of it does not count");
ghoul.advance(r, RELOCK_MS + 20, steady);
assert.equal(takeStory(r), true);
assert.equal(r.story.page, 1, "now the page turns");
assert.equal(r.story.ms, 0);
assert.equal(r.story.full, false);
assert.equal(takeStory(r), false, "each page has its own lockout");
// Through every page the way a patient reader would: wait out the typing, press once.
for (let at = 1; at < PAGES.length; at++) {
assert.equal(r.story.page, at);
ghoul.advance(r, revealEnd(PAGES[at]) + 20, steady);
assert.equal(takeStory(r), true);
}
assert.equal(r.phase, "play", "the last page's press enters the hall");
assert.equal(r.story, null);
assert.equal(takeStory(r), false, "nothing to take after");
assert.equal(r.spec.id, "hall");
});
test("Ghoul Rush story: the window's keys, any move and fire alike, turn pages; repeats and early presses never do; a click does", () => {
for (const name of ["left", "right", "up", "down", "action"]) {
const { g } = openGame();
assert.equal(g.round.phase, "story", `${name}: a run opens on the story`);
assert.equal(g.round.input.fire, false, "the press that starts never fires");
g.key(name);
assert.equal(g.round.story.page, 0, `${name}: early press ignored`);
assert.equal(g.round.story.full, false);
lock(g);
g.key(name, true);
assert.equal(g.round.story.full, false, `${name}: a repeat is ignored`);
g.release(name);
g.key(name);
assert.equal(g.round.story.full, true, `${name}: a fresh press finishes the typing first`);
tick(g, RELOCK_MS + 40);
g.key(name, true);
assert.equal(g.round.story.page, 0, `${name}: a repeat never turns the page`);
g.release(name);
g.key(name);
assert.equal(g.round.story.page, 1, `${name}: the next press turns it`);
assert.equal(g.round.input.fire, false, `${name}: no shot is fired at the story`);
assert.equal(g.round.input.up || g.round.input.left || g.round.input.right || g.round.input.down, false, `${name}: no move is kept`);
assert.equal(g.round.you.x, ghoul.roomById("hall").start, `${name}: YOU has not moved`);
}
const { g } = openGame();
g.pointer("down", 10, 10);
assert.equal(g.round.story.page, 0, "a click before the lockout does nothing");
lock(g);
g.pointer("move", 10, 10);
g.pointer("up", 10, 10);
assert.equal(g.round.story.full, false);
g.pointer("down", 10, 10);
assert.equal(g.round.story.full, true, "a click finishes the typing first");
tick(g, RELOCK_MS + 40);
g.pointer("down", 10, 10);
assert.equal(g.round.story.page, 1, "and the next click turns the page");
});
test("Ghoul Rush story: holding fire for a second skips the whole story, a tap or a short hold does not, and the bar shows it", () => {
const { g, texts } = openGame();
// A fire held from the start: the key's repeats never start the clock.
for (let k = 0; k < 30; k++) g.key("action", true);
tick(g, 2000);
assert.equal(g.round.phase, "story", "a held key from the run's own press never skips");
assert.equal(g.round.story.hold, -1);
// Too short a hold.
const { g: h } = openGame();
h.key("action");
assert.equal(h.round.story.hold, 0, "a fresh press starts the clock");
tick(h, SKIP_HOLD_MS - 200);
assert.equal(h.round.phase, "story");
assert.ok(h.round.story.hold > 0);
texts.length = 0;
h.release("action");
assert.equal(h.round.story.hold, -1, "let go stops the clock");
tick(h, 2000);
assert.equal(h.round.phase, "story");
// Held the whole second: the story is over at once, whatever page it was on, and the hall is announced.
const { g: k, sounds } = openGame();
lock(k);
k.key("action");
k.key("action", true);
tick(k, SKIP_HOLD_MS + 100);
assert.equal(k.round.phase, "play", "the hold skipped the story");
assert.equal(k.round.story, null);
assert.equal(k.round.spec.id, "hall");
assert.ok(k.round.page === undefined);
assert.ok(sounds.includes("ghoulRoomIn"), "the hall's door sounds as the run starts");
// The skip bar draws while it is held, the hint on every page.
const { g: m, texts: seen } = openGame();
m.key("action");
tick(m, 500);
assert.ok(seen.includes(SKIP_HINT.toUpperCase()), "the skip hint shows");
assert.ok(m.round.story.hold >= 400);
// skipStory and pressStory are the plain functions behind it.
const r = ghoul.newRound(1);
assert.equal(skipStory(r), false, "no story, nothing to skip");
beginStory(r);
assert.equal(pressStory(r, true), false, "a repeat is nothing");
assert.equal(pressStory(r, false), true);
assert.equal(r.story.hold, 0);
stepStory(r, SKIP_HOLD_MS - 1);
assert.equal(r.phase, "story");
releaseStory(r);
assert.equal(r.story.hold, -1);
assert.equal(skipStory(r), true);
assert.equal(r.phase, "play");
});
test("Ghoul Rush story: a pause holds it, the hint of every page shows once a press counts, and the skip hint is always up", () => {
const { g, texts } = openGame();
tick(g, 100);
g.pause();
const held = g.round.story.ms;
tick(g, 2000);
assert.equal(g.round.story.ms, held, "a pause holds the page's clock");
g.key("action");
g.key("left");
assert.equal(g.round.story.hold, -1, "no key counts while paused");
assert.equal(g.round.story.page, 0);
g.resume();
tick(g, 100);
assert.ok(g.round.story.ms > held);
// Every page: the skip hint, the heading, the page's text, and the hint once a press counts.
for (let at = 0; at < PAGES.length; at++) {
g.round.story = { page: at, ms: 0, full: false, arm: 0, hold: -1, cue: 99, shown: 0 };
texts.length = 0;
g.tick(1);
assert.ok(texts.includes(SKIP_HINT.toUpperCase()), `page ${at + 1} shows how to skip`);
assert.equal(texts.includes(STORY_HINT) || texts.includes(LAST_HINT), false, "no continue hint inside the lockout");
g.round.story.ms = STORY_LOCK_MS + 100;
texts.length = 0;
g.tick(1);
assert.ok(texts.includes(at === PAGES.length - 1 ? LAST_HINT : STORY_HINT), `page ${at + 1} shows the continue hint once a press counts`);
assert.ok(texts.includes(PAGES[at].chapter), `page ${at + 1} shows its heading`);
g.round.story.ms = 60000;
g.round.story.full = true;
texts.length = 0;
g.tick(1);
for (const line of PAGES[at].lines) assert.ok(texts.includes(line), `page ${at + 1}: "${line}" is drawn in full`);
}
});
test("Ghoul Rush story: never in the practice stage select, on a respawn or in a new room, and a new run shows it again", () => {
const { g } = openGame();
assert.equal(g.round.phase, "story");
g.stageSelect();
assert.equal(g.round.phase, "select", "the stage select opens on its list, not the story");
assert.equal(g.round.story, undefined);
assert.equal(g.round.practice, true);
g.key("action");
assert.notEqual(g.round.phase, "story", "and a room taken from it goes on");
// A real run: skip it, then a lost life and a new room never bring it back.
const { g: h } = openGame();
skipStory(h.round);
h.tick(16);
assert.equal(h.round.phase, "play");
h.round.dice = 0;
h.round.you.safeMs = 0;
ghoul.lose(h.round, "zombie");
tick(h, ghoul.CRASH_MS + 400);
assert.notEqual(h.round.phase, "story", "no story on a respawn");
assert.equal(h.round.story, null);
h.round.phase = "clear";
h.round.phaseMs = 1;
h.tick(16);
assert.notEqual(h.round.phase, "story", "no story in a new room");
assert.equal(h.round.phase, "pick", "the hall's door leads to the stage pick, never the story");
h.round.phaseMs = 0;
ghoul.pickStage(h.round);
assert.equal(h.round.phase, "intro", "and a stage opens on its own card");
tick(h, ghoul.INTRO_MIN_MS + 100);
ghoul.takeIntro(h.round);
tick(h, ghoul.READY_MS + 200);
assert.equal(h.round.phase, "play");
// The end screen and a new run: the story again.
h.round.lives = 1;
h.round.dice = 0;
h.round.infinite = false;
ghoul.lose(h.round, "zombie");
for (let k = 0; k < 300 && h.state === "running"; k++) h.tick(16);
assert.equal(h.state, "over");
h.key("action");
assert.equal(h.state, "running");
assert.equal(h.round.phase, "story", "every new run opens on it");
assert.equal(h.round.story.page, 0);
// The pure round never has it (the tests that walk the rules rely on that).
assert.equal(ghoul.newRound(9).phase, "play");
});
test("Ghoul Rush story: its sounds play (a drone under it, its timed tones, a page turn, the hall's door) and the hall's music waits", () => {
const { g, sounds, hums } = openGame();
const music = [];
tick(g, 1200);
assert.ok(hums.some(([id, name]) => id === "ghoul:story" && name === "ghoulStoryDrone"), "the story's drone runs under it");
assert.ok(hums.every(([id]) => id === "ghoul:story"), "no monster or house hum under the story");
assert.ok(Object.hasOwn(ghoulSfx.hums, "ghoulStoryDrone"));
const first = PAGES[0].cues[0][1];
assert.ok(sounds.includes(first), `${first} plays at the first page's start`);
assert.ok(sounds.includes("tickSoft"), "a soft blip while it types");
lock(g);
typedOut(g);
tick(g, RELOCK_MS + 40);
sounds.length = 0;
g.key("left");
g.tick(16);
assert.equal(g.round.story.page, 1);
assert.ok(sounds.includes("ghoulStoryPage"), "a page turn rustles");
assert.equal(music.length, 0);
// Every tone and hum the story owns keeps this game's prefix.
for (const name of Object.keys(ghoulSfx.tones)) if (name.startsWith("ghoulStory")) assert.match(name, /^ghoulStory[A-Z]/);
assert.ok(Object.keys(ghoulSfx.tones).filter((n) => n.startsWith("ghoulStory")).length >= 8, "a handful of house tones");
});
test("Ghoul Rush story: endless lives and the stage code are untouched by it", () => {
const { g } = openGame();
g.cheat(true);
assert.equal(g.round.infinite, true);
lock(g);
g.key("up");
assert.equal(g.round.infinite, true, "the code survives the story");
skipStory(g.round);
g.tick(16);
g.round.lives = 1;
ghoul.lose(g.round, "zombie");
tick(g, ghoul.CRASH_MS + 400);
assert.equal(g.round.lives, 1, "no life is lost with the code on");
assert.equal(g.state, "running");
});
test("Ghoul Rush story: every page draws on a fake canvas at many moments, the finale's title letter by letter, without throwing", () => {
for (let at = 0; at < PAGES.length; at++) {
const texts = [];
const ctx = fakeCtx(texts);
const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } });
g.resize(900, 900);
g.key("action");
for (const ms of [0, 1, 120, 450, 900, 1500, 2300, 3100, 4000, 5200, 6500, 8000, 12000, 40000]) {
for (const full of [false, true]) {
for (const hold of [-1, 500]) {
g.round.story = { page: at, ms, full, arm: 0, hold, cue: 99, shown: 0 };
g.tick(1);
}
}
}
assert.ok(texts.some((t) => PAGES[at].chapter === t), `page ${at + 1} draws its heading`);
if (at === PAGES.length - 1) {
g.round.story = { page: at, ms: 6000, full: true, arm: 0, hold: -1, cue: 99, shown: 0 };
texts.length = 0;
g.tick(1);
for (const ch of FINALE_TITLE) if (ch !== " ") assert.ok(texts.includes(ch), `the finale draws ${ch}`);
}
}
assert.ok(SCENE_H > 20 && SCENE_H < 40, "the scene keeps to the top of the field");
});
test("Ghoul Rush story: the whole run still goes through it on a real clock, from the first press to the hall, ready to play", () => {
const { g, texts } = openGame();
assert.equal(g.round.phase, "story");
let guard = 0;
while (g.round.phase === "story" && guard++ < 40) {
typedOut(g);
tick(g, RELOCK_MS + 40);
g.key("right");
g.release("right");
}
assert.equal(g.round.phase, "play");
assert.equal(g.round.spec.id, "hall");
texts.length = 0;
tick(g, 100);
assert.ok(texts.some((t) => String(t).includes("The Long Hall")), "the hall is announced once the story is out");
});
@@ -0,0 +1,894 @@
// 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
import { test } from "node:test";
import assert from "node:assert/strict";
import * as ghoul from "../src/web-console/public/activities/ghoul.js";
import { skipBossIntro } from "./ghoul-test-helpers.mjs";
import * as tr from "../src/web-console/public/activities/ghoul-tray.js";
import * as ct from "../src/web-console/public/activities/ghoul-cart.js";
import * as sl from "../src/web-console/public/activities/ghoul-sled.js";
import { EVENT_VOICE, LOSE_SOUNDS, LOSE_WORDS, LOOKS as TRAY_LOOKS, VOICES as TRAY_VOICES, telegraphMarks, telegraphs } from "../src/web-console/public/activities/ghoul-tray-draw.js";
import * as ghoulSfx from "../src/web-console/public/activities/ghoul-sfx.js";
import { LOOKS, VOICES, bonusTick, react } from "../src/web-console/public/activities/ghoul-draw.js";
import { BONUS_FLOOR, diceFor, endBonus, makeBonus } from "../src/web-console/public/activities/ghoul-bonus.js";
const steady = () => 0.5;
// The pack draws no random number: a run on this fails on the first draw.
const never = () => {
throw new Error("the tray drew a random number");
};
const events = (round, type) => round.events.filter((e) => e.type === type);
function through(round) {
round.phase = "clear";
round.phaseMs = 1;
ghoul.advance(round, 4, steady);
}
// A round in the Servants' Back Stairs reached the way play reaches it, nothing woken, the clocks
// long, the bonus round on (five hearts).
function trayRound(seed = 5) {
const round = ghoul.newRound(seed);
round.lives = 3;
round.dice = 0;
through(round);
round.offer = ["wing"];
round.phaseMs = 0;
ghoul.pickStage(round, 0);
while (round.spec.id !== "tray") through(round);
round.phase = "play";
for (const st of round.spawns) st.over = true;
round.monsters.length = 0;
round.hordeMs = Infinity;
round.timeMs = 1e9;
round.bonus = 1e9;
round.events.length = 0;
return round;
}
const NONE = { runner: "tray", time: 1e9, finish: 1e6, track: [], pots: [], lows: [], cooks: [], domes: [], plates: [], grease: [], checks: [] };
// The same round over a ride of its own (a plain track to measure the tray on).
function synth(ride) {
const round = trayRound();
round.runner = null;
round.spec = { ...round.spec, start: 10, ground: [[0, 5, 0]], ride: { ...NONE, ...ride } };
tr.TRAY.place[0](round, {});
return round;
}
const FLAT = [[[0, 20], [4000, 20]]];
const DOWN = [[[0, 40], [4000, 40 - 0.15 * 4000]]];
const UP = [[[0, 0], [4000, 0.3 * 4000]]];
// The tray on line `line` of the ride at `x`, at speed `v`.
function trayAt(round, x, line, { v = tr.TRAY_V, safe = false } = {}) {
const y = ct.trackY(round.spec.ride, line, x);
assert.ok(y !== null, `line ${line} runs under ${x}`);
Object.assign(round.you, { x, y, vy: 0, state: "run", shelf: -1, face: 1, out: 0, safeMs: safe ? 1e9 : 0, ducking: false });
Object.assign(round.runner, { line, v, coyote: 0 });
round.camX = Math.max(0, Math.min(round.spec.length - ghoul.FIELD_W, x - 24));
}
function run(round, ms, keys = {}, random = steady) {
Object.assign(round.input, keys);
for (let t = 0; t < ms; t += 4) ghoul.advance(round, 4, random);
for (const key of Object.keys(keys)) round.input[key] = typeof keys[key] === "number" ? 0 : false;
}
function until(round, done, ms = 6000, random = steady) {
let t = 0;
for (; t < ms && !done(); t += 4) ghoul.advance(round, 4, random);
return t;
}
const press = (round) => {
round.input.jump = ghoul.JUMP_BUFFER_MS;
round.input.up = true;
};
const heard = (e, extra = {}) => {
const played = [];
const noop = () => {};
const kit = { tone: (name) => played.push(name), burst: noop, float: noop, ring: noop, banner: () => null, shake: noop, flash: noop, glow: noop, splat: noop, fx: { clock: 1e6 }, monsters: ghoul.MONSTERS, powers: ghoul.POWERS, bosses: ghoul.BOSSES, g: {}, floorAt: () => 6, ...extra };
react({ x: 10, y: 6, tx: 20, ty: 6, ...e }, kit);
return { played };
};
const ROOM = ghoul.roomById("tray");
const R = ROOM.ride;
const lines = ct.linesOf(R);
const floorOf = (x) => ghoul.groundAt(ROOM, x);
const slopeAtLine = (L, i) => (L.pts[i + 1][1] - L.pts[i][1]) / (L.pts[i + 1][0] - L.pts[i][0]);
/* -------------------------------------------------------------- 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", () => {
const st = ghoul.stageById("wing");
assert.deepEqual(st.rooms, ["kitchen", "conservatory", "attic", "tray", "crypt"]);
assert.equal(st.boss, ghoul.roomById("crypt").boss);
assert.deepEqual([ROOM.title, ROOM.sub], ["Last Orders", "Dinner is served. You are dinner"]);
assert.equal(ROOM.dark, false);
assert.equal(ROOM.key, null);
assert.equal(ROOM.boss, null);
assert.equal(ROOM.bonus, true, "a bonus round");
assert.equal(R.runner, "tray");
assert.ok(ROOM.length >= 2400 && ROOM.length <= 3400, `${ROOM.length} units long`);
assert.equal(ghoul.ROOM_MUSIC.tray, "ghoulTrayRide");
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.equal(ROOM.ground[1][0], R.finish);
assert.ok(ROOM.door > R.finish && ROOM.door > ROOM.length - 14);
assert.ok(floorOf(ROOM.door - 2) > -Infinity, "floor to walk out on");
for (const L of lines) for (let i = 0; i + 1 < L.pts.length; i++) assert.ok(L.pts[i + 1][0] > L.pts[i][0], "x rises");
assert.ok(ct.trackY(R, 0, ROOM.start) > floorOf(ROOM.start), "the tray starts over the landing");
const secs = (lines.at(-1).x1 - ROOM.start) / tr.TRAY_V;
assert.ok(secs >= 62 && secs <= 80, `${secs.toFixed(1)} s at TRAY_V`);
// Every line stays inside the room, clear of the roof and of the fall.
for (const L of lines) for (const [, y] of L.pts) assert.ok(y > 8 && y < 40, `a track height of ${y}`);
// Stairs fall about 0.17, shelves climb about 0.28 or run flat, nothing steeper.
for (const L of lines) {
for (let i = 0; i + 1 < L.pts.length; i++) {
const s = slopeAtLine(L, i);
assert.ok(s >= -0.2 && s <= 0.32, `a slope of ${s.toFixed(3)}`);
}
}
assert.equal(lines.length, 18);
assert.deepEqual([R.pots.length, R.lows.length, R.cooks.length], [16, 11, 4]);
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", () => {
const lip = lines.at(-1);
const end = lip.pts.at(-1);
const rise = ct.slopeOf(R, lines.length - 1, lip.x1);
assert.ok(rise >= tr.RAMP_SLOPE, "the last shelf ends rising");
const table = floorOf(R.finish + 1);
for (const v of [tr.TRAY_MIN, 34, tr.TRAY_V, 55, tr.GREASE_V, tr.TRAY_MAX]) {
let vy = rise * v + tr.RAMP_POP;
let x = end[0];
let y = end[1];
for (let t = 0; t < 3; t += 0.002) {
vy -= tr.TRAY_G * 0.002;
x += v * 0.002;
y += vy * 0.002;
if (vy < 0 && y <= table) break;
}
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 (let i = 0; i + 1 < lines.length - 1; i++) {
const a = lines[i];
const b = lines[i + 1];
const gap = b.x0 - a.x1;
assert.ok(gap >= 9 && gap <= 18, `gap ${i} is ${gap} wide`);
const end = a.pts.at(-1);
const slope = ct.slopeOf(R, i, a.x1);
assert.ok(slope < 0, "gaps lie at the foot of a flight (no ramp launch)");
for (const v of [40, 44, 50, 60]) {
assert.equal(tr.flight(R, a.x1, end[1], slope * v, v), null, `gap ${i}, no jump, at ${v}`);
for (const early of [0, 4]) {
const x = a.x1 - early;
const y = ct.trackY(R, i, x);
const s = tr.flight(R, x, y, tr.TRAY_JUMP_V + ct.slopeOf(R, i, x) * v, v);
assert.ok(s, `gap ${i}: a jump ${early} early at ${v} lands`);
assert.equal(s.line, i + 1, `gap ${i} cleared, at ${v}, ${early} early`);
}
}
}
});
// The kit's numbers the room is built to.
function k() {
return { HIT_W: ghoul.HIT_W, HIT_H: ghoul.HIT_H, DUCK_H: ghoul.DUCK_H };
}
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", () => {
const jumps = [];
for (const [x, line, kind] of R.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] of R.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`);
jumps.push([x - 14, x - 2]);
}
for (let i = 0; i + 1 < lines.length; i++) jumps.push([lines[i].x1, lines[i + 1].x0]);
const ducks = R.lows.map(([x0, x1]) => [x0, x1]);
jumps.sort((a, b) => a[0] - b[0]);
for (let i = 0; i + 1 < jumps.length; i++) assert.ok(jumps[i + 1][0] - jumps[i][1] >= 22, `jumps at ${jumps[i][1]} and ${jumps[i + 1][0]}`);
for (const [d0, d1] of ducks) {
for (const [j0, j1] of jumps) assert.ok(j0 - d1 >= 38 || d0 - j1 >= 38, `a jump at ${j0} and a duck at ${d0}`);
}
for (let i = 0; i < ducks.length; i++) {
const [x0, x1, y, kind] = R.lows[i];
assert.ok(kind === 0 || kind === 1);
let hi = 0;
let lo = 99;
for (let x = x0 - k().HIT_W / 2; x <= x1 + k().HIT_W / 2; x += 0.25) {
const g = ct.linesAt(R, x)[0];
assert.ok(g, "a shelf under a low");
hi = Math.max(hi, g[1]);
lo = Math.min(lo, g[1]);
}
assert.ok(hi + k().DUCK_H < y, `a ducked box clears the low at ${x0}`);
assert.ok(lo + k().HIT_H > y, `a standing box hits the low at ${x0}`);
for (const [j0, j1] of ducks) if (j0 !== x0) assert.ok(j0 - x1 > 20 || x0 - j1 > 20);
}
// The grease: on flat shelf only, and nothing in it spaced shorter than the faster tray needs (30).
assert.equal(R.grease.length, 5);
for (const [a, b] of R.grease) {
for (let x = a; x <= b; x += 1) {
const line = ct.linesAt(R, x)[0][0];
assert.equal(ct.slopeOf(R, line, x), 0, `grease at ${x} is on the flat`);
}
const inside = jumps.filter(([j0, j1]) => j1 > a - 30 && j0 < b + 30);
for (let i = 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.
const cs = R.checks;
for (let i = 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] of jumps) 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", () => {
const flat = synth({ track: FLAT });
run(flat, 3000);
assert.ok(Math.abs(flat.runner.v - tr.TRAY_V) < 0.5, `${flat.runner.v} on the flat`);
const slick = 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");
const down = synth({ track: DOWN });
run(down, 4000);
assert.ok(down.runner.v > tr.TRAY_V && down.runner.v <= tr.TRAY_MAX);
const up = synth({ track: UP });
run(up, 4000);
assert.ok(up.runner.v < tr.TRAY_V && up.runner.v >= tr.TRAY_MIN);
const keyed = synth({ track: FLAT });
run(keyed, 3000, { left: true });
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);
});
function greasyAt(round, x) {
return tr.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", () => {
const round = synth({ track: FLAT });
press(round);
let peak = 0;
const start = round.you.y;
let t = 0;
for (; t < 2000; t += 4) {
ghoul.advance(round, 4, steady);
peak = Math.max(peak, round.you.y - start);
if (t > 40 && round.runner.line >= 0) break;
}
round.input.up = false;
assert.ok(peak > 12 && peak < 14.5, `${peak} high`);
assert.ok(t > 650 && t < 850, `${t} ms in the air`);
assert.equal(events(round, "trayJump").length, 1);
assert.equal(events(round, "trayLand").length, 1);
const edge = synth({ track: [[[0, 20], [60, 20]], [[75, 20], [400, 20]]] });
trayAt(edge, 59, 0);
run(edge, 40);
assert.equal(edge.runner.line, -1, "off the end");
press(edge);
run(edge, 8);
assert.equal(events(edge, "trayJump").length, 1, "the grace jump");
});
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", () => {
for (const [kind, cause] of [[0, "ham"], [1, "pans"]]) {
const round = synth({ track: FLAT, lows: [[60, 66, 23.0, kind]] });
run(round, 20, { down: true });
assert.equal(events(round, "trayDuck").length, 1);
round.input.down = true;
until(round, () => round.you.x > 75, 3000);
round.input.down = false;
assert.equal(round.bonusRound.hearts, 5);
const hit = synth({ track: FLAT, lows: [[60, 66, 23.0, kind]] });
until(hit, () => hit.bonusRound.hearts < 5, 3000);
assert.equal(hit.bonusRound.hearts, 4);
assert.equal(hit.lives, 3, "not a life");
assert.equal(events(hit, "lose")[0].cause, cause);
assert.equal(events(hit, "trayCrash")[0].what, cause);
assert.equal(hit.phase, "play", "the ride plays on");
assert.ok(hit.you.safeMs > 0, "blinking safe");
assert.deepEqual(hit.bonusRound.perf.hits, ["l0"]);
run(hit, 1000);
assert.equal(hit.bonusRound.hearts, 4, "the same low costs nothing twice");
}
const jump = synth({ track: FLAT, lows: [[60, 66, 23.0, 0]] });
trayAt(jump, 40, 0);
press(jump);
until(jump, () => jump.bonusRound.hearts < 5 || jump.you.x > 80, 3000);
assert.equal(jump.bonusRound.hearts, 4, "a jump does not clear a low");
const both = 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", () => {
for (const [kind, cause] of [[0, "pot"], [1, "cutlery"]]) {
const hit = synth({ track: FLAT, pots: [[60, 0, kind]] });
until(hit, () => hit.bonusRound.hearts < 5, 3000);
assert.equal(hit.bonusRound.hearts, 4);
assert.equal(events(hit, "lose")[0].cause, cause);
assert.deepEqual(hit.bonusRound.perf.hits, ["p0"]);
run(hit, 1500);
assert.equal(hit.bonusRound.hearts, 4, "once");
const clear = synth({ track: FLAT, pots: [[60, 0, kind]] });
trayAt(clear, 60 - 14, 0);
press(clear);
until(clear, () => clear.you.x > 80, 3000);
assert.equal(clear.bonusRound.hearts, 5, `a jump clears ${cause}`);
}
});
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", () => {
const room = () => synth({ track: FLAT, cooks: [[220, 0]] });
const hit = room();
trayAt(hit, 100, 0);
until(hit, () => hit.runner.cooks[0].state === "up", 3000);
assert.ok(hit.runner.cooks[0].state === "up" && 220 - hit.you.x <= tr.COOK_NEAR && 220 - hit.you.x > tr.COOK_NEAR - 6);
assert.equal(events(hit, "trayCookUp").length, 1);
until(hit, () => hit.runner.cooks[0].dish, 1500);
assert.equal(events(hit, "trayToss").length, 1);
assert.ok(hit.runner.cooks[0].dish.x < 220);
until(hit, () => hit.bonusRound.hearts < 5, 3000);
assert.equal(hit.bonusRound.hearts, 4);
assert.equal(events(hit, "lose")[0].cause, "dish");
assert.deepEqual(hit.bonusRound.perf.hits, ["c0"]);
assert.equal(hit.runner.cooks[0].dish, null, "the dish is spent");
// A jump as it comes clears it.
const jump = room();
trayAt(jump, 100, 0);
for (let t = 0; t < 6000 && jump.you.x < 240; t += 4) {
const d = jump.runner.cooks[0].dish;
if (d && d.x - jump.you.x < 14 && d.x - jump.you.x > 4 && jump.runner.line >= 0) press(jump);
ghoul.advance(jump, 4, steady);
}
jump.input.up = false;
assert.equal(jump.bonusRound.hearts, 5, "jumped");
// The cook shot while winding up: 150 points, no dish ever.
const shoot = room();
trayAt(shoot, 100, 0);
const score = shoot.score;
shoot.input.fire = true;
until(shoot, () => shoot.runner.cooks[0].state === "broken", 3000);
shoot.input.fire = false;
assert.equal(shoot.runner.cooks[0].state, "broken");
assert.equal(events(shoot, "trayCookHit")[0].points, tr.COOK_POINTS);
assert.ok(shoot.score - score >= tr.COOK_POINTS);
run(shoot, 3000);
assert.equal(shoot.bonusRound.hearts, 5, "no dish");
assert.equal(events(shoot, "trayToss").length, 0);
// A dish shot out of the air breaks (nothing scored).
const dish = room();
trayAt(dish, 100, 0);
until(dish, () => dish.runner.cooks[0].dish, 3000);
dish.runner.cooks[0].state = "spent";
dish.input.fire = true;
until(dish, () => !dish.runner.cooks[0].dish, 1500);
dish.input.fire = false;
assert.equal(events(dish, "trayDishBreak").length, 1);
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)", () => {
const round = synth({ track: FLAT, domes: [[60, 0, 0], [100, 0, 7]] });
const score = round.score;
until(round, () => round.runner.domes[0], 3000);
assert.equal(round.runner.domes[0], true);
assert.equal(round.runner.served, 1);
assert.equal(round.bonusRound.perf.acts, 1);
assert.equal(events(round, "trayDome")[0].n, 1);
assert.equal(events(round, "trayDome")[0].points, tr.DOME_POINTS);
assert.ok(round.score - score >= tr.DOME_POINTS);
until(round, () => round.you.x > 130, 3000);
assert.equal(round.runner.domes[1], false, "a high dome is not run through");
const hop = synth({ track: FLAT, domes: [[100, 0, 7]] });
trayAt(hop, 92, 0);
press(hop);
until(hop, () => hop.runner.domes[0] || hop.you.x > 130, 3000);
hop.input.up = false;
assert.equal(hop.runner.domes[0], true, "a jump takes a high dome");
// A plate: touching it, even jumping through it, serves nothing.
const touch = synth({ track: FLAT, plates: [[100, 0, 2.4]] });
trayAt(touch, 86, 0);
press(touch);
until(touch, () => touch.you.x > 130, 3000);
touch.input.up = false;
assert.equal(touch.runner.plates[0], false);
assert.equal(touch.runner.served, 0);
// Shot with a standing bolt, it is served.
const shot = synth({ track: FLAT, plates: [[100, 0, 2.4]] });
shot.input.fire = true;
until(shot, () => shot.runner.plates[0], 3000);
shot.input.fire = false;
assert.equal(shot.runner.plates[0], true);
assert.equal(shot.runner.served, 1);
assert.equal(events(shot, "trayPlate")[0].points, tr.PLATE_POINTS);
assert.equal(shot.bonusRound.perf.acts, 1);
// A high plate needs a bolt from a jump: a standing bolt flies under it.
const high = 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.
const again = 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)", () => {
const probe = synth({ track: DOWN });
probe.input.fire = true;
run(probe, 300);
probe.input.fire = false;
assert.ok(probe.shots.length > 0);
for (const s of probe.shots) {
const over = 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", () => {
const gap = [[[0, 20], [60, 20]], [[75, 20], [400, 20]]];
const fall = synth({ track: gap });
trayAt(fall, 30, 0);
until(fall, () => fall.bonusRound.hearts < 5, 3000);
assert.equal(fall.bonusRound.hearts, 4);
assert.equal(events(fall, "lose")[0].cause, "tumble");
assert.equal(fall.phase, "play");
assert.equal(fall.lives, 3);
until(fall, () => fall.runner.line === 1 && fall.you.x > 90, 3000);
assert.equal(fall.runner.line, 1, "back on the shelf ahead");
assert.equal(fall.bonusRound.hearts, 4);
const hop = 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", () => {
const round = trayRound();
round.dice = 2;
round.bonusRound.hearts = 1;
trayAt(round, lines[0].x1 - 6, 0);
round.you.safeMs = 0;
until(round, () => round.phase === "clear", 6000);
assert.equal(round.bonusRound.hearts, 0);
assert.equal(round.bonusRound.over, true);
assert.equal(round.bonusRound.won, false);
const end = events(round, "bonusEnd");
assert.equal(end.length, 1);
assert.deepEqual([end[0].won, end[0].dice], [false, 0]);
assert.equal(round.over, false, "no game over");
assert.equal(round.lives, 3);
assert.equal(round.dice, 2);
run(round, ghoul.CARD_LOST_MS + 100);
assert.equal(round.spec.id, "crypt");
assert.equal(round.bonusRound, null);
assert.equal(round.runner, null);
assert.equal(round.lives, 3);
assert.equal(round.dice, 2);
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", () => {
const round = trayRound();
const first = R.checks[0];
const li = ct.linesAt(R, first)[0][0];
trayAt(round, first - 3, li, { safe: true });
until(round, () => round.runner.check === 0, 1000);
assert.equal(round.runner.check, 0);
assert.equal(events(round, "trayCheck")[0].n, 1);
trayAt(round, R.checks[1] - 3, ct.linesAt(R, R.checks[1])[0][0], { safe: true });
until(round, () => round.runner.check === 1, 1000);
assert.equal(round.runner.check, 1);
tr.TRAY.place[0](round, {});
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", () => {
const round = trayRound();
round.dice = 1;
const last = lines.length - 1;
trayAt(round, lines[last].x1 - 12, last, { safe: true });
until(round, () => round.runner.done, 4000);
assert.equal(round.runner.done, true);
assert.equal(events(round, "trayLaunch").length, 1);
assert.equal(events(round, "trayLaunch")[0].last, true);
assert.equal(events(round, "trayFinish").length, 1);
assert.ok(round.you.x > R.finish + 4 && round.you.x < R.finish + 40, `${round.you.x} landed`);
assert.equal(round.you.y, floorOf(round.you.x));
assert.equal(round.hasKey, true, "the door opens");
assert.equal(round.phase, "play");
round.input.right = true;
until(round, () => round.phase === "clear", 20000);
round.input.right = false;
assert.equal(round.phase, "clear");
const end = events(round, "bonusEnd");
assert.equal(end.length, 1);
assert.equal(end[0].won, true);
assert.ok(end[0].dice >= BONUS_FLOOR && end[0].dice <= ghoul.MAX_DICE, `${end[0].dice} dice`);
assert.equal(round.dice, Math.min(ghoul.MAX_DICE, 1 + end[0].dice));
assert.equal(round.lives, 3);
run(round, ghoul.CARD_MS + 100);
assert.equal(round.spec.id, "crypt");
assert.equal(round.runner, null);
});
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)", () => {
const round = trayRound();
trayAt(round, 120, 1, { safe: true });
round.input.fire = true;
for (let t = 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)", () => {
const round = trayRound();
const b = round.bonusRound;
assert.equal(b.perf.goal, tr.COURSES_GOAL);
assert.equal(tr.COURSES_GOAL, 7);
assert.equal(b.perf.total, R.pots.length + R.lows.length + R.cooks.length + lines.length - 1);
assert.equal(b.perf.steady, false, "no cherries yet");
const mk = (perf) => {
const x = makeBonus({ stats: { kills: 0 } });
Object.assign(x.perf, { total: b.perf.total, goal: tr.COURSES_GOAL }, perf);
return x;
};
assert.equal(diceFor(mk({ hits: [], acts: 7, steady: true })), 9, "a perfect, hungry ride");
assert.equal(diceFor(mk({ hits: [], acts: 6, steady: true })), 8, "a sixth course short");
assert.equal(diceFor(mk({ hits: [], acts: 7, steady: false })), 8, "no cherries");
assert.equal(diceFor(mk({ hits: [], acts: 0, steady: false })) >= BONUS_FLOOR, true);
const hit = mk({ hits: R.pots.map((_, i) => `p${i}`), acts: 0, steady: false });
hit.hearts = 1;
assert.equal(diceFor(hit), BONUS_FLOOR + Math.round((2 * (b.perf.total - R.pots.length)) / b.perf.total), "hit a lot, no courses");
// Courses reach the grade as they are served.
const meal = synth({ track: FLAT, domes: Array.from({ length: 8 }, (_, i) => [40 + i * 12, 0, 0]) });
until(meal, () => meal.runner.served >= 7, 4000);
assert.equal(meal.bonusRound.perf.acts, 7);
// Cherries: 45% of the room's.
const goal = Math.ceil(tr.CHERRY_SHARE * round.candy.length);
trayAt(round, 60, 0, { safe: true });
for (let i = 0; i < goal - 1; i++) round.candy[i] = true;
run(round, 500);
assert.equal(b.perf.steady, false, "one cherry short");
round.candy[goal - 1] = true;
run(round, 500);
assert.equal(b.perf.steady, true, "enough cherries");
});
test("Ghoul Rush's Servants' Back Stairs: endless lives (round.infinite) spare the hearts for every cause, through the same lose path", () => {
const tries = [
{ pots: [[60, 0, 0]] }, { pots: [[60, 0, 1]] }, { lows: [[56, 62, 23.0, 0]] }, { lows: [[56, 62, 23.0, 1]] }, { cooks: [[170, 0]] },
];
for (const t of tries) {
const r = synth({ track: FLAT, ...t });
r.infinite = true;
if (t.cooks) trayAt(r, 100, 0);
until(r, () => events(r, "lose").length > 0, 6000);
assert.ok(events(r, "lose").length > 0, JSON.stringify(Object.keys(t)));
assert.equal(r.bonusRound.hearts, 5, JSON.stringify(Object.keys(t)));
assert.equal(r.lives, 3);
}
const crack = synth({ track: [[[0, 20], [60, 20]], [[75, 20], [400, 20]]] });
crack.infinite = true;
trayAt(crack, 30, 0);
until(crack, () => events(crack, "lose").length > 0, 3000);
assert.equal(crack.bonusRound.hearts, 5);
assert.equal(crack.lives, 3);
});
test("Ghoul Rush's Servants' Back Stairs: the Garlic shield takes a hit instead of a heart", () => {
const round = 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");
for (const [event, [kind, act]] of Object.entries(EVENT_VOICE)) {
const name = TRAY_VOICES[kind] && TRAY_VOICES[kind][act];
assert.ok(name, `${event} has a ${kind}.${act} voice`);
assert.ok(ghoulSfx.default.tones[name], `${name} exists`);
assert.equal(VOICES[kind][act], name, "joined to the game's voices");
assert.ok(heard({ type: event, what: "pot", points: 50 }).played.includes(name), `${event} plays ${name}`);
const len = Math.max(...ghoulSfx.default.tones[name].layers.map((l) => (l.delay || 0) + l.seconds));
assert.ok(len <= 1.2, `${name} is ${len} s`);
}
for (const cause of ["pot", "cutlery", "ham", "pans", "dish", "tumble"]) {
assert.ok(LOSE_WORDS[cause], `${cause} has words`);
assert.ok(LOSE_SOUNDS[cause] && LOSE_SOUNDS[cause].length === 3, `${cause} has a sound`);
assert.ok(heard({ type: "lose", cause, hearts: 3 }).played.length > 0, `${cause} sounds`);
}
assert.equal(heard({ type: "trayJump" }).played.length, 1);
assert.equal(heard({ type: "trayPlate", points: 120, n: 3 }).played.length, 1);
});
test("Ghoul Rush's Servants' Back Stairs: the room's own names do not collide with the game's (events, kinds), and the music is a real track", () => {
for (const e of tr.EVENTS) assert.ok(e.startsWith("tray"), e);
const other = new Set();
for (const pack of [ct, sl]) for (const e of pack.EVENTS || []) other.add(e);
for (const e of tr.EVENTS) assert.ok(!other.has(e), `${e} is the tray's alone`);
assert.deepEqual(Object.keys(tr.TRAY).filter((key) => ["hazards", "bosses", "boss"].includes(key)), []);
const music = ghoulSfx.default.music.ghoulTrayRide;
for (const part of Object.values(music.patterns)) {
for (const row of Object.values(part)) assert.equal(row.split("|").length, 4, "four bars a pattern");
}
assert.ok(music.order.every((p) => music.patterns[p]));
});
/* --------------------------------------------------------------- drawing */
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", () => {
const ctx = new Proxy({}, { get: (t, name) => (name in t ? t[name] : () => {}), set: (t, name, value) => ((t[name] = value), true) });
const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } });
g.resize(900, 900);
g.key("action");
g.tick(16);
const r = g.round;
through(r);
r.offer = ["wing"];
r.phaseMs = 0;
ghoul.pickStage(r, 0);
while (r.spec.id !== "tray") through(r);
r.lives = 99;
const pot = R.pots.find((p) => !p[2]);
const cutlery = R.pots.find((p) => p[2]);
const spots = [ROOM.start + 40, pot[0] - 10, cutlery[0] - 10, R.lows[0][0] - 5, R.lows[3][0] - 5, R.cooks[0][0] - 30, R.domes[3][0] - 8, R.plates[3][0] - 8, R.checks[0], lines[0].x1 - 10, R.grease[0][0] + 10, R.finish - 40];
for (const dark of [true, false]) {
for (const x of spots) {
r.dark = dark;
r.phase = "play";
for (const st of r.spawns) st.over = true;
r.hordeMs = Infinity;
r.monsters.length = 0;
const top = ct.linesAt(R, x)[0] || [lines.length - 1, 20];
trayAt(r, x, top[0], { safe: true });
r.runner.cooks = r.runner.cooks.map((c, i) => ({ ...c, state: ["down", "up", "toss", "spent", "broken"][i % 5], t: 600, dish: i % 2 ? { x: x + 20, y: top[1] + 1.6 } : null }));
r.runner.domes = r.runner.domes.map((_, i) => i % 3 === 0);
r.runner.plates = r.runner.plates.map((_, i) => i % 4 === 0);
for (const air of [false, true]) {
if (air) Object.assign(r.you, { state: "air", vy: 20, y: r.you.y + 4 });
if (air) r.runner.line = -1;
r.you.ducking = x === R.lows[0][0] - 5 && !air;
r.shots.push({ x: x + 6, y: r.you.y + 2.4, vx: 130, vy: -10, gone: 0 });
for (let n = 0; n < 4; n++) g.tick(16);
r.monsters.length = 0;
r.you.safeMs = 1e9;
trayAt(r, x, top[0], { safe: true });
}
}
}
assert.equal(r.spec.id, "tray");
r.you.safeMs = 0;
trayAt(r, R.pots[2][0] - 3, R.pots[2][1]);
for (let n = 0; n < 30; n++) g.tick(16);
assert.ok(r.bonusRound.hearts < r.bonusRound.max || r.phase !== "play", "the crash draws too");
const done = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } });
done.resize(900, 900);
done.key("action");
done.tick(16);
const d = done.round;
through(d);
d.offer = ["wing"];
d.phaseMs = 0;
ghoul.pickStage(d, 0);
while (d.spec.id !== "tray") through(d);
d.phase = "play";
d.runner.done = true;
d.runner.restX = R.finish + 20;
Object.assign(d.you, { x: R.finish + 30, y: 10, state: "run" });
d.camX = R.finish - 40;
for (let n = 0; n < 10; n++) done.tick(16);
for (const won of [true, false]) {
endBonus(d, won, { ROOM_POINTS: 300, award: (rd, pts) => (rd.score += pts) });
d.bonusRound.over = true;
for (let n = 0; n < 10; n++) {
done.tick(16);
bonusTick(d, { tone() {}, fx: {} });
}
d.bonusRound.over = false;
}
// The stage select goes straight into it.
const pick = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } });
pick.resize(900, 900);
pick.stageSelect();
const p = pick.round;
const at = ghoul.STAGES.findIndex((s) => s.id === "wing");
for (let i = 0; i < at; i++) ghoul.steerSelect(p, 1, 0);
for (let i = 0; i < 3; i++) ghoul.steerSelect(p, 0, 1);
assert.equal(p.select.room, 3);
pick.tick(16);
ghoul.takeSelect(p);
assert.equal(p.spec.id, "tray");
assert.equal(p.runner.line, 0);
assert.equal(p.you.y, ct.trackY(R, 0, ROOM.start));
pick.tick(16);
});
/* ----------------------------------------------------------- the bots */
const mix = (a, b) => {
let h = Math.imul(a + 0x9e37, 0x85ebca6b) ^ Math.imul(b + 0x7f4a, 0xc2b2ae35);
h ^= h >>> 13;
h = Math.imul(h, 0x5bd1e995);
h ^= h >>> 15;
return (h >>> 0) / 4294967296;
};
// A bot that dodges well: it jumps at the end of a line (not the lip), 9 to 15 short of a pot or a
// piece of cutlery and as a dish comes, jumps for the high domes, ducks under every low, and holds
// the blaster. `miss` is the share of things it fails to dodge (by a hash).
function goodBot(round, seed, miss = 0.04) {
const { you, runner: c, input: inp } = round;
inp.left = inp.right = inp.down = false;
inp.fire = true;
if (round.phase !== "play" || !c || c.done) {
inp.up = false;
return;
}
const ok = (x) => mix(seed, Math.round(x)) >= miss;
const look = 9 + (seed % 7);
let jump = false;
if (c.line >= 0) {
const last = c.line === lines.length - 1;
if (!last && lines[c.line].x1 - you.x < 2.2 && ok(lines[c.line].x1)) jump = true;
const ahead = (x) => x - you.x > 6 && x - you.x < look;
for (const [x] of R.pots) if (ahead(x) && ok(x)) jump = true;
R.cooks.forEach((_, i) => {
const d = c.cooks[i].dish;
if (d && d.x - you.x > 4 && d.x - you.x < 12 && ok(d.x)) jump = true;
});
R.domes.forEach(([x, , lift], i) => {
if (lift > 0 && !c.domes[i] && ahead(x - 3)) jump = true;
});
for (const [x0, x1] of R.lows) if (you.x > x0 - 10 && you.x < x1 + 3 && ok(x0)) inp.down = true;
}
if (jump && !inp.down) press(round);
else inp.up = false;
}
function idleBot(round) {
const inp = round.input;
inp.left = inp.right = inp.down = false;
inp.up = false;
inp.fire = true;
}
function rideWith(seed, bot, limit = 100000) {
const round = trayRound(seed);
const lost = [];
let t = 0;
for (; t < limit && round.phase !== "clear" && !round.over; t += 16) {
bot(round);
if (round.runner && round.runner.done && round.phase === "play") round.input.right = true;
ghoul.advance(round, 16, steady);
for (const e of round.events) if (e.type === "lose") lost.push(e.cause);
if (round.runner && !round.runner.done) {
const off = round.you.x - round.camX;
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", () => {
const dice = [];
for (let seed = 1; seed <= 12; seed++) {
const { round, lost, ms } = rideWith(seed, (r) => goodBot(r, seed));
const b = round.bonusRound;
assert.equal(b.won, true, `seed ${seed} finished (lost ${lost.join(",")})`);
assert.ok(ms > 60000 && ms < 76000, `${ms} ms`);
assert.ok(b.dice >= 6 && b.dice <= ghoul.MAX_DICE, `${b.dice} dice`);
assert.ok(round.runner.served >= tr.COURSES_GOAL, `${round.runner.served} courses`);
assert.equal(round.lives, 3, "never a run life");
assert.equal(round.runner.check, R.checks.length - 1, "past every checkpoint");
dice.push(b.dice);
}
assert.ok(dice.reduce((a, b) => a + b, 0) / dice.length >= 7, `${dice.join(",")}`);
});
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 (let seed = 1; seed <= 6; seed++) {
const { round, lost } = rideWith(seed, idleBot);
const b = 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}`);
assert.equal(round.lives, 3);
assert.equal(round.over, false);
}
});
/* ------------------------------------------------------------ telegraphs */
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", () => {
const marks = telegraphMarks(R);
const answers = { gap: "JUMP", pot: "JUMP", cutlery: "JUMP", ham: "DUCK", pans: "DUCK", cook: "SHOOT" };
assert.equal(marks.length, lines.length - 1 + R.pots.length + R.lows.length + R.cooks.length, "one per obstacle, none for the courses");
for (const m of marks) assert.equal(m.answer, answers[m.kind], m.kind);
const first = R.lows.find((l) => !l[3]);
const m = marks.find((q) => q.x === (first[0] + first[1]) / 2);
assert.equal(m.kind, "ham");
const xs = [m.lead - 45, m.lead - 41, m.lead - 36, m.lead - 30, m.lead - 10, m.lead, m.lead + 3, m.lead + 7];
const alphaOf = (x) => (telegraphs(R, x).find((t) => t.kind === "ham" && t.lead === m.lead) || { alpha: 0 }).alpha;
const a = xs.map(alphaOf);
assert.equal(a[0], 0, "not yet in view");
assert.ok(a[2] > 0 && a[2] < 1, "fading in 40 to 30 ahead");
assert.equal(a[3], 1);
assert.equal(a[4], 1);
assert.ok(a[6] > 0 && a[6] < 1, "fading as it passes");
assert.equal(a[7], 0, "gone once passed");
assert.deepEqual(telegraphs(R, m.lead - 33), telegraphs(R, m.lead - 33), "deterministic");
for (const kind of ["gap", "pot", "cutlery", "ham", "pans", "cook"]) {
const of = marks.filter((q) => q.kind === kind).sort((p, q) => p.lead - q.lead);
assert.ok(of.length >= 3, kind);
of.forEach((q, i) => {
assert.equal(q.n, i);
const shown = telegraphs(R, q.lead - 32).find((t) => t.lead === q.lead);
assert.equal(shown.words, i < 3, `${kind} ${i}`);
});
}
});
test("Ghoul Rush's Servants' Back Stairs' intro banner says the controls plainly", () => {
assert.match(R.how, /UP to jump, DOWN to duck, hold space to shoot/);
});
@@ -89,7 +89,7 @@ const heard = (e, extra = {}) => {
test("Ghoul Rush's Hollow End Village is a stage of three rooms and the Green, its monsters and boss joined to the game's, with a power-up of its own, a moon that rises and a place for each kind", () => {
const st = ghoul.stageById("village");
assert.deepEqual(st.rooms, ROOM_IDS);
assert.deepEqual(st.rooms, ["street", "inn", "square", "wagon", "green"], "the Torch Mob bonus ride sits before the Green");
assert.equal(st.boss, "beast");
assert.equal(st.title, "Hollow End Village");
assert.equal(st.sub, "Every curtain twitches as you pass");
@@ -98,7 +98,7 @@ test("Ghoul Rush's Hollow End Village is a stage of three rooms and the Green, i
assert.equal(vl.BOSSES.beast.sub, "Shoot it while it clings to the wall");
assert.ok(ghoul.MONSTERS.villager.hp === 3 && ghoul.MONSTERS.hanged.hp === 3 && ghoul.MONSTERS.shutter.hp === 2 && ghoul.BOSSES.beast.hp === 110);
for (const id of st.rooms) assert.ok(ghoul.ROOM_MUSIC[id], `${id} has music`);
const [street, inn, square, green] = st.rooms.map((id) => ghoul.roomById(id));
const [street, inn, square, , green] = st.rooms.map((id) => ghoul.roomById(id));
const returning = ["zombie", "bat", "crow", "hound", "ghost"];
for (const room of [street, inn, square]) {
assert.ok(room.key, `${room.id}: a key`);
File diff suppressed because it is too large. Load diff
+103 -13
View File
@@ -11,6 +11,7 @@ import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import * as ghoul from "../src/web-console/public/activities/ghoul.js";
import { skipStory as storySkip } from "../src/web-console/public/activities/ghoul-story.js";
import { BANNER_SHADE, CHUNK, GAUGE_COOL, GAUGE_HOT, GAUGE_WARM, LOOKS, SEAM, VOICES, contrast, gaugeColor, hudLayout, labelSpot, limbInk } from "../src/web-console/public/activities/ghoul-draw.js";
import { ACCENTS } from "../src/web-console/public/palette.js";
import { humNames, toneNames } from "../src/web-console/public/tones.js";
@@ -22,6 +23,13 @@ const ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), "..");
const GHOUL_TONES = Object.freeze(["ghoulBlast", "ghoulStomp", "ghoulBoo", "ghoulRoar", "ghoulCandy", "zombiePop", "zombieGroan", "batSwoop", "doorUnlock", "doorThrough", "creakBoard", "ghoulGrowl", "ghoulShriek", "ghoulSkitter", "ghoulSpit", "ghoulThunder"]);
const steady = () => 0.5;
// Past the intro story at once (it has its own tests): a run opens on it, and the tests that play from the hall skip it.
function skipStory(g) {
if (g.round.phase !== "story") return;
storySkip(g.round);
g.tick(0);
}
/* ------------------------------------------------------------ canvases */
// A 2D context whose every method is a no-op that counts itself.
@@ -158,6 +166,14 @@ function withTokens(values, fn) {
/* ---------------------------------------------------------- round helpers */
// Past a stage's intro card at once (the card has its own tests).
// Leaves a stage's intro card or a boss room's (phase "intro" or "bossintro").
function skipIntro(round) {
if (round.phase !== "intro" && round.phase !== "bossintro") return;
round.introMs = ghoul.INTRO_MIN_MS;
ghoul.takeIntro(round);
}
// Goes through the door of the room the round is in.
function through(round) {
round.phase = "clear";
@@ -254,6 +270,7 @@ test("Ghoul Rush answers the game contract: ready until started, pause and resum
assert.equal(g.resize(ghoul.W * ghoul.MIN_CELL, ghoul.H * ghoul.MIN_CELL), true, "just big enough");
assert.equal(g.resize(2000, 2000), true);
g.start();
skipStory(g);
g.round.dice = 0;
assert.equal(g.state, "running");
g.pause();
@@ -938,7 +955,7 @@ test("Ghoul Rush: every room but a boss's keeps a horde coming in from the edges
for (const base of ghoul.ROOMS) {
if (base.boss) assert.deepEqual([base.horde.length, base.hordeMs], [0, 0], `${base.id}: no horde in a boss's room`);
else if (base.ride && base.ride.gallery) assert.deepEqual([base.horde.length, base.hordeMs], [0, 0], `${base.id}: the dark ride is a gallery, no horde`);
else if (base.ride && base.ride.sled) assert.deepEqual([base.horde.length, base.hordeMs], [0, 0], `${base.id}: the sled's things are the pack's own, no horde`);
else if (base.ride && (base.ride.sled || base.ride.runner)) assert.deepEqual([base.horde.length, base.hordeMs], [0, 0], `${base.id}: a ride's things are the pack's own, no horde`);
else assert.ok(base.horde.length > 0 && base.hordeMs > 0, `${base.id} has a horde`);
for (const kind of base.horde) assert.ok(ghoul.MONSTERS[kind], `${base.id}: ${kind} is a monster`);
}
@@ -1020,7 +1037,7 @@ test("Ghoul Rush: Spread shot and Rapid fire run out after their time, the Garli
ghoul.applyPower(round, "spread");
ghoul.applyPower(round, "rapid");
ghoul.advance(round, ghoul.POWERS.spread.ms + 8, steady);
assert.deepEqual(round.effects, { spread: 0, rapid: 0, lantern: 0, wings: 0, bell: 0, silver: 0, shears: 0, holy: 0, salts: 0, saw: 0, bane: 0, floss: 0, cocoa: 0 });
assert.deepEqual(round.effects, { spread: 0, rapid: 0, lantern: 0, wings: 0, bell: 0, silver: 0, shears: 0, holy: 0, salts: 0, saw: 0, bane: 0, floss: 0, cocoa: 0, boots: 0 });
assert.equal(events(round, "expire").length, 2);
ghoul.applyPower(round, "garlic");
const z = put(round, "zombie", 30);
@@ -1052,6 +1069,34 @@ test("Ghoul Rush: Spread shot and Rapid fire run out after their time, the Garli
assert.equal(r2.drops.length, 0, "and taken");
});
test("Ghoul Rush's Long Hall is always lit until you take its key, then the lights go out and stay out, even after you lose a life; no other room does this", () => {
const spec = ghoul.roomById("hall");
assert.equal(spec.dark, false);
assert.equal(spec.darkOnKey, true);
for (let seed = 1; seed <= 100; seed++) assert.equal(ghoul.newRound(seed).dark, false, `seed ${seed} starts lit`);
assert.deepEqual(ghoul.ROOMS.filter((r) => r.darkOnKey).map((r) => r.id), ["hall"]);
const round = ghoul.newRound(1);
round.dice = 0;
round.phase = "play";
ghoul.advance(round, 4, steady);
assert.equal(round.dark, false, "lit on the way to the key");
assert.equal(round.events.some((e) => e.type === "keyDark"), false);
Object.assign(round.you, { x: spec.key[0], y: spec.key[1], vx: 0, vy: 0, state: "run", safeMs: 1e9 });
round.camX = Math.max(0, spec.key[0] - 36);
ghoul.advance(round, 4, steady);
assert.equal(round.hasKey, true);
assert.equal(round.dark, true, "the lights go out");
assert.equal(round.events.filter((e) => e.type === "keyDark").length, 1);
// A lost life keeps the key, so the dark stays too.
ghoul.lose(round, "zombie");
ghoul.advance(round, ghoul.CRASH_MS + ghoul.READY_MS + 40, steady);
assert.equal(round.spec.id, "hall");
assert.equal(round.hasKey, true);
assert.equal(round.dark, true, "still out after a respawn");
// The next run's hall is lit again.
assert.equal(ghoul.newRound(1).dark, false);
});
test("Ghoul Rush: a room is dark some of the times it is entered, the same each time for a seed, and a lit one never has a Lantern, placed or dropped", () => {
const rooms = [];
for (let seed = 1; seed <= 400; seed++) {
@@ -1064,11 +1109,19 @@ test("Ghoul Rush: a room is dark some of the times it is entered, the same each
while (round.spec.id !== "library") through(round);
rooms.push(round);
}
// Each run's hall.
const halls = Array.from({ length: 400 }, (_, i) => ghoul.newRound(i + 1).dark);
const share = halls.filter(Boolean).length / halls.length;
// The Library across 400 runs.
const share = rooms.filter((r) => r.dark).length / rooms.length;
assert.ok(Math.abs(share - ghoul.DARK_CHANCE) < 0.08, `dark ${share} of the time`);
assert.deepEqual(Array.from({ length: 50 }, (_, i) => ghoul.newRound(i + 1).dark), halls.slice(0, 50), "a seed plays the same");
for (let seed = 1; seed <= 50; seed++) {
const again = ghoul.newRound(seed);
again.dice = 0;
through(again);
again.offer = ["manor"];
again.phaseMs = 0;
ghoul.pickStage(again, 0);
while (again.spec.id !== "library") through(again);
assert.equal(again.dark, rooms[seed - 1].dark, "a seed plays the same");
}
const lit = rooms.filter((r) => !r.dark);
const dark = rooms.filter((r) => r.dark);
assert.ok(lit.length && dark.length, "the Library both ways");
@@ -1703,7 +1756,9 @@ test("Ghoul Rush: out of the hall, and out of each boss's room, you pick the nex
assert.equal(ghoul.steerPick(r2, 1), r2.offer.length > 1);
const want = r2.offer[r2.pick];
assert.equal(ghoul.pickStage(r2), true);
assert.deepEqual([r2.stage, r2.stageAt, r2.offer, r2.room, r2.phase], [want, 0, null, 2, "ready"]);
assert.deepEqual([r2.stage, r2.stageAt, r2.offer, r2.room, r2.phase], [want, 0, null, 2, "intro"], "the stage's intro card comes first");
skipIntro(r2);
assert.equal(r2.phase, "ready");
assert.equal(r2.spec.id, ghoul.stageById(want).rooms[0]);
assert.deepEqual(events(r2, "stage").map((e) => [e.stage, e.n]), [[want, 1]]);
// Through the stage's rooms in order, then the boss's door: cleared, and
@@ -2320,7 +2375,10 @@ function botPlay(seed, skill, rooms, limitMs = 15 * 60000) {
if (round.phase === "pick" && round.phaseMs <= 0) {
if (!round.cleared.includes("manor") && !round.offer.includes("manor")) round.offer[0] = "manor";
ghoul.pickStage(round, Math.max(0, round.offer.indexOf("manor")));
skipIntro(round);
}
// A boss room opens on its card (a stage's own was skipped at the pick).
skipIntro(round);
bot(round);
ghoul.advance(round, 16, random);
ms += 16;
@@ -2353,8 +2411,10 @@ test("Ghoul Rush: of ten runs a sharp bot gets nearly all through the hall and t
// The Rotting Gourd's room (the fifth, after the hall) runs longer: the
// blaster has to cool between bursts at a boss. So does the sixth, the
// first of whichever stage the pick deals (it changes with every stage
// added: Hollow End's Main Street takes the bot up to a minute).
per.forEach((p, i) => assert.ok(p.secs >= 10 && p.secs <= (i === 4 ? 60 : i === 5 ? 70 : 40), `seed ${seed}: room ${i + 1} took ${p.secs.toFixed(1)} s`));
// added: Hollow End's Main Street takes the bot up to a minute). The
// Gourd's bound has room for the slow end of the bot's spread, about a
// minute, which is one seed or two in thirty.
per.forEach((p, i) => assert.ok(p.secs >= 10 && p.secs <= (i === 4 ? 65 : i === 5 ? 70 : 40), `seed ${seed}: room ${i + 1} took ${p.secs.toFixed(1)} s`));
}
assert.ok(outOfFoyer >= 9, `${outOfFoyer} of 10 through the hall and out of the Foyer`);
assert.ok(pastGourd >= 5, `${pastGourd} of 10 past the Gourd`);
@@ -2393,6 +2453,14 @@ function takeManor(g) {
if (!r.cleared.includes("manor") && !r.offer.includes("manor")) r.offer[0] = "manor";
r.pick = Math.max(0, r.offer.indexOf("manor"));
g.key("action");
leaveIntro(g);
}
// Past a stage's intro card the way a player does: the minimum wait, then fire.
function leaveIntro(g) {
if (g.round.phase !== "intro" && g.round.phase !== "bossintro") return;
for (let ms = 0; ms < ghoul.INTRO_MIN_MS + 50; ms += 16) g.tick(16);
g.key("action");
}
// Starts a game with nothing waking.
@@ -2401,6 +2469,7 @@ function ghoulGame(opts = {}) {
const g = ghoul.default.create({ canvas, ...opts });
g.resize(900, 900);
g.key("action");
skipStory(g);
g.tick(16);
quiet(g.round);
return { g, calls };
@@ -2463,6 +2532,7 @@ test("Ghoul Rush game: space while paused does nothing (only the window plays on
const g = ghoul.default.create({ canvas });
g.resize(900, 900);
g.key("action");
skipStory(g);
g.round.dice = 0;
assert.equal(g.state, "running");
assert.equal(g.round.input.fire, false, "the press that starts never fires");
@@ -2493,9 +2563,11 @@ test("Ghoul Rush game: the start screen names the record, the pick screen shows
g.resize(900, 900);
assert.ok(texts.some(([t]) => t.includes(`Best: 0 of ${ghoul.STAGES.length} stages`)), "the start screen names the record");
g.key("action");
skipStory(g);
g.round.dice = 0;
g.tick(16);
const through = () => {
leaveIntro(g);
const r = g.round;
quiet(r);
r.hasKey = true;
@@ -2521,7 +2593,8 @@ test("Ghoul Rush game: the start screen names the record, the pick screen shows
assert.equal(g.round.phase, "pick", "never on a key repeat");
const want = g.round.offer[0];
g.key("action");
assert.deepEqual([g.round.stage, g.round.input.fire], [want, false], "space takes the stage, and fires nothing");
assert.deepEqual([g.round.stage, g.round.input.fire, g.round.phase], [want, false, "intro"], "space takes the stage, and fires nothing");
leaveIntro(g);
for (let k = 0; k < ghoul.stageById(want).rooms.length - 1; k++) {
through();
assert.equal(saved, 0, "no stage cleared yet");
@@ -2535,6 +2608,7 @@ test("Ghoul Rush game: the start screen names the record, the pick screen shows
for (let ms = 0; ms < ghoul.PICK_HOLD_MS + 50; ms += 16) g.tick(16);
g.key("up");
assert.ok(g.round.stage && g.round.stage !== want, "up takes one too, never the stage just cleared");
leaveIntro(g);
for (let ms = 0; ms < ghoul.READY_MS + 50; ms += 16) g.tick(16);
g.round.dice = 0;
g.round.lives = 1;
@@ -2574,11 +2648,15 @@ test("Ghoul Rush game: stageSelect() (the window's stage code) opens a practice
const last = ghoul.STAGES.length - 1;
for (let i = 0; i < last + 3; i++) g.key("down");
assert.equal(r.select.at, last, "down stops at the last stage");
// Two up: the Mine, whose second to last room is a walked one (the Carnival's is the dark ride).
// Two up clamps inside the list; then steer on to the Manor, whose second
// to last room is a runner ride (the Carnival's is the dark ride's
// gallery, whose end screen carries no tally line).
g.key("up");
g.key("up");
assert.equal(r.select.at, last - 2);
const st = ghoul.STAGES[last - 2];
const st = ghoul.STAGES[0];
for (let i = 0; i < ghoul.STAGES.length; i++) g.key("up");
assert.equal(r.select.at, 0, "the Manor");
for (let i = 0; i < st.rooms.length + 3; i++) g.key("right");
assert.equal(r.select.room, st.rooms.length - 1, "right stops at the boss room");
g.key("left");
@@ -2647,6 +2725,7 @@ test("Ghoul Rush game: every tone it plays is one tones.js has, its own blips am
const g = ghoul.default.create({ canvas: stubCanvas().canvas, tone: (name) => heard.add(name) });
g.resize(900, 900);
g.key("action");
skipStory(g);
const bot = makeBot(ghoul, 1, ghoul.seeded(3));
for (let ms = 0; ms < 90000 && g.round.room < 3 && g.state === "running"; ms += 16) {
takeManor(g);
@@ -2672,6 +2751,7 @@ test("Ghoul Rush game: its own sounds keep its prefix, and a run holds a monster
});
g.resize(900, 900);
g.key("action");
skipStory(g);
g.round.dice = 0;
const bot = makeBot(ghoul, 1, ghoul.seeded(3));
for (let ms = 0; ms < 180000 && g.round.room < 4 && g.state === "running"; ms += 16) {
@@ -2696,6 +2776,7 @@ test("Ghoul Rush game: its own sounds keep its prefix, and a run holds a monster
const h = ghoul.default.create({ canvas: stubCanvas().canvas, tone: (name) => sounds.push(name) });
h.resize(900, 900);
h.key("action");
skipStory(h);
h.round.dice = 0;
h.round.lives = 1;
for (let k = 0; k < 60; k++) h.tick(16);
@@ -2753,6 +2834,7 @@ test("Ghoul Rush game: a banner fades to see-through while something that can hu
const g = ghoul.default.create({ canvas });
g.resize(900, 900);
g.key("action");
skipStory(g);
quiet(g.round);
for (let k = 0; k < 10; k++) g.tick(16);
assert.ok(alphas.at(-1) > 0.9, `clear strip: solid (${alphas.at(-1)})`);
@@ -2774,6 +2856,7 @@ test("Ghoul Rush game: a \"Ready?\" banner still waiting when play begins is dro
const g = ghoul.default.create({ canvas, best: () => 1 });
g.resize(900, 900);
g.key("action");
skipStory(g);
g.round.dice = 0;
quiet(g.round);
g.tick(16);
@@ -2822,7 +2905,7 @@ test("Ghoul Rush: every pill's text reads at 4.5:1 on its backing and its timer'
assert.ok(k >= 4.5, `${theme}/${id}: "${p.text}" in ${p.ink} on ${under} reads ${k.toFixed(2)}:1`);
}
}
for (const want of ["THE LONG HALL", `STAGE 0 OF ${ghoul.STAGES.length}`, "♥", "BONUS 0", "~CHAIN x4", "KEY", "~SPREAD", "~RAPID", "GARLIC"]) {
for (const want of ["THE LONG HALL", `STAGE 0 OF ${ghoul.STAGES.length}`, "♥", "BONUS 0", "~CHAIN x4", "~SPREAD", "~RAPID", "GARLIC"]) {
const tinted = want.startsWith("~");
const text = tinted ? want.slice(1) : want;
assert.ok(seen.some((p) => p.text.includes(text) && (!tinted || p.tints.length)), `${theme}/${id}: "${text}" drawn (${seen.map((p) => p.text)})`);
@@ -2883,6 +2966,7 @@ test("Ghoul Rush: the blaster's gauge fills with its heat, notched where the bol
const g = ghoul.default.create({ canvas: stubCanvas().canvas });
g.resize(900, 900);
g.key("action");
skipStory(g);
for (let k = 0; k < 5; k++) g.tick(16);
const gauge = () => g.hud.gauge;
assert.equal(gauge().free, ghoul.HEAT_FREE / ghoul.HEAT_MAX, "the notch sits where fireGap() starts to slow");
@@ -2933,6 +3017,7 @@ test("Ghoul Rush game: the opening banner sits in the field from the start's fir
g.resize(900, 900);
shades.length = 0;
g.key("action");
skipStory(g);
assert.equal(shades.length, 1, "the start paints its banner");
const [[top, h]] = shades;
assert.ok(top >= 0 && top + h <= ghoul.FIELD_H, `inside the field (${top})`);
@@ -2947,6 +3032,7 @@ test("Ghoul Rush game: Planny keeps his star eye in your highlight running, firi
const g = ghoul.default.create({ canvas });
g.resize(900, 900);
g.key("action");
skipStory(g);
g.round.dice = 0;
g.tick(16);
quiet(g.round);
@@ -2996,6 +3082,7 @@ test("Ghoul Rush game: what never moves in a room is drawn off screen once, CHUN
const g = ghoul.default.create({ canvas });
g.resize(900, 900);
g.key("action");
skipStory(g);
g.tick(16);
quiet(g.round);
g.tick(16);
@@ -3040,6 +3127,7 @@ test("Ghoul Rush game: every room and boss draws, and each pick of stage, throug
const g = ghoul.default.create({ canvas });
g.resize(900, 900);
g.key("action");
skipStory(g);
for (let n = 1; n <= ghoul.ROOMS.length; n++) {
const r = g.round;
r.lives = 99;
@@ -3052,6 +3140,7 @@ test("Ghoul Rush game: every room and boss draws, and each pick of stage, throug
g.tick(16);
}
assert.ok(calls.count > drawn, `room ${n} draws`);
leaveIntro(g);
if (r.boss) r.boss.state = "down";
r.hasKey = true;
// Through the door, once any life lost in the run is over with.
@@ -3070,6 +3159,7 @@ test("Ghoul Rush game: every room and boss draws, and each pick of stage, throug
g.tick(16);
}
if (n === ghoul.ROOMS.length) break;
leaveIntro(g);
for (let ms = 0; ms < ghoul.READY_MS + 100; ms += 16) g.tick(16);
assert.equal(g.round.room, n + 1);
}