feat/maze-backtracker #174

Merged
OragonEfreet merged 3 commits from feat/maze-backtracker into main 2026-07-31 16:28:57 +02:00
Owner
No description provided.
OragonEfreet added this to the 1.1 milestone 2026-07-31 16:11:12 +02:00
The recursive backtracker of the literature, without the recursion. It
walks on to a neighbour it has never stood on until it is boxed in by its
own ground, then falls back one cell at a time along the way it came
until it finds somewhere left to go. Falling back off the cell it started
from ends the generation.

It is the twin of hunt-and-kill: both are walks that never retread, and
they part company only over what to do at a dead end. Hunt-and-kill scans
the grid for somewhere to resume, paying O(n) a time and keeping nothing;
this one retraces its own steps, paying O(1) a time and keeping the way
home. The result is the most lopsided of the six and the most deliberate
looking, with the longest and most winding corridors and few dead ends.

It names no direction and only asks for neighbours, so it works on any
family.

One byte per cell, where the book would keep a stack of cell indices and
a visited set. Each cell records which of its slots faces the cell it was
reached from; two values of that byte are spoken for, one for a cell
never stood on and one for the cell the walk began at, which cannot be
mistaken for a slot since a link byte caps a cell at eight of them. That
is a fifth of the five bytes a stack and a visited set would want, and
nothing scales with how deep the walk goes.

Which slot of the new cell faces the old one is asked of the adjacency
rather than derived, since only the family knows: a handful of
comparisons per carved cell, and no assumption that a maze has opposites
at all.

The path marks earn their keep here for the first time. The cells marked
as a path are exactly the ones a recursive version would be holding on
its call stack, so watching a run shows that path grow and retreat, which
no other algorithm here does.

Five cases, checked by mutation against a fresh build each time: walking
onto covered ground, leaving the head or the path behind when falling
back, and failing to mark the start cell as the root are all caught. So
is storing the outward slot instead of the facing one, which sends the
retreat the wrong way -- that one leaves the algorithm unable to settle,
so the case counts steps under a cap and holds them to the two per cell
less one that a finished run takes, rather than looping until something
else gives up.
The table held only names, and a block in the setup filled in the
algorithms afterwards, so which algorithm a label belonged to was two
places away and kept in step by hand.

The table now holds the getter rather than what it returns, which puts
the two together on one line and lets the block go. Calling it moves to
where the builder is made.

Naming the algorithms in the table directly does not work: an object that
outlives the program's start has to be initialised with a constant, and
these are function calls. C++ allows exactly that and the compatibility
job compiles the examples as C++, so the direct form would have passed
that job while breaking the C build it exists to protect.
.
All checks were successful
C++ Compatibility / C++ Compatibility Check (pull_request) Successful in 7s
Documentation / build-docs (pull_request) Successful in 8s
QA / cert (pull_request) Successful in 29s
Build and Test / linux-linux-gcc / shared (pull_request) Successful in 17s
Build and Test / linux-linux-gcc / static (pull_request) Successful in 17s
Build and Test / linux-windows-mingw / shared (pull_request) Successful in 26s
Build and Test / linux-windows-mingw / static (pull_request) Successful in 26s
aeb305d05e
OragonEfreet deleted branch feat/maze-backtracker 2026-07-31 16:28:57 +02:00
OragonEfreet referenced this pull request from a commit 2026-07-31 16:28:58 +02:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
OragonEfreet/banjo!174
No description provided.