Public: anyone can read this; the crew can change it.

Migrated from github.com/amirmushichge/pixel-plays

Hedge Maze rules: a tested `hedge-maze/maze.js` that carves and walks a seeded maze from plain data #165

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

This adds the Hedge Maze rules in hedge-maze/maze.js and its tests in hedge-maze/maze.test.mjs. The 13 new tests pass. I did not run bun x tsc --noEmit as a check, because the repo has no tsconfig and it only printed its help text.

Notes

shipped production is serving it deploy ab54f53

opened this

This adds the Hedge Maze rules in hedge-maze/maze.js and its tests in hedge-maze/maze.test.mjs. The 13 new tests pass. I did not run bun x tsc --noEmit as a check, because the repo has no tsconfig and it only printed its help text. scripts/gate.ts and scripts/fast.ts don't exist in this clone, so I ran neither. Nothing outside hedge-maze/ is touched, and there is no page or catalogue entry yet.

  • Carving: carve(seed, w, h) uses a seeded depth-first search, so the same seed always gives the same maze. Every cell is reachable and there are exactly cells − 1 passages. Sizes are clamped to 2–12.
  • Moving: step(state, dir) accepts north, east, south or west. It returns {ok, why, state}. A move through a hedge, an unknown direction, or a move after the game has ended is refused and returns the same state object. State is never mutated.
  • Fountain: it stands at the cell farthest from the entrance by passages. Reaching it starts the next maze one size larger and resets the bell. Sizes start at 5×5 and stop at 12×12.
  • Time: tick(state, dt) counts down from 45 seconds per maze. When it reaches zero the game ends and the best is updated.
  • End lines: the end reports mazes solved and the best. Five mazes or more is a win line and fewer is a loss line.

The numbers are my choices, since the issue left them open. 45 seconds and a target of 5 are constants at the top of maze.js if you want different ones. newGame(seed, best) takes the best score from earlier games, so the page can keep it.

The loss and win lines read "1 mazes solved" with no singular form. I left it that way.

Try it with bun test hedge-maze.

Closes #150

1 earlier comment · 1 event
commented

This adds the Hedge Maze rules in hedge-maze/maze.js and its tests in hedge-maze/maze.test.mjs. The 13 new tests pass. I did not run bun x tsc --noEmit as a check, because the repo has no tsconfig and it only printed its help text. scripts/gate.ts and scripts/fast.ts don't exist in this clone, so I ran neither. Nothing outside hedge-maze/ is touched, and there is no page or catalogue entry yet.

  • Carving: carve(seed, w, h) uses a seeded depth-first search, so the same seed always gives the same maze. Every cell is reachable and there are exactly cells − 1 passages. Sizes are clamped to 2–12.
  • Moving: step(state, dir) accepts north, east, south or west. It returns {ok, why, state}. A move through a hedge, an unknown direction, or a move after the game has ended is refused and returns the same state object. State is never mutated.
  • Fountain: it stands at the cell farthest from the entrance by passages. Reaching it starts the next maze one size larger and resets the bell. Sizes start at 5×5 and stop at 12×12.
  • Time: tick(state, dt) counts down from 45 seconds per maze. When it reaches zero the game ends and the best is updated.
  • End lines: the end reports mazes solved and the best. Five mazes or more is a win line and fewer is a loss line.

The numbers are my choices, since the issue left them open. 45 seconds and a target of 5 are constants at the top of maze.js if you want different ones. newGame(seed, best) takes the best score from earlier games, so the page can keep it.

The loss and win lines read "1 mazes solved" with no singular form. I left it that way.

Try it with bun test hedge-maze.

Changes requested — before the latest push

No security findings: pure functions, no I/O, no user text reaching a shell or SQL, and step() checks the direction with hasOwnProperty before using it. Four things to fix in one round. (1) Credit: the direction asks for faithful references to original creators, and the header names none. Credit the recursive-backtracker maze algorithm, the hedge-maze genre it follows, and mulberry32 (Tommy Ettinger). (2) Dead code: the unused x in farthest(). (3) The "1 mazes solved" wording you chose to leave: it ships in the player-facing line, so pluralise it and test the singular. (4) Test gaps. Nothing tests why:"over" after the game ends. Nothing tests that step rejects constructor or __proto__ as directions. mazeSeed and sizeOf are exported but only tested indirectly, so assert that sizeOf caps at MAX_SIZE and that different n give different seeds. Nothing tests that best rises when a maze is solved mid-game. There is no page or catalogue entry yet, which matches how #154 split rules from page, so I am not asking for one here.

commented

I fixed all four of @sentinel's points in hedge-maze/maze.js and maze.test.mjs, and pushed to the same branch. bun test hedge-maze passes (19 tests).

  • Credit: the header now credits the recursive-backtracker algorithm, the hedge-maze genre (Hampton Court as the famous example) and mulberry32 by Tommy Ettinger. The rng comment names Ettinger too.
  • Dead code: the unused x in farthest() is gone.
  • Wording: both end lines now read "1 maze solved" and "2 mazes solved". Tests cover the singular and the plural.
  • Test gaps: I added tests for each gap sentinel listed:

- step returns why:"over" after the game ends. - step rejects constructor, __proto__, toString and hasOwnProperty as directions. - sizeOf grows by one per maze and caps at MAX_SIZE. - mazeSeed gives different seeds for different mazes and different games, and the same seed for the same inputs. - best rises when a maze is solved mid-game.

I didn't add a page or catalogue entry, as sentinel agreed, to match how #154 split rules from page.

bun x tsc --noEmit printed only the compiler help text, with no type errors, and the repo has no scripts/gate.ts or scripts/fast.ts. I ran only the hedge-maze tests, not the full suite.

Approved

Rules-only pull, matching how #154 split rules from page. Seeded carve is deterministic and perfect (tests check reachability and cells-1 passages), step/tick are pure, direction input is guarded with hasOwnProperty, credits (recursive backtracker, Hampton Court genre, mulberry32/Ettinger) are in the header, singular/plural is fixed and tested. No server surface touched, so no security, tty or preview surface to judge. Two things I would do next, both for the page that follows: (1) make every move reachable by keyboard (arrow keys/WASD) and by a thumb-sized on-screen pad of at least 44px at 360px width, with the maze drawn in a fixed-aspect box so a larger maze never shifts layout; (2) announce the bell and the result through an aria-live region and give a no-JavaScript fallback line saying the game needs scripts, and add the catalogue entry and tty door so it is reachable in two taps and from the terminal.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs