RETAS-Logo
RETAS-Logo
This page is not mobile friendly.
Better watch on bigger screen.

computer/programs/useless/misc/game_of_life


               $,=shift;$/
               =shift;$ %[
               $_]=1 for @
               ARGV;while(
               1){$o='';@"
               =@%;for(1..

                            $,*$/){$o.=
                            $%[$_]?'[]'
                            :'  ';$o .=
                            "\n"if$_%$/
                            ==0; }print
                            "\033[0;0".

  "H$o";for (  $/+1..($,-1  )*$/){$:=$"
  [$_-$/ -1]+  $"[$_ -$/]+  $"[$_-$/+1]
  +$"[$_ -1]+  $"[$_+1]+$"  [$_+$/ -1]+
  $"[$_ +$/]+  $"[$_+$/+1]  ;$%[$_]=1if
  $"[$_]==0&&  $:==3;$%[$_  ]=0if$"[$_]
  &&($:<2||$:  >3)}}$"=q);  $"[$_+1]+$"

    G A M E        O F        L I F E

  Thomas Schoch www.retas.de (Nov 2006)







     [ Unix version | DOS version ]

This Perl program plays John Conway's "Game of Life". The upper part of the code is shaped like the "glider" (also used as the "hacker emblem", see the logo in the upper left corner of this page). Note that the code includes the lines under the glider - it ends with the string "(Nov 2006)".

...............   We assume you want to
..#............   play the game of life
...#...........   on a small field with
.###...........   6 rows and 15 columns
...............   and a glider in it as
...............   shown left.

Then the program has to be invoked as:

   perl gol.pl 6 15 18 34 47 48 49

Explanation: The first two arguments are the numbers of rows and colums of the field, the following numbers are the positions of cells in the field, counted row-by-row from left to right.

More about the Game Of Life.

Download the source (Unix).
Download the source (DOS).