Sitelet https://github.com/dojoengine/origami/pull/129
Skip to content

feat(hexmap): hex maze generator and digger (L5) - #129

Merged
bal7hazar merged 1 commit into
mainfrom
feat/hexmap-mazer
Sep 27, 2026
Merged

bal7hazar merged 1 commit into
mainfrom
feat/hexmap-mazer

Conversation

@bal7hazar

Copy link
Copy Markdown
Collaborator

Summary

Lot L5 of origami_hexmap: Mazer::generate, Digger::corridor and Digger::maze.

  • Mazer: randomised backtracker over the 6 directions, interior only. A candidate is tested with one mask test maze & 2^c * K (K: field constant per direction and parity). Only the 3 forward neighbours of a tile are candidates (the other two touch its parent), and a carved middle candidate excludes both sides without a test. The direction logic is specialised at compile time (Heading impls).
    • Order 0: the current tile is the candidate's only open neighbour (one-tile corridors and walls).
    • Order 1: in addition, no open tile lies at distance 2 of the candidate except the three tiles behind the current one. So two open tiles at distance 2 always share an open neighbour, and corridors never run side by side. Pictures are in the doc comment.
    • Order >= 2: panics with Mazer: order > 1 not supported (same message as origami_map). The order is asserted once.
  • Digger: opens the edge entrance (not a corner), steps to an interior neighbour (an open one if any, otherwise drawn at random), then digs with the same rule against its own tiles. As soon as a dug tile touches an open tile of the grid, corridor stops and maze merges the grid and keeps growing.

Gas (17x14, sierra gas)

Measured Per tile
generate(17, 14, 0) (target < 3M) 2_875_890 32_314
generate(17, 14, 1) 1_826_661 39_710
corridor (3x2 room) 314_852 34_984
maze (3x2 room) 3_229_661 35_885
origami_map 18x14 maze, order 0 27_966_300 229_232

Every variant from the brief is implemented and measured in tests/bench_mazer.cairo: explicit stack +51 %, per-neighbour bit tests +220 %, felt maze +1.9 %, DivRem coordinates +12.4 %, lazy draws +7.4 %, shuffle6 +199 %, rotation order -1.7 % per tile (not adopted: below 2 % and biased). Iteration history is in GAS.md.

Tests

  • Exact grids on fixed seeds (drawings in comments) for 17x14, 19x13, 7x7 and 3x3, both orders. Digger in both modes.
  • Invariants: interior only, determinism, 83x3 and 3x83 extremes, connectivity by flood fill on Layout::expand, tree property (edges = tiles - 1), the order-1 distance-2 rule, and every carve mask checked against its definition from Geometry::distance.
  • Digger: every non-corner edge of 7x7 and 3x3, and corridor == maze when nothing is reachable.
  • Panics: order, corner, non-edge, dimensions.

Deviation

The digger stops (or merges) when a dug tile touches the open area. origami_map stops when it steps onto it. On hexes, touching already means connected; stepping onto it made corridors run along the room before entering it.

🤖 Generated with Claude Code

Mazer::generate: randomised backtracker over 6 directions with one mask
test per candidate (2^c * K, K a per-direction field constant), only the
3 forward neighbours as candidates, per-direction code via Heading impls.
Order 0: one-tile corridors and walls; order 1: two open tiles at distance
2 always share an open neighbour; order >= 2 panics.

Digger::corridor / Digger::maze: open an edge entrance and dig with the
same rule until the dug tiles touch the original grid (stop or merge).

17x14 order 0: 2.88M gas (32k per tile, origami_map 229k per tile).
Variants and budgets in GAS.md and tests/bench_mazer.cairo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bal7hazar
bal7hazar merged commit 58f8acf into main Sep 27, 2026
9 checks passed
@bal7hazar
bal7hazar deleted the feat/hexmap-mazer branch September 27, 2026 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant