Struct Prim

Source
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§

Source§

impl Prim

Source

pub const fn new() -> Prim

Create a new instance of the algorithm with an empty set of the frontier cells

Trait Implementations§

Source§

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:

  1. Chooses an arbitrary cell and adds it to the maze.

  2. Adds all neighbor cells that are not in the F yet to F.

  3. Removes one of the F cells at random and carves a passage from that to whichever adjacent cell is already part of the maze.

  4. Adds the neighbours of the formerly frontier cell to the F.

  5. Repeats steps 3 and 4 until the F is empty.

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
Source§

impl Default for Prim

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> 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<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
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