Tutorials/Creating custom rules
![]() |
This article is a stub. You can help LifeWiki by expanding it. |
![]() |
This article needs to be expanded with: information about icons in ruletables. |
![]() |
This article needs to be expanded with: information about INT custom rules |
So, you already know about Golly and rules?
Creating custom rules: the rule table
Maybe you want to create a rule entirely from scratch, e.g. for use in Golly. Golly has the ability to run a very large class of rules using RuleLoader, described by a special syntax which you will now learn how to employ.
To create a new rule, you first need to know how to create a ruletable. Each line in the main part of a ruletable is called a transition. For this tutorial, we are going to recreate Life, but with the name "Tutorial". To start, open your favorite text editor and type:
@RULE RuleName
where RuleName is the name of your rule; let's call this rule Tutorial, for tutorial purposes.
Before writing the transition table, finish the header section like this -- maybe with a few lines of comments between "@RULE" and "@TABLE", to help people understand what this rule table is going to define:
@RULE Tutorial This is a practice Golly .rule file that implements standard Conway's Game of Life rules. @TABLE n_states:2 neighborhood:Moore symmetries:permute
- @TABLE: This tells Golly that the table definition starts here.
- n_states: This is how many states your rule has, INCLUDING state 0, the dead state/background, so 2 states will have live and dead states and 1 state will only have the background.
- neighborhood: This is the neighborhood the rule uses, can be Moore, vonNeumann, Hexagonal, or oneDimensional, for the full list see the RoadMap
- symmetries: This is the invariant symmetry of each transition -- the different ways that Golly is allowed to rearrange the list of neighbors and still get a match. Using 'none' symmetry, if you want birth at 4 neighbours, you will have to write out every single possible arrangement of 4 neighbours -- each arrangement on a separate line. Permute makes it easy -- we will come back to that later. There are other symmetries, too. Rotate4, rotate4reflect, rotate8, and none are examples of symmetries, with rotate4reflect particularly useful for isotropic custom rules.
Now, it is time to write the transition table! Here, we will make Life, B3/S23. To specify a transition definition, type a string as so:
Starting State, N Neighbor State, NE Neighbor State, E Neighbor State, SE Neighbor State, S Neighbor State, SW Neighbor State, W Neighbor State, NW Neighbor State, New State
So, for Life's "B3", we write:
0, 1,1,1,0,0,0,0,0, 1
This means that if a state 0 cell has 3 neighbors, it will become state 1. This is also where permute comes in; if we didn't have permute, say none, it would only make the cell live if it is exactly the same as we put it, live on the North, North East, and East only, but permute makes it so all B3 states are filled.
Now we'll write down the transitions for death. With this method, we don't need to actually write out any line the survival transitions S2 or S3, because the cell does not change state in those cases. Live cells in life survive if they have 2 or 3 live neighbors, hence die (from loneliness, one imagines) if they have only 0 or 1, or (from overcrowding) if they have 4 or more. Note that the numbers between the spaces signify the condition.
1, 0,0,0,0,0,0,0,0, 0 1, 1,0,0,0,0,0,0,0, 0 1, 1,1,1,1,0,0,0,0, 0 1, 1,1,1,1,1,0,0,0, 0 1, 1,1,1,1,1,1,0,0, 0 1, 1,1,1,1,1,1,1,0, 0 1, 1,1,1,1,1,1,1,1, 0
Another common way to achieve the same effect is to write out just the two survival conditions, and add a "catch-all" transition line at the end of the table that kills the cell no matter how many neighbors it has. Golly accepts the first matching transition that it finds, reading the table from top to bottom -- so if one of the survival transition lines turns out to match, then the "catch-all" transition at the end will be ignored.
To do things that way, you will need variables. They do not have to be "a1", "a2", etc., they can be whatever you want to call them, but it’s good to keep things organized. This method is very useful dealing with rules with multiple states.
var a1 = {0,1} var a2 = {0,1} var a3 = {0,1} var a4 = {0,1} var a5 = {0,1} var a6 = {0,1} var a7 = {0,1} var a8 = {0,1} var a9 = {0,1} 1, 1,1,0,0,0,0,0,0, 1 a1, 1,1,1,0,0,0,0,0, 1 a1, a2,a3,a4,a5,a6,a7,a8,a9, 0
The reason why you need to use many variables instead of just one is because if you use just one, Golly interprets it as always referring to the same state. So on first reading it might seem as if a simple "catch-all" death transition definition like this ought to work:
var a = {0,1} ... a, a, a, a, a, a, a, a, a, 0
But Golly will actually not find matches with that definition, except in two rare cases. Basically, that definition gets interpreted the same way as
0, 0,0,0,0,0,0,0,0, 0 1, 1,1,1,1,1,1,1,1, 0
This version of the "catch-all" transition line wouldn't actually catch all the other cases, where some neighbour cells are alive and some are dead. In those cases the cell would fail to turn off the way it's supposed to.
So ... all nine separate variable definitions, a1 through a9, are needed to make this method work (except technically you can get away with just a "1" at the beginning of the line, instead of defining the "a1" variable -- see if you can see why!)
Anyway, using the first method the entire file should now look like this:
@RULE Tutorial @TABLE n_states:2 neighborhood:Moore symmetries:permute 0, 1,1,1,0,0,0,0,0, 1 1, 0,0,0,0,0,0,0,0, 0 1, 1,0,0,0,0,0,0,0, 0 1, 1,1,1,1,0,0,0,0, 0 1, 1,1,1,1,1,0,0,0, 0 1, 1,1,1,1,1,1,0,0, 0 1, 1,1,1,1,1,1,1,0, 0 1, 1,1,1,1,1,1,1,1, 0
Save this file and open it using the RuleLoader algorithm, or select all of it and paste it into Golly, and voilà, you've recreated Conway Life!
Making multiple states in the same ruletable which simulate different rules each (referred to as a rule mashup) is also an acceptable move.
Icons, Names and Colors
Colors
By default, each state is colored so that state 0 is a dark grey, and all other states form a gradient from red (state 1) to yellow (the final state). If you don't like the default colors of your states, you can change them to different colors. For this, you use @COLORS :
@COLORS 0 0 0 0 1 255 255 255
Each argument in @COLORS is structured as follows, using the RGB color model:
<state> <red> <green> <blue>
Colors can be useful if you have a lot of states and it would be confusing to give nearby states similar colors.
Names
If you hover over states in LifeViewer, you can see their name.
In order to set a state's name, you need to use @NAMES :
@NAMES 0 off 1 on
There are two arguements in @NAMES, as follows.
<state> <name>
Examples of Custom Rules
|
|