Game-Life-Infinite-Board
view release on metacpan or search on metacpan
lib/Game/Life/Infinite/Board.pm view on Meta::CPAN
print "--- STATIC! --- \n";
exit;
};
if ($stats->{'oscilator'} > 1) {
$board->shrinkBoard;
$board->crudePrintBoard();
print "--- OSCILATOR " . $stats->{'oscilator'} . " --- \n";
$board->tick($oscCheck);
$board->shrinkBoard;
$board->crudePrintBoard();
exit;
};
};
=head1 DESCRIPTION
This module implements the well known Conway's Game of Life in Perl.
Points of interest:
=over
=item *
Infinite grid (no "fell over" or "warp").
=item *
Oscilator detection
=item *
Rules as parameter
=item *
Simple load, save and print
=item *
Colourised life support (Immigration, Quadlife)
=back
=head1 METHODS
=head2 C<new>
C<< my $board = Game::Life::Infinite::Board->new($rules); >>
Initializes a new board. I<$rules> is a reference to an array of arrays, containing the rules that will be used to calculate the next generation. Example:
C<my $rules = [[3,4,5], [1,2,7]];>
First array sets the number of neighbours required for a live cell to survive. Second array sets the number of neighbours required for a new cell to be born. If not defined, the standard rules (C<[[3], [2,3]]>) will be used.
=head2 C<setRules>
C<< $board->setRules($rules); >>
Change the rules on an existing board.
=head2 C<updateCell>
C<< $board->updateCell($x,$y,$state); >>
Set the state of the cell with coordinates $x,$y to $state, where $state can be 0 (dead) or 1..4 (alive). Standard rules board (not colored) can only use 1 for alive cell. Immigration board can only use 1 or 2.
=head2 C<loadInit>
C<< $board->loadInit($filename) >>
Detects file format and loads a formation from a text file. Uses the function L</&format_is> to detect the file format and if a known format is successfully detected, uses the corresponding method (see below) to load the file. For now (0.06) only .ce...
=head2 C<loadCells>
C<< $board->loadCells($file_array_ref) >>
Loads an initial grid from an array containing a file in cells (ASCII) format. Live cells are marked with 'O' (upper case o). If the character '2' is found, is used as a second color and board color is set to 'Immigration'. If characters '3' and/or '...
=head2 C<loadRLE>
C<< $board->loadRLE($file_array_ref) >>
Loads an initial grid from an array containing a file in rle (run length encoded) format. The standard tags (b, o, $) are supported. The 3 first unknown tags found are used as extra cell states and the board color is set to 'Immigration' (one extra s...
=head2 C<loadL105>
C<< $board->loadL105($file_array_ref) >>
Loads an initial grid from an array containing a file in Life 1.05 format as described in L<http://www.conwaylife.com/wiki/Life_1.05>. If found, a comment line (#D) containing the string "Name:" is used to fill the 'name' attribute. Color is not supp...
=head2 C<loadL106>
C<< $board->loadL106($file_array_ref) >>
Loads an initial grid from an array containing a file in Life 1.06 format as described in L<http://www.conwaylife.com/wiki/Life_1.06>. Color is not supported in this format.
=head2 C<saveGridTxt>
C<< $board->saveGridTxt($filename) >>
Saves the current board formation as text, using 'O' for live cells and '.' for dead cells. '2', '3' and '4' are used for extra colors. The resulting file can be loaded using loadInit.
=head2 C<crudePrintBoard>
C<< $board->crudePrintBoard; >>
Prints the board with 'O' for live cells and '.' for dead cells, plus some information about the current state of the board. If the board is an Immigration or Quadlife board, characters '2', '3' and '4' are used for the extra colors.
=head2 C<tick>
C<< $board->tick($oscCheck); >>
Applies the rules once and transforms the board to the next generation. If $oscCheck is defined and is greater than one, then a history of the board $oscCheck generations long is kept and used to detect oscilating populations with period less or equa...
=head2 C<shrinkBoard>
C<< $board->shrinkBoard; >>
Shrinks the board by deleting cell entries from the internal grid data structure (which saves memory and speeds up processing) and adjusting minx, maxx, miny, maxy attributes, which speeds up oscilator detection and printing and keeps the file saved ...
=head2 C<setColor>
C<< $board->setColor($color); >>
Defines the use of color. $color can be one of 'Immigration', 'Quadlife' or 'Normal'. Color cannot be changed if the board is older that generation zero. Failure (unknown color or generation > 0) returns undef. Default color setting is 'Normal'. See ...
( run in 0.752 second using v1.01-cache-2.11-cpan-39bf76dae61 )