Struct andys_morning_stroll::KitchenFloor
source · 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) % 3The 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
impl RandomWalk for KitchenFloor
source§fn make_move<R: Rng>(&mut self, _rng: &mut R)
fn make_move<R: Rng>(&mut self, _rng: &mut R)
Make a random move on the internal state machine.
source§fn walk<R: Rng>(
&mut self,
src: Self::State,
tgt: Self::State,
rng: &mut R
) -> u32
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 moresource§fn walk_until_limit<R: Rng>(
&mut self,
src: Self::State,
tgt: Self::State,
rng: &mut R,
limit: u32
) -> Result<u32, u32>
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