From ab9037a26c96d8cb0fdc0405f7a696f47a89992c Mon Sep 17 00:00:00 2001 From: Ramkumar Ethiraj Date: Mon, 19 Oct 2026 06:07:24 +0000 Subject: [PATCH] Add Lumen light-beam mirror puzzle game --- README.md | 1 + assets/site.css | 93 ++++++ games/index.html | 6 +- games/lumen/core.js | 411 +++++++++++++++++++++++++ games/lumen/index.html | 650 +++++++++++++++++++++++++++++++++++++++ scripts/verify-lumen.mjs | 29 ++ 6 files changed, 1189 insertions(+), 1 deletion(-) create mode 100644 games/lumen/core.js create mode 100644 games/lumen/index.html create mode 100644 scripts/verify-lumen.mjs diff --git a/README.md b/README.md index ccf2bb2..95433c6 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ The home page lists one **Games Hub** card (`games/`). Individual games live on - **Echo Path** (`games/echo/`) — staged memory game; watch a path of adjacent cells light up, then trace it in order; one step longer per stage, grid grows 3×3 → 5×5, three lives, combo multiplier up to ×5, pause and restart; best score - **Number Forge** (`games/forge/`) — target-number puzzle; tap a tile, a sign, and a second tile to merge them, and make the target; Journey runs 15 puzzles over 5 tiers (3 → 5 tiles, × then ÷ unlock, 3 skips), Blitz is 2 minutes (+5s per solve); par and speed bonuses, clean-streak bonus, undo/reset/hint, results summary; best score per mode - **Circuit Link** (`games/circuit/`) — rotate-the-tiles wiring puzzle; tap tiles to turn them until every tile is fed from the gold core with no loose ends; Journey runs 12 circuits over 4 tiers (4×4, 5×5, 6×6, 6×8, 3 skips), Blitz is 3 minutes (+10s per solve), Daily is one date-seeded 6×6 board; turn-direction toggle, lock mode, undo/reset/hint, par-tap and speed bonuses, clean-streak bonus, results summary; best score per mode +- **Lumen** (`games/lumen/`) — canvas light-beam puzzle; drag mirrors and splitters onto floor tiles and tap to turn them so red, green and blue lasers reach every target with exactly the colour mix it asks for; 19 handcrafted levels over 4 tiers (Reflect, Split, Spectrum, Mastery) with pivots, fixed mirrors, glass and colour gates; undo/restart/pause, par-based 1–3 stars per level, level select with unlocks and progress in `rmkr-game-lumen-*`; every level checked solvable by `node scripts/verify-lumen.mjs` #### Casual Quiz (unlisted) diff --git a/assets/site.css b/assets/site.css index fe3b48b..7cd2547 100644 --- a/assets/site.css +++ b/assets/site.css @@ -2126,3 +2126,96 @@ body[data-tool="collab"] .site-footer { display: none; } @media (prefers-reduced-motion: reduce) { .cl-pipe, .cl-grid { transition: none; } } + +/* Lumen (light-beam puzzle) */ +.lm-stage { width: min(100%, 560px); } +.lm-play { display: flex; flex-direction: column; gap: 0.75rem; width: 100%; } +.lm-play[hidden], .lm-select[hidden] { display: none; } +.lm-strip { + display: flex; + flex-wrap: wrap; + gap: 0.35rem 1rem; + justify-content: space-between; + font-size: 0.82rem; + font-weight: 700; + color: var(--color-muted); +} +.lm-strip strong { color: var(--color-accent); font-variant-numeric: tabular-nums; } +.lm-canvas-wrap { + position: relative; + display: flex; + justify-content: center; + width: 100%; +} +.lm-canvas { + display: block; + max-width: 100%; + border-radius: var(--radius); + border: 1px solid var(--color-line); + box-shadow: var(--shadow); + touch-action: none; + cursor: pointer; +} +.lm-canvas:focus { outline: none; } +.lm-canvas:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 3px; } +.lm-tools { + display: grid; + grid-template-columns: repeat(3, minmax(0, 1fr)); + gap: 0.5rem; +} +.lm-select { display: flex; flex-direction: column; gap: 1rem; width: 100%; } +.lm-tier-title { + display: flex; + flex-wrap: wrap; + align-items: baseline; + gap: 0.25rem 0.6rem; + margin: 0 0 0.5rem; + font-size: 1rem; +} +.lm-tier-title span { font-size: 0.78rem; font-weight: 600; color: var(--color-muted); } +.lm-levels { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); + gap: 0.5rem; +} +.lm-lvl { + display: flex; + flex-direction: column; + align-items: center; + gap: 0.15rem; + min-height: 44px; + padding: 0.55rem 0.35rem; + border-radius: var(--radius); + border: 1px solid var(--color-line); + background: linear-gradient(145deg, #1c2844, #121a2c); + color: var(--color-text); + font-family: inherit; + cursor: pointer; + transition: border-color 0.12s ease, transform 0.08s ease; +} +.lm-lvl:hover:not(:disabled) { border-color: var(--color-accent); } +.lm-lvl:active:not(:disabled) { transform: scale(0.97); } +.lm-lvl:disabled { opacity: 0.45; cursor: default; } +.lm-lvl.is-done { border-color: rgba(255, 195, 0, 0.45); } +.lm-lvl-n { font-size: 1.15rem; font-weight: 900; color: var(--color-accent); } +.lm-lvl-name { font-size: 0.74rem; font-weight: 700; text-align: center; overflow-wrap: anywhere; } +.lm-lvl-stars { font-size: 0.78rem; color: var(--color-accent); letter-spacing: 0.08em; } +.lm-lvl.is-locked .lm-lvl-stars { color: var(--color-muted); letter-spacing: 0; } +.lm-win { + position: absolute; + inset: 0; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + gap: 0.4rem; + padding: 1rem; + text-align: center; + background: rgba(12, 21, 36, 0.9); + border-radius: var(--radius); +} +.lm-win[hidden] { display: none; } +.lm-win-stars { margin: 0; font-size: 2rem; color: var(--color-accent); letter-spacing: 0.15em; } +.lm-win-title { margin: 0; font-size: 1.25rem; } +.lm-win-text { margin: 0; font-size: 0.9rem; color: var(--color-muted); max-width: 30ch; } +.lm-win-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; margin-top: 0.4rem; } diff --git a/games/index.html b/games/index.html index 0693376..f6c91d7 100644 --- a/games/index.html +++ b/games/index.html @@ -4,7 +4,7 @@ Focus Games | RMKR Toolkit - + @@ -125,6 +125,10 @@

Number Forge

Circuit Link

Turn wire tiles until every lamp is wired back to the gold core. A 12-circuit Journey, a 3-minute Blitz, and a Daily board.

+ +

Lumen

+

Drag and turn mirrors and splitters to steer red, green and blue lasers into every target. 19 handcrafted levels over 4 tiers, with stars per level.

+

How it works

diff --git a/games/lumen/core.js b/games/lumen/core.js new file mode 100644 index 0000000..fdb04b5 --- /dev/null +++ b/games/lumen/core.js @@ -0,0 +1,411 @@ +/* Lumen: level data, beam tracer and solver. Shared by the page and scripts/verify-lumen.mjs. */ +(function (root) { + "use strict"; + // Directions: 0 N, 1 E, 2 S, 3 W. + var DR = [-1, 0, 1, 0], DC = [0, 1, 0, -1]; + // Reflection tables, indexed by travel direction. Orientation 0 is "/", 1 is "\". + var REFLECT = [[1, 0, 3, 2], [3, 2, 1, 0]]; + var DIR_CH = { "^": 0, ">": 1, "v": 2, "<": 3 }; + var COLOR_CH = { r: 1, g: 2, b: 4 }; + + // Level tokens (two characters per cell, space separated): + // .. floor (pieces may be placed) ## wall :: glass (beam passes, no pieces) + // r> emitter: colour r/g/b + facing ^ > v < + // T5 target needing exactly that colour mix (1 red, 2 green, 4 blue, sums mix) + // G4 colour gate: lets through only that colour + // F/ F% fixed mirror ("%" stands for a backslash) X/ X% fixed splitter + // Q/ Q% pivot mirror: turns in place but can't move + // M/ M% movable mirror S/ S% movable splitter (half reflects, half passes) + var TIERS = ["Reflect", "Split", "Spectrum", "Mastery"]; + var LEVELS = [ + { name: "First Light", tier: 0, par: 2, rows: [ + "r> .. .. .. .. ..", + ".. .. .. .. .. ..", + ".. .. .. .. .. ..", + ".. .. .. .. T1 ..", + ".. M/ .. .. .. .."], + sol: [[0,4,"M",1]] }, + { name: "Corner Pocket", tier: 0, par: 3, rows: [ + ".. .. .. .. .. ..", + "r> .. .. ## .. ..", + ".. .. .. ## .. ..", + ".. .. .. .. .. ..", + ".. ## .. .. .. ..", + ".. T1 .. M/ M/ .."], + sol: [[1,2,"M",1],[5,2,"M",0]] }, + { name: "Dogleg", tier: 0, par: 4, rows: [ + "r> .. .. F% .. .. ..", + ".. .. .. .. .. ## ..", + ".. ## ## .. .. ## ..", + ".. .. .. .. .. .. ..", + ".. .. ## ## ## .. T1", + "M/ M/ .. .. .. .. .."], + sol: [[3,3,"M",1],[3,6,"M",1]] }, + { name: "Crosswinds", tier: 0, par: 6, rows: [ + ".. .. .. .. .. .. ..", + "r> .. .. ## .. .. T1", + ".. .. .. .. .. .. ..", + ".. ## .. .. .. ## ..", + ".. .. .. .. .. .. ..", + "T1 .. .. ## .. .. r<", + ".. M/ M/ .. M/ M/ .."], + sol: [[1,2,"M",1],[5,2,"M",0],[5,4,"M",1],[1,4,"M",0]] }, + { name: "Pivot Hall", tier: 0, par: 3, rows: [ + "b> .. .. Q/ .. .. ..", + ".. ## .. .. .. ## ..", + ".. .. .. Q% .. .. ..", + ".. ## .. ## .. ## ..", + "T4 .. .. Q/ .. .. M/"], + sol: [[2,0,"M",0],[0,3,"Q",1],[2,3,"Q",0],[4,3,"Q",0]] }, + { name: "Fork", tier: 1, par: 1, rows: [ + ".. .. .. T1 .. ..", + ".. .. .. .. .. ..", + "r> .. .. .. .. T1", + ".. .. .. .. .. ..", + ".. S/ .. .. .. .."], + sol: [[2,3,"S",0]] }, + { name: "Trident", tier: 1, par: 5, rows: [ + ".. T1 .. .. .. .. ..", + ".. .. .. ## .. .. ..", + "r> .. .. .. .. .. ..", + ".. .. .. ## .. .. ..", + ".. .. .. .. .. .. T1", + "## .. .. .. T1 .. ..", + "S% S% M/ .. .. .. .."], + sol: [[2,1,"S",0],[2,4,"S",1],[2,6,"M",1]] }, + { name: "Glasshouse", tier: 1, par: 5, rows: [ + ".. .. :: T1 :: .. ..", + ".. .. :: .. :: .. ..", + "r> .. :: .. :: .. ..", + ".. .. .. .. .. .. ..", + ":: :: .. ## .. :: ::", + "T1 .. .. .. .. .. T1", + ".. S/ .. S/ .. M/ M/"], + sol: [[2,6,"M",1],[2,3,"S",0],[3,6,"S",0],[3,0,"M",0]] }, + { name: "Twin Engines", tier: 1, par: 3, rows: [ + "r> .. .. .. .. .. .. T1", + ".. .. .. .. .. .. ## ..", + "## .. .. .. .. ## .. ..", + ".. T1 .. .. .. .. .. ..", + ".. .. T1 .. ## .. ## ..", + ".. .. .. ## .. .. .. ..", + ".. .. .. .. .. .. .. r<", + "S/ .. M% S% .. T1 .. .."], + sol: [[0,2,"S",1],[6,1,"M",1],[6,5,"S",0]] }, + { name: "Hall of Mirrors", tier: 1, par: 3, rows: [ + ".. .. .. ## T1 ## .. .. ..", + ".. Q% .. .. .. .. .. .. T4", + ".. .. .. ## .. ## .. .. ..", + "## .. ## .. .. .. ## .. ..", + "r> .. .. .. X/ .. .. .. ..", + "## .. ## .. .. .. ## .. ..", + ".. .. .. ## .. ## .. .. ..", + ".. .. .. .. T1 .. .. F/ ..", + "M/ b^ .. ## .. ## .. .. S/"], + sol: [[4,7,"M",1],[1,1,"Q",0],[8,8,"S",0]] }, + { name: "Violet", tier: 2, par: 3, rows: [ + ".. .. .. .. .. ..", + "r> .. .. .. .. ..", + ".. .. ## .. .. ..", + ".. .. .. .. T5 ..", + ".. .. .. .. .. ..", + ".. b^ .. M/ M/ .."], + sol: [[1,4,"M",1],[3,1,"M",0]] }, + { name: "Gatekeeper", tier: 2, par: 6, rows: [ + "r> .. .. .. ## .. ..", + ".. .. .. .. G4 .. T4", + ".. .. .. .. ## .. ..", + ".. .. .. .. ## .. ..", + ".. .. .. .. ## .. ..", + ".. .. .. .. G1 .. T1", + "b> .. .. .. ## .. ..", + "M/ M/ .. M/ M/ .. .."], + sol: [[0,1,"M",1],[1,3,"M",0],[5,1,"M",1],[6,3,"M",0]] }, + { name: "Crossfire", tier: 2, par: 2, rows: [ + ".. .. .. gv .. .. ..", + ".. .. .. .. .. .. ..", + "r> .. .. .. .. .. T2", + ".. .. .. .. .. .. ..", + ".. .. .. .. .. .. ..", + ".. .. .. T1 .. .. ..", + "M/ M/ M/ .. .. .. .."], + sol: [[2,3,"M",1],[6,0,"M",0],[6,1,"M",0]] }, + { name: "White Room", tier: 2, par: 7, rows: [ + ".. .. .. gv .. .. ..", + ".. .. .. .. .. .. ..", + ".. .. .. ## .. ## ..", + ".. .. .. T7 .. .. ..", + ".. ## .. .. ## .. ..", + "r> .. .. .. .. .. ..", + ".. .. .. .. .. .. b<", + "M% M/ M/ M% M% M% .."], + sol: [[1,1,"M",0],[1,3,"M",0],[3,1,"M",1],[3,5,"M",1],[5,3,"M",0],[6,5,"M",1]] }, + { name: "Spectrum", tier: 2, par: 7, rows: [ + ".. .. .. ## .. .. .. ..", + "r> .. .. .. .. .. .. ..", + ".. .. .. .. .. .. .. ..", + ".. .. .. .. .. .. .. T3", + ".. .. ## .. .. ## .. ..", + ".. .. .. .. .. .. .. T6", + "M/ .. ## .. .. .. .. ..", + "M/ M/ M% S% g^ M/ b> .."], + sol: [[0,4,"M",0],[0,5,"M",0],[1,7,"M",1],[3,4,"M",0],[7,7,"M",0],[5,4,"S",0]] }, + { name: "Clockwork", tier: 3, par: 6, rows: [ + ".. .. .. ## .. .. ..", + ".. Q% .. Q% .. .. T1", + ".. .. .. .. .. ## ..", + "r> .. .. X/ .. Q/ ..", + ".. ## .. .. .. .. ..", + ".. Q% .. .. .. Q% ..", + ".. T1 .. T1 ## .. S%"], + sol: [[5,3,"S",0],[1,1,"Q",1],[1,3,"Q",0],[3,5,"Q",1],[5,1,"Q",0],[5,5,"Q",0]] }, + { name: "Lighthouse", tier: 3, par: 3, rows: [ + ".. .. .. T1 .. .. ..", + "T1 .. .. .. .. .. ..", + "T1 .. .. .. .. .. ..", + ".. ## .. .. .. .. ..", + ".. .. .. .. .. .. T1", + ".. .. .. .. .. ## ..", + ".. .. .. r^ .. .. ..", + "M/ S% S% .. S/ .. .."], + sol: [[1,3,"S",1],[2,3,"S",1],[4,3,"S",0],[7,0,"M",0]] }, + { name: "Aurora", tier: 3, par: 9, rows: [ + ".. g> .. .. .. .. .. .. ..", + ".. ## .. .. .. .. .. .. T4", + "r> .. .. .. .. .. .. .. T1", + ".. .. .. .. .. .. ## .. ..", + ".. .. .. .. T7 .. .. .. ..", + ".. .. ## .. .. .. ## .. ..", + ".. .. .. .. .. .. .. .. b<", + ".. .. ## .. .. .. .. .. ..", + "M/ M/ S/ M% M/ S% .. .. .."], + sol: [[0,4,"M",1],[1,7,"M",0],[2,2,"S",1],[4,2,"M",1],[6,4,"M",1],[6,7,"S",1]] }, + { name: "Prism Engine", tier: 3, par: 6, rows: [ + "r> .. .. .. .. G1 .. .. T1", + ".. ## .. .. .. .. .. ## ..", + ".. .. .. .. ## .. .. G4 ..", + ".. .. .. .. .. G1 .. .. T5", + "b> .. .. G4 .. .. .. .. T4", + ".. ## .. .. ## .. .. ## ..", + ".. .. .. .. .. .. .. .. ..", + ".. ## .. .. ## .. ## .. ..", + "S/ M/ M/ M% S% .. .. .. .."], + sol: [[0,2,"S",1],[2,6,"M",0],[2,8,"M",1],[3,2,"M",1],[4,6,"S",0]] } + ]; + + function parse(def) { + var rows = def.rows.map(function (r) { return r.trim().split(/\s+/); }); + var R = rows.length, C = rows[0].length; + var lv = { name: def.name, tier: def.tier, par: def.par, R: R, C: C, cells: [], emitters: [], targets: [], pieces: [] }; + for (var r = 0; r < R; r++) { + if (rows[r].length !== C) throw new Error(def.name + ": ragged row " + r); + for (var c = 0; c < C; c++) { + var t = rows[r][c], a = t[0], b = t[1], cell = { k: "floor" }; + var orient = b === "%" ? 1 : 0; + if (t === "..") cell = { k: "floor" }; + else if (t === "##") cell = { k: "wall" }; + else if (t === "::") cell = { k: "glass" }; + else if (COLOR_CH[a] && DIR_CH[b] != null) { cell = { k: "emitter", color: COLOR_CH[a], dir: DIR_CH[b] }; lv.emitters.push({ r: r, c: c, color: cell.color, dir: cell.dir }); } + else if (a === "T") { cell = { k: "target", need: +b }; lv.targets.push({ r: r, c: c, need: +b }); } + else if (a === "G") cell = { k: "gate", color: +b }; + else if (a === "F") cell = { k: "fixed", type: "mirror", o: orient }; + else if (a === "X") cell = { k: "fixed", type: "split", o: orient }; + else if (a === "Q") lv.pieces.push({ r: r, c: c, type: "mirror", o: orient, move: false }); + else if (a === "M") lv.pieces.push({ r: r, c: c, type: "mirror", o: orient, move: true }); + else if (a === "S") lv.pieces.push({ r: r, c: c, type: "split", o: orient, move: true }); + else throw new Error(def.name + ": bad token " + t); + lv.cells.push(cell); + } + } + return lv; + } + + // Trace every emitter. pieces: [{r,c,type,o}]. Returns segments for drawing, + // the colour mix arriving at each target, the set of cells beams cross, and solved. + function trace(lv, pieces) { + var R = lv.R, C = lv.C, n = R * C, occ = new Array(n), i; + for (i = 0; i < pieces.length; i++) occ[pieces[i].r * C + pieces[i].c] = pieces[i]; + var hit = {}, lit = new Uint8Array(n), segs = [], seen = {}; + for (var e = 0; e < lv.emitters.length; e++) { + var em = lv.emitters[e]; + var stack = [[em.r, em.c, em.dir]]; + while (stack.length) { + var s = stack.pop(), r = s[0], c = s[1], d = s[2], sr = r, sc = c; + for (var guard = 0; guard < 4 * n + 4; guard++) { + var nr = r + DR[d], nc = c + DC[d]; + if (nr < 0 || nc < 0 || nr >= R || nc >= C) { segs.push([em.color, sr, sc, nr, nc, 0]); break; } + r = nr; c = nc; + var idx = r * C + c, key = em.color + ":" + idx + ":" + d; + if (seen[key]) { segs.push([em.color, sr, sc, r, c, 1]); break; } + seen[key] = 1; + lit[idx] |= em.color; + var cell = lv.cells[idx], p = occ[idx]; + if (p || cell.k === "fixed") { + var type = p ? p.type : cell.type, o = p ? p.o : cell.o; + segs.push([em.color, sr, sc, r, c, 1]); + var nd = REFLECT[o][d]; + stack.push([r, c, nd]); + if (type === "split") stack.push([r, c, d]); + break; + } + if (cell.k === "wall" || cell.k === "emitter") { segs.push([em.color, sr, sc, r, c, 2]); break; } + if (cell.k === "target") { hit[idx] = (hit[idx] || 0) | em.color; segs.push([em.color, sr, sc, r, c, 1]); break; } + if (cell.k === "gate" && !(cell.color & em.color)) { segs.push([em.color, sr, sc, r, c, 2]); break; } + } + } + } + var solved = true, states = []; + for (i = 0; i < lv.targets.length; i++) { + var t = lv.targets[i], got = hit[t.r * C + t.c] || 0; + states.push(got); + if (got !== t.need) solved = false; + } + return { segs: segs, targets: states, lit: lit, solved: solved }; + } + + function placeable(lv, r, c) { return lv.cells[r * lv.C + c].k === "floor"; } + + // Search for placements that solve the level. Beams only care about pieces + // they touch, so each step places a spare piece on a floor cell a beam + // crosses; spare pieces left over are parked on dark floor cells. + function solve(lv, opts) { + opts = opts || {}; + var limit = opts.limit || 4000000; + var pivots = lv.pieces.filter(function (p) { return !p.move; }); + var movers = lv.pieces.filter(function (p) { return p.move; }); + var types = movers.map(function (p) { return p.type; }).sort(); + var best = null, nodes = 0, memo = {}; + function costOf(placed, pv, parked) { + var cost = 0, i; + for (i = 0; i < pivots.length; i++) if (pv[i] !== pivots[i].o) cost++; + // Assign start pieces to final spots of the same type (brute force). + var finals = placed.concat(parked); + var bestA = Infinity, used = new Array(finals.length); + (function rec(k, acc) { + if (acc >= bestA) return; + if (k === movers.length) { bestA = acc; return; } + var m = movers[k]; + for (var j = 0; j < finals.length; j++) { + if (used[j] || finals[j].type !== m.type) continue; + var f = finals[j], cst; + if (f.park) cst = f.r === m.r && f.c === m.c ? 0 : 1; + else cst = (f.r === m.r && f.c === m.c ? 0 : 1) + (f.o === m.o ? 0 : 1); + used[j] = true; rec(k + 1, acc + cst); used[j] = false; + } + })(0, 0); + return cost + bestA; + } + function tryParked(placed, pv, rest, res) { + // Park spares: keep them where they start if that spot is dark and free, else any dark free floor. + var taken = {}, i, parked = []; + placed.forEach(function (p) { taken[p.r * lv.C + p.c] = 1; }); + pivots.forEach(function (p) { taken[p.r * lv.C + p.c] = 1; }); + var restLeft = rest.slice(); + movers.forEach(function (m) { + var k = restLeft.indexOf(m.type), idx = m.r * lv.C + m.c; + if (k >= 0 && !taken[idx] && !res.lit[idx]) { restLeft.splice(k, 1); taken[idx] = 1; parked.push({ r: m.r, c: m.c, type: m.type, o: m.o, park: true }); } + }); + for (i = 0; i < lv.R * lv.C && restLeft.length; i++) { + if (taken[i] || res.lit[i] || lv.cells[i].k !== "floor") continue; + taken[i] = 1; + parked.push({ r: Math.floor(i / lv.C), c: i % lv.C, type: restLeft.shift(), o: 0, park: true }); + } + if (restLeft.length) return null; + return parked; + } + function full(placed, pv, parked) { + var all = placed.slice(); + pivots.forEach(function (p, i) { all.push({ r: p.r, c: p.c, type: p.type, o: pv[i] }); }); + if (parked) parked.forEach(function (p) { all.push(p); }); + return all; + } + function dfs(placed, pv, rest) { + if (++nodes > limit) return; + var key = pv.join("") + "|" + placed.map(function (p) { return p.r + "," + p.c + p.type[0] + p.o; }).sort().join(";"); + if (memo[key]) return; + memo[key] = 1; + var res = trace(lv, full(placed, pv, null)); + if (res.solved) { + var parked = tryParked(placed, pv, rest, res); + if (parked) { + var all = full(placed, pv, parked); + if (trace(lv, all).solved) { + var cost = costOf(placed, pv, parked); + if (!best || cost < best.cost) best = { cost: cost, pieces: all, placed: placed.length }; + } + } + } + if (!rest.length) return; + var occ = {}; + placed.forEach(function (p) { occ[p.r * lv.C + p.c] = 1; }); + pivots.forEach(function (p) { occ[p.r * lv.C + p.c] = 1; }); + var seenT = {}; + for (var t = 0; t < rest.length; t++) { + if (seenT[rest[t]]) continue; + seenT[rest[t]] = 1; + var nextRest = rest.slice(0, t).concat(rest.slice(t + 1)); + for (var i = 0; i < res.lit.length; i++) { + if (!res.lit[i] || occ[i] || lv.cells[i].k !== "floor") continue; + for (var o = 0; o < 2; o++) { + dfs(placed.concat([{ r: Math.floor(i / lv.C), c: i % lv.C, type: rest[t], o: o }]), pv, nextRest); + } + } + } + } + for (var mask = 0; mask < (1 << pivots.length); mask++) { + var pv = pivots.map(function (p, i) { return (mask >> i) & 1; }); + dfs([], pv, types); + } + return { best: best, nodes: nodes, truncated: nodes > limit }; + } + + + // Fewest drags and turns needed to go from the start layout to a solution + // layout (pieces of one kind are interchangeable, so try every pairing). + function solutionCost(lv, sol) { + var cost = 0, movers = [], finals = []; + lv.pieces.forEach(function (p) { + if (!p.move) { + var f = sol.filter(function (s) { return s[2] === "Q" && s[0] === p.r && s[1] === p.c; })[0]; + if (f && f[3] !== p.o) cost++; + } else movers.push(p); + }); + sol.forEach(function (s) { if (s[2] !== "Q") finals.push(s); }); + var best = Infinity, used = []; + (function rec(k, acc) { + if (acc >= best) return; + if (k === movers.length) { best = acc; return; } + var m = movers[k], want = m.type === "split" ? "S" : "M"; + for (var j = 0; j < finals.length; j++) { + var f = finals[j]; + if (used[j] || f[2] !== want) continue; + used[j] = true; + rec(k + 1, acc + (f[0] === m.r && f[1] === m.c ? 0 : 1) + (f[3] === m.o ? 0 : 1)); + used[j] = false; + } + })(0, 0); + return cost + best; + } + // Scripted check: the stored solution uses exactly the level's pieces, + // leaves pivots where they are, sits on free floor and lights every target. + function checkSolution(lv, sol) { + var errs = [], seen = {}, i; + var want = lv.pieces.map(function (p) { return p.move ? (p.type === "split" ? "S" : "M") : "Q@" + p.r + "," + p.c; }).sort().join(); + var got = sol.map(function (s) { return s[2] === "Q" ? "Q@" + s[0] + "," + s[1] : s[2]; }).sort().join(); + if (want !== got) errs.push("piece set differs"); + for (i = 0; i < sol.length; i++) { + var s = sol[i], key = s[0] + "," + s[1]; + if (seen[key]) errs.push("two pieces on " + key); + seen[key] = 1; + if (s[2] !== "Q" && !placeable(lv, s[0], s[1])) errs.push("piece on non-floor " + key); + } + var pieces = sol.map(function (s) { return { r: s[0], c: s[1], type: s[2] === "S" ? "split" : "mirror", o: s[3] }; }); + if (!trace(lv, pieces).solved) errs.push("solution does not light every target"); + if (trace(lv, lv.pieces).solved) errs.push("level starts solved"); + return errs; + } + + var api = { TIERS: TIERS, LEVELS: LEVELS, parse: parse, trace: trace, solve: solve, placeable: placeable, solutionCost: solutionCost, checkSolution: checkSolution, REFLECT: REFLECT, DR: DR, DC: DC }; + if (typeof module === "object" && module.exports) module.exports = api; + else root.LumenCore = api; +})(this); diff --git a/games/lumen/index.html b/games/lumen/index.html new file mode 100644 index 0000000..90d92cd --- /dev/null +++ b/games/lumen/index.html @@ -0,0 +1,650 @@ + + + + + + Lumen | RMKR Toolkit + + + + + + +
+ ← Focus Games +

Lumen

+

Lasers burn across a dark lab. Drag mirrors and splitters into their path and turn them until every target glows with exactly the colour it asks for.

+ +
+ How to play +
    +
  • Drag a gold-framed piece to any empty floor tile to move it. Drop it on another movable piece to swap them. Tap a piece to turn it a quarter turn.
  • +
  • Mirrors bounce a beam 90°. Splitters (dashed glass) bounce half the beam and let the other half through.
  • +
  • Pivots sit on a round base: they turn but can't be moved. Grey pieces are bolted down.
  • +
  • Targets show the colour they need around their ring. Red and blue make magenta, red and green make yellow, green and blue make cyan, and all three make white. A target fed the wrong mix stays dark.
  • +
  • Walls stop beams. Glass lets beams through but nothing can stand on it. A coloured gate only lets its own colour pass.
  • +
  • Every move counts: a drag, a swap or a turn. Solve in par moves for ★★★, within par + 3 for ★★, any solve earns ★.
  • +
  • Undo takes back a move and Restart resets the level. Levels open one after another; your stars stay in this browser only.
  • +
  • Keyboard: arrow keys move the cursor, Enter or Space picks up and drops a piece, X turns it, U or Backspace undoes, R restarts, P pauses, L opens levels, N goes to the next level, Esc cancels.
  • +
+
+ +
+
+ Level: — + Moves: 0 + Par: — + Time: 0:00 + Stars: 0 +
+
+ + +
+
+

Pick a level to begin.

+ +
+
+
+ +
+
+
+ + + + diff --git a/scripts/verify-lumen.mjs b/scripts/verify-lumen.mjs new file mode 100644 index 0000000..51f3343 --- /dev/null +++ b/scripts/verify-lumen.mjs @@ -0,0 +1,29 @@ +#!/usr/bin/env node +/** + * Lumen (games/lumen/) level check. + * For every level: the stored solution uses exactly the level's pieces and + * lights every target, the level does not start solved, and par equals the + * fewest moves to reach that solution. A bounded independent search then + * tries to solve each level from scratch as a second opinion. + */ +import { createRequire } from "node:module"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; + +const require = createRequire(import.meta.url); +const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); +const L = require(path.join(root, "games/lumen/core.js")); +let failed = 0; +L.LEVELS.forEach((def, i) => { + const lv = L.parse(def); + const errs = L.checkSolution(lv, def.sol); + const cost = L.solutionCost(lv, def.sol); + if (cost !== def.par) errs.push(`par ${def.par} but stored solution takes ${cost}`); + const s = L.solve(lv, { limit: 150000 }); + const search = s.best ? `search solved (${s.best.cost} moves)` : s.truncated ? "search budget hit" : "search found none"; + if (!s.best && !s.truncated) errs.push("exhaustive search found no solution"); + console.log(`${String(i + 1).padStart(2)} ${def.name.padEnd(16)} ${L.TIERS[def.tier].padEnd(9)} par ${def.par} ${errs.length ? "FAIL " + errs.join("; ") : "ok"} · ${search}`); + if (errs.length) failed++; +}); +console.log(failed ? `${failed} level(s) failed` : `All ${L.LEVELS.length} levels verified solvable.`); +process.exit(failed ? 1 : 0);