Game-Life-Faster

 view release on metacpan or  search on metacpan

lib/Game/Life/Faster.pm  view on Meta::CPAN

text. Specifically, the returns are the number of the first row that
contains a living cell, the number of the column that contains the first
living cell, and the text grid with each line C<"\n">-terminated.

If there are no living cells, nothing is returned.

If called in scalar context you get the living portion of the grid.

=head2 get_used_grid

 use Data::Dumper;
 print Dumper( $life->get_used_grid() );

This method is similar to L<get_grid()|/get_grid>, but only returns
cells that have actually been assigned a value, or acquired a value in
the course of processing. Cells that have never had a value are
represented by C<undef>. Trailing C<undef>s in a row are suppressed.
Rows consisting only of unused cells are represented by C<undef>, not
C<[]>, and trailing C<undef> rows are also suppressed.

=head2 place_points

 $life->place_points( $x, $y, $array );

This method populates a portion of the grid whose top left corner is
specified by C<$x> and C<$y> with the state information found in
C<$array>. This is a reference to an array of array references.  Each
value of the inner array represents the state of the corresponding cell,
with a true value representing "living," and a false value representing
"dead."

As an incompatible change to the same-named method of
L<Game::Life|Game::Life>, points whose value is C<undef> are ignored.

=head2 place_text_points

 $life->place_text_points( $x, $y, $living, @array );

This method populates a portion of the grid whose top left corner is
specified by C<$x> and C<$y> with the state information found in the
text of C<@array>, one row per element. Characters in C<@array> that
match the character in C<$living> cause the corresponding cells to be
made "living." All other characters cause the cell to be made "dead."
This method interprets the strings in C<@array> as new state

As an incompatible change to the same-named method of
L<Game::Life|Game::Life>, if C<@array> contains exactly one element
B<and> that element contains new line characters, it is split on new
lines, allowing something like

 $life->place_text_points( 0, 0, 'X', <<'EOD' );
 .X.
 ..X
 XXX
 EOD

The heavy lifting is done by L<set_point_state()|/set_point_state>.

=head2 process

 $life->process( $iterations );

This method runs the game for the specified number of iterations, which
defaults to C<1>.

As an incompatible change to the same-named method of
L<Game::Life|Game::Life>, the number of points that actually changed
state is returned. If C<$iterations> is greater than C<1>, the return
represents the last iteration. The corresponding
L<Game::Life|Game::Life> method does not have an explicit C<return>.

=head2 set_point

 $life->set_point( $x, $y );

This method sets the state of the point at position C<$x>, C<$y> of the
grid to "living." It returns a true value.

This method is a wrapper for L<set_point_state()|/set_point_state>.
Because of this, it is fatal to attempt to set a point outside the grid.

=head2 set_point_state

 $life->set_point_state( $x, $y, $state );

This method sets the state of the point at position C<$x>, C<$y> of the
grid to C<$state>. An C<undef> value is ignored; a true value of
C<$state> sets the cell "living;" a false value sets it "dead." It
returns the state.

An exception will be raised if you attempt to set a point "live" which
is outside the grid.

This method is an extension to L<Game::Life|Game::Life>.

=head2 set_rule

 $life->set_rule( $kind, $rule );

This method sets the C<breed> or C<live> rules, which govern the
transition from "dead" to "living" and "living" to "dead" respectively.
The arguments are:

=over

=item $kind

This argument specifies the kind of rule being set, and must be either
C<'breed'> or C<'live'>.

=item $rule

This argument specifies the actual rule. It must be either an array of
non-negative integers specifying the number of neighbors that must exist
to apply this rule, or a false value to specify the default.

The defaults depend on the value of C<$kind> as follows:

=over

=item breed => [ 3 ]

=item live => [ 2, 3 ]

=back

=back



( run in 0.845 second using v1.01-cache-2.11-cpan-71847e10f99 )