Square Cell

The Program

This program was written to explore 2D cellular automata (CA) that use the three neighborhoods shown in the program's main display below.

The neighborhood on the left (Square) is the well known Moore neighborhood, the neighborhood in the center (Diamond) is the Moore neighborhood rotated through 45 degrees and the neighborhood on the right (Both) is a combination of the other two. The program's grid can be considered to consist of vertical and horizontal lines when using the Square neighborhood and diagonal lines (vertical and horizontal lines rotated through 45 degrees) when using the Diamond neighborhood. For example, the period 4 diagonal glider which occurs in Conway's Life rule when the Square neighborhood is used, becomes a period 4 orthogonal glider when the Diamond neighborhood is used. With this program, Conway's Life and related rules can be run using both the Square and Diamond neighborhoods together, and interactions that occur between them can be explored.

The program can be used to find interesting rules. It does this by generating random rule parameters and then running the resulting rule starting with a randomly generated pattern. This process is controlled by simply clicking a New Rule menu button. Options specifying how the rule parameters are to be modified are provided.

Patterns generated by running a CA simulation can be saved to and loaded from pattern files.

The program provides controls which can be used to edit the CA simulation display, and analyze the simulation patterns.

The program will execute on a PC running Windows XP, is written in Delphi 5 and uses the Graphics32 library.

Installation

First download SquareCell.zip from here. The zip archive contains the program source code, the executable file SquareCell.exe and this document. Unzip the achieve into a directory of your choice and place an icon on your desktop linked to "..\Square Cell\Version 3\SquareCell.exe".

Simulation Control

A 2D cellular automaton is a collection of cells on a square grid that are colored according to their state. The cell collection evolves through a number of discrete time steps according to a set of rules based on the states of neighboring cells. The rules are applied iteratively for as many time steps as desired. The program represents a cellular automaton on a rectangular display divided uniformly into squares. Each time step the program examines each cell in turn and changes its state by applying a rule to the cell's state and the states of its neighbors.

To get started, execute the program and click the Rule menu. This will display the Mixed Generations rule dialog set to the well known rule Star Wars. Click Ok to close the dialog . Now click the Random menu to set the cells to random states and click the Start menu to run the simulation. Stop the simulation by clicking the Stop menu and step the simulation by clicking the Step menu. Clear the display by clicking the Clear menu. This sets the state of each cell to 0.

Now click Start and repeatedly click New Rule. This simple process together with setting new rule options, described below, randomly selects new rules in the Mixed Generations rule family and runs them.

Cell patterns may be saved to a pattern file by clicking 'File | Save' and restored from a pattern file by clicking 'File | Open'. The pattern files contain the rule string and the collection of cell states.

Cell patterns may be analyzed to determine if they are ships, oscillators or are stable. The message box shown below displays the result after clicking the Analyze menu button with Conway's well known glider displayed.

The Rules

Mixed Generations

Specific rules in the family of rules called Mixed Generations are selected by setting parameters in an input dialog window shown below. This dialog window is displayed by clicking the Rule menu.

In the discussion that follows let s be the number of states and m = (s - 1) / 2.

Notice the Neighbors group at the top right on the dialog window, the radio buttons in this group select the neighborhood (Square, Diamond or Both). When Both is selected it is usual to set the Number of States to an odd value and the State Weights 1..m equal to the State Weights m + 1..s - 1. With this neighborhood, the cell states are evenly divided into two groups. The states 0..m use the Square neighborhood and the states 0, m + 1..s - 1 use the Diamond neighborhood.

Each cell can be in one of 16 possible states in the range 0..15. Each iteration, the states of a cells neighbors are multiplied by appropriate State Weights and then counted. For example, if a neighbor is in state 3 and the State Weight corresponding to state 3 is 5 then the neighbor will contribute a count of 5 to the cells neighbor count. The State Weights are in the range -10..10.

Consider first the case where the neighborhood is either Square or Diamond. In this simple case, if a cell is in state 0 then it changes to state 1 if its neighbor count is included in the Birth Group. Otherwise the cell remains in state 0. If a cell is in state 1 then it remains in state 1 if its neighbor count is included in the Survival Group. If a cell is in state 1 and the cell's neighbor count is not included in the Survival Group and s > 2 then the cell's state changes to state 2, otherwise it changes to state 0. If a cell is in state n where n >= 2 then it changes to state n + 1 if n + 1 < s, otherwise the cell returns to state 0.

Now consider the case where the neighborhood is Both. In this more complex case, if a cell is in state 0 then it changes to state 1 if its neighbor count contributed by neighbors in state 1..m is included in the Birth Group or to m + 1 if its neighbor count contributed by neighbors in state m + 1..s - 1 is included in the Birth Group. Otherwise the cell remains in state 0.

If a cell is in state 1 then it remains in state 1 if its neighbor count contributed by neighbors in state 1..m is included in the Survival Group. If a cell is in state 1 and the cell's neighbor count contributed by neighbors in state 1..m is not included in the Survival Group and m > 1 then the cell's state changes to state 2, otherwise it changes to state 0. If a cell is in state n where n >= 2 then it changes to state n + 1 if n + 1 <= m, otherwise the cell returns to state 0.

Similarly, if a cell is in state m + 1 then it remains in state m + 1 if its neighbor count contributed by neighbors in state m + 1..s - 1 is included in the Survival Group. If a cell is in state m + 1 and the cell's neighbor count contributed by neighbors in state m + 1..s - 1 is not included in the Survival Group and s > m + 2 then the cell's state changes to state m + 2, otherwise it changes to state 0. If a cell is in state n where n >= m + 2 then it changes to state n + 1 if n + 1 < s, otherwise the cell returns to state 0.

The Number of States and the State Weights are modified by clicking the associated up or down arrow controls. The Birth and Survival Groups are provided with edit and button controls to add, delete and clear entries.

Display Editing

The State Selector popup dialog shown below is displayed by Right clicking the display with the 'Shift' key down. This dialog shows all possible cell states. To select a particular state simply click the appropriate square. Individual cells on the display may then be set to the selected state by clicking them.

A group of cells is selected by clicking the display with the 'Ctrl' key down. The first click marks a corner of the area to be selected and the second click marks an opposite corner. A third click clears the selection. A selected cell group may be manipulated by controls on the Selection Control popup dialog shown below. This dialog is displayed by Right clicking the display.

The cells inside the selecting rectangle may be set to state 0 by clicking the Clear Inside button. Similarly, the cells outside this rectangle may be set to 0 by clicking the Clear Outside button. Selected cell groups may be flipped about the X or Y axis or rotated through 90 degrees. All the cells that are not in state 0 may be selected by clicking the Select All button. As a convenience for group rotation, all cells that are not in state 0 may also be selected by surrounding them with a square by clicking the Select Square button. Control buttons are also provided to center the selected group of cells, set the selected cell states to randomly generated values and save the selected cells in a pattern file. Selected cell groups may be moved or copied by dragging them. The setting of the two radio buttons on the Selection Control dialog specify which function is active.

If a cell is clicked with the 'Shift' key down, the cells neighborhood is displayed.

As a convenience, a group of cells that form some interesting pattern when using the Square neighborhood can be converted to a group of cells that perform in a similar manner when using the Diamond neighborhood by clicking the menu "Convert | Square to Diamond". Click the menu "Convert | Diamond to Square" to perform the reverse operation. These conversions only operate when the neighborhood is set to Both.

Options

The Options dialog shown below is displayed by clicking the Options menu.

Each of the colors associated with the cell states, the cell grid and the cell group selector can be changed. Simply click on the appropriate square to display the color selector and choose a color.

The cell size in pixels can be set to any number in the range 1..15 using the Grid Size selector.

The number of simulation steps executed when the Step menu is clicked can be set using the Step Size edit control.

When either the display cells or a selected group of cells are set to random states (colors), the cell density can be set using the Density selector.

For the Mixed Generations family, the new rule function generates random State Weights, random Birth Counts and random Survival Counts according to the settings of the check boxes in the New Rule Controls group. If a check box is checked, random values are generated and replace the current values and if the check box is not checked the current values are unchanged.

Enhancements

The process of generating interesting rules by first clicking the Start menu and then repeatedly clicking the New Rule menu has worked quite well. The code executed by the New Rule function is in the GenerateNewRule procedure in the file MixedGenerations.pas. This code is somewhat primitive. Recode this procedure to implement a more sophisticated algorithm.

References

  1. MCell a 1D and 2D Cellular Automata Explorer Program by Mirek Wojtowicz
  2. MCell Extensions and Pattern File Collections by Brian Prentice
  3. Tiled Cellular Automata Program by Brian Prentice
  4. Graphics32 Library

Contact

Please send any comments, suggestions or program enhancements to:

Brian Prentice.