Java Applet : Life Game

Java Applet : Life Game

This applet has been selected by Gamelan to be in the first "Best Of Java" book. At that time, I refused. Everybody makes mistakes.

The Overview of Life

The Life's game is a cellular animation originally developed by John Conway. It consists of a table of cells and a set of rules which describe how to find successive generations of the cells.

The Rules of Life

  1. For each populated cell in the table, count the number of neighbors to that cell :
    If it has 0 or 1 neighbors, the cell dies of 'loneliness'.
    If it has 2 or 3 neighbors, the cell survives to the successive generation.
    If it has 4 or more neighbors, the cell dies of 'overcrowding'.
  2. For each empty cell in the table, count the number of live neighbors to that cell :
    If it has exactly 3 neighbors, it becomes populated.

Features

  1. The field :

    A click on a cell can have several features :
    If the cell is empty (or dead, which means that it is in white), you place the selectioned pattern in that cell. If the pattern is larger than 1x1 (all the cases except the first one), it gets extended to the right-bottom part of the cell. For more details, see the drop down list section below.
    If the cell is alive (all the colors except white), you remove the cell, and it turns to white.
  2. The buttons :

    Go ! : A click on this button makes the applet run until a stable state is found. When the applet runs, the 'Go !' button turns to a 'Stop !' button. A click on the 'Stop !' button stops the evolution of the cells.
    Step : A click on this button enables you to view the next step on the evolution of the cells.
    Clear : A click on this button clears the whole field.
    Debug : A click on this button switches the applet in 'debug' mode. The 'debug' mode is useful for me to check out whether there is a bug in my applet. In 'debug' mode, a click on a cell prints out in the Java console the properties of that cell (position and neighbors). The 'debug' mode turns off the 'Go !' , 'Step' and 'Clear' buttons. To quit the 'debug' mode, click again on the 'debug' button.
    You should not use the Debug mode.
  3. The drop down lists :

    Color mode : You can set the applet to be either in color mode to have cells in different colors, or in black and white mode.
    Cell size : You can switch the cells' size between those values : 4,5,10,20,40. Those numbers describe the size of the cells in pixels. So when you pick up a big one, the cells will be big, the applet will run faster, but the field will contain less cells too ! Be aware that some of the patterns are really huge, so you would need small cells to get the correct displayed on the screen.
    Pattern selection : This list enables you to switch between 61 preselected shapes. The list is showing the name of the pattern, the subtype of that shape, and its dimensions. The pattern selected is drawn from the cell clicked towards the right-bottom direction of the field. The field is supposed to be cyclic, which means that the cells on the border are neighbors of each others. So, you have to set your field size correctly enough to have the place to draw your pattern. Otherwise, the result may be surprising (if a cell gets drawn twice, it turns to the dead state). The different patterns subtypes are :
    Normal shape : 1 item
    Stable shape : 20 items
    Periodic shape : 15 items
    Methusaleh shape : 7 items
    Glider shape : 10 items
    Puffer shape : 3 items
    Fuse shape : 2 items
    Other shape : 3 items

The game


If you were using a Java-enabled browser, you would see the java life game instead of this paragraph

Document first published 8th of May, 1996, last modified 31st of December, 1998 by Laurent David

This web page has been visited by web surfers since 31st of December, 1998.