pub struct KitchenFloor { /* private fields */ }
Expand description

An implementation of the infinite hexagonally tiled kitchen floor Andy unwittingly found himself walking around on this morning.

To implement this, we can use a coordinate system (x, y), where each hexagon, including the black ones, has a coordinate assigned.

There are two distinct types of white hexagon, which we can characterise by the compass directions we can move to adjacent white hexagons: A. (NW, SW, E) B. (W, NE, SE)

We can map the co-ordinates of any given white hexagon to ascertain its type by:

hex_type: bool = (y % 3) == (3 - x) % 3

The available moves in each case are:

  • hex_type == 0: (x, y) -> [(x+1, y+1), (x, y-1), (x-1, y)]
  • hex_type == 1: (x, y) -> [(x, y+1), (x-1, y-1), (x+1, y)]

Trait Implementations§

source§

impl RandomWalk for KitchenFloor

§

type State = (i32, i32)

The representation of state in this state machine.
source§

fn make_move<R: Rng>(&mut self, _rng: &mut R)

Make a random move on the internal state machine.
source§

fn get_state(&self) -> Self::State

Return the current state of the machine.
source§

fn set_state(&mut self, state: Self::State)

Set the state of the internal state machine.
source§

fn walk<R: Rng>( &mut self, src: Self::State, tgt: Self::State, rng: &mut R ) -> u32

Perform a random walk, starting at src, and making random moves until the tgt state is reached. This does not terminate at zero steps if src and tgt are the same, a move is always made first before continuing until tgt. Read more
source§

fn walk_until_limit<R: Rng>( &mut self, src: Self::State, tgt: Self::State, rng: &mut R, limit: u32 ) -> Result<u32, u32>

Same as walk_until, but also takes a limit parameter, specifying the maximum length of the walk we should allow before bailing out. Returns Ok(num_steps) if tgt is reached at or before the limit, and Err(limit) otherwise. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

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

§

fn vzip(self) -> V