pub struct Prim { /* private fields */ }
Expand description
The Prim’s algorithm for generating mazes
The original version of the algorithm generates a minimal spanning tree in a graph. With one little change, it becomes a suitable method for generating mazes.
Mazes generated by Prim’s algorithm share many of the characteristics of those created via Kruskal’s algorithm, such as having an abundance of short cul-de-sacs which makes the maze harder to puzzle out at a glance
Implementations§
Trait Implementations§
Source§impl Algorithm for Prim
An implementation of the Prim’s algorithm for generating mazes
impl Algorithm for Prim
An implementation of the Prim’s algorithm for generating mazes
For efficiency, let’s define a legend for the following algorithm steps:
- “F” or “frontier”: the set of all cells that are not yet in the maze, but are adjacent to a cell that is in the maze.
The standard version of the algorithm generates a minimal spanning tree in a graph. With a slight change of adding some random, it works something like this:
-
Chooses an arbitrary cell and adds it to the maze.
-
Adds all neighbor cells that are not in the F yet to F.
-
Removes one of the F cells at random and carves a passage from that to whichever adjacent cell is already part of the maze.
-
Adds the neighbours of the formerly frontier cell to the F.
-
Repeats steps 3 and 4 until the F is empty.
Auto Trait Implementations§
impl Freeze for Prim
impl RefUnwindSafe for Prim
impl Send for Prim
impl Sync for Prim
impl Unpin for Prim
impl UnwindSafe for Prim
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.