The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Array::Tour::RandomWalk - Return coordinates to take a random path.

SYNOPSIS

      use Array::Tour::RandomWalk qw(:directions);
  
      my $rndwalk = Array::Tour::RandomWalk->new(
          dimensions => [13, 7, 1],
          start => [0, 0, 0]
          backtrack => "queue",
          );

The object is created with the following attributes:

dimensions

Set the size of the grid:

        my $spath1 = Array::Tour->new(dimensions => [16, 16]);

If the grid is going to be square, a single integer is sufficient:

        my $spath1 = Array::Tour->new(dimensions => 16);
start

Default value: [0, 0, 0]. Starting point of the random walk.

backtrack

Default value: 'queue'. Method of looking up cells to backtrack to. As the random walk is made, cells where there were more than one direction to go are stored in a list. When the random walk hits a dead end, it goes back to a cell in the list. By default, the list is treated as a queue: the first cell on the list is the first cell used.

If backtrack is set to 'stack', the list is treated as a stack: the last cell on the list is the first cell used.

The final choice, 'random', will choose a cell at random from the list.

The new() method is defined in the Array::Tour class. Attributes unique to this class are dealt with in its own _set() method.

PREREQUISITES

Perl 5.8 or later. This is the version of perl under which this module was developed.

DESCRIPTION

A simple iterator that will return the coordinates of the next cell if one were to randomly tour a matrix.

direction()

Returns the current direction as found in the :directions EXPORT tag.

Overrides Array::Tour's direction() method.

Tour Object Methods

next()

Returns an array reference to the next coordinates to use. Returns undef if the object is finished.

Overrides Array::Tour's next() method.

Internal Tour Object Methods

_set()

  $self->_set(%attributes);
  

Overrides Array::Tour's _set() method.

_random_dir()

The default function used to perform the random walk.

The function may be overridden if a function is referenced in {wander}. This function will take two arguments, a reference the list of possible directions to move to, and a reference to the position (an array of [column, row, level]).

_collect_dirs()

  @directions = $obj->_collect_dirs($c, $r, $l);

Find all of our possible directions to wander through the array. You are only allowed to go into not-yet-broken cells. The directions are deliberately accumulated in a counter-clockwise fashion.

_break_through()

See Also

Array::Tour Games::Maze

AUTHOR

John M. Gamble may be found at <jgamble@cpan.org>