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

feat(hexmap): bit-sliced hex cave generator (L4) - #127

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

bal7hazar merged 1 commit into
mainfrom
feat/hexmap-caver

Conversation

@bal7hazar

Copy link
Copy Markdown
Collaborator

Summary

Lot L4 of origami_hexmap: the hex cave generator.

  • Caver::generate(width, height, order, seed): ~50 % random fill of the interior (one Poseidon permutation), then order synchronous generations of a 6-neighbour automaton, rule B4/S2, computed on the whole bitmap at once. order == 0 returns the initial fill.
    • Neighbour planes are field shifts of the grid (one parity split per generation).
    • Carry-save count with the bitwise builtin called directly: one application gives AND, XOR and OR, so a full adder costs 2 applications and carries are additions of disjoint bitmaps.
    • No interior mask on born tiles: a border tile has at most 3 interior neighbours.
    • u128 single-limb path for boards of at most 128 bits.
  • Caver::keep_component(grid, width, height, from): flood fill by Layout::expand. It stays separate from generate because it costs about 2x generate(17, 14, 3).

Gas (sierra gas, snforge)

Measured Target
One generation, 17x14 35_710 < 60_000
generate(17, 14, 3, seed) 146_747 < 250_000
One generation, 7x7 (single limb) 16_030
keep_component on a 17x14 cave 300_925
origami_map Caver::generate(18, 14, 2) (for the record) ~85_000_000

All the required variants are measured in bench_caver.cairo and listed in GAS.md (L4 section). They cover rules B4/S2, B4/S3 and B3/S3, fills of 25/50/75 %, the design's AND-only adder network (+46 %), corelib u256 operators (+30 %), planes from shared sub-terms (+11 %), design parity-split planes (+1 %), and the u256 path against the u128 path on 7x7 (-60 %). Every variant is checked against a scalar reference automaton.

Note for review

caver.cairo declares extern fn bitwise(u128, u128) -> (u128, u128, u128). This is the same libfunc that the corelib keeps private. If it gets promoted to helpers/bits.cairo, other lots can use it too.

🤖 Generated with Claude Code

Caver::generate runs a synchronous B4/S2 cellular automaton on the whole
board at once: 6 neighbour planes as field shifts, a carry-save count
with the bitwise builtin called directly (AND, XOR and OR in one
application), and a u128 single-limb path for boards of at most 128 bits.
Caver::keep_component keeps the floor connected to a position.

17x14: 35.7k gas per generation, generate(17, 14, 3) 146.7k.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bal7hazar
bal7hazar merged commit b262294 into main Sep 27, 2026
9 checks passed
@bal7hazar
bal7hazar deleted the feat/hexmap-caver branch September 27, 2026 14:16
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