feat(hexmap): random walk generator (L6) - #131
Merged
Merged
Conversation
Walker::generate: seed-selected interior start, `steps` moves in a loop, each move draws one of the 6 directions, moves if the target is interior and opens the tile. 4.8k-5.3k gas per step on 17x14 (origami_map: ~60k). - one pool division by 216 per three moves, 216-arm table (called once), counter-based pool refill - doubled column `2x + (y & 1)` and one-hot position: felt-only bound tests and moves, no parity branch - positions of three moves summed (one equality) and ORed once - 18 moves per loop iteration Benchmarks for the winner and the losing variants (random source, move, grid accumulation, loop shape), with budgets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements
Walker::generate(width, height, steps, seed)inorigami_hexmap(lot L6): start on a seed-selected interior tile, thenstepsmoves in a loop. Each move draws one of the 6 directions, moves if the target is interior (stays otherwise) and opens the tile.steps == 0returns only the start tile.Gas (17x14): 4.8k-5.3k per step, under the 6k target.
For reference,
origami_map's walker test (18x14, 500 steps) reports 29.9M.Design (details in
GAS.md, section L6)pool < 2^32test.c = 2x + (y & 1), row, and one-hot position2^i, all felts. Bound tests are felt equalities with no parity branch. The state carries the NorthEast factor for both row parities and swaps them on vertical moves, so a move is one field product.u256once, and converted to a felt once at the end.The losing variants required by the brief are kept test-only in
bench_walker.cairo, with their numbers inGAS.md:next_below, 3-bit digits with rejection, pair table(x, y)with a parity bool, index plus mask test, one-hot plus ANDTests
neighborplus bit test and set, on the same draws):🤖 Generated with Claude Code