Tutorials/Creating custom rules

From LifeWiki
Revision as of 10:58, 10 July 2017 by Apple Bottom (talk | contribs) (Factored out from Tutorial/Rules)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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, 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 RuleTables, which are the transitions that occur every generation, AKA Rules. 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. Next, add the table, i.e. your actual transitions for the rule. Do this before getting to the actual transitions.

@TABLE
n_states:2
neighborhood:Moore
symmetries:permute
  • @TABLE: This tells Golly that the table 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, Hexagonal, vonNeumann, or oneDimensional, for the full list see the RoadMap
  • symmetries: This is the arrangements accepted for each transition, none will make it so for example, if you want birth at 4 neighbors, you will have to write out every single arrangement of 4 neighbors. Permute makes it easy, we will come back to that later.

Now, transition time! Here, we will make Life, B3/S23. To make a transition, 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 make transitions for death. We don't do it for survival because survival means no transition happens to the cell. 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.

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

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.

Examples of Custom Rules