Struct RecursiveDivision

Source
pub struct RecursiveDivision;
Expand description

The “Recursive Division” algorithm for generating mazes

According to Wikipedia and James Buck’s maze generation blogs this algorithm should be implemented as a wall adder, as opposed to the rest of the algorithms in this library which are designated as “passage carvers”. In a nutshell, the idea is to recursively divide the original grid with no walls — call this a “chamber” — into smaller subchambers with randomly positioned walls and single passages within them. This fractal nature makes this algorithm novel. You could theoretically continue the process indefinitely at progressively finer and finer levels of detail on demand. This may be useful when developing a game where a player wanders from one section of the maze to another without a need to store the entire maze in the memory.

My implementation of this algorithm is a bit different from the above. The design of this library supports only the passage-carving technique (mixing both techniques would lead to an uglier API and less efficient generation mechanism, which I tested using benchmarks). Given that I’ve slightly modified the algorithm to be rather a “passage carver”. The method and its fractal nature remain though. Of course, the generation process would be less fancy this way, but this library has nothing to do with visualizing the generation progress step-by-step. If you’re interested in this side of the maze generation world, feel free to check my other program for the terminal called Daedalus.

It’s also worth mentioning that the algorithm’s fractal nature leads to some visual artifacts and bottlenecks like a single passage between two sections that effectively divide the entire maze into two distinct regions, thus making it easy to spot the passage and work backward to a solution.

Trait Implementations§

Source§

impl Algorithm for RecursiveDivision

An implementation of the “Recursive Division” algorithm for generating mazes

It works like this:

  1. Begins with an original grid as a working field.

  2. Bisects the field either horizontally or vertically by carving a passage through the wall from a random cell.

  3. Repeats step #2 with the areas on either side of the wall where the passage was carved.

  4. Continues, recursively, until the maze reaches the desired resolution.

Source§

fn generate(&mut self, grid: &mut Grid, rng: &mut StdRng)

Runs algorithm through the given Grid object, thus mutating the grid and generating a new maze

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V