Recently I've been exploring extensions to the Generations rule family. This seems like a good thread to introduce the idea. Consider the following modification to the Golly supplied file RuleTreeGen.java.
Code: Select all
import java.util.*;
public class RuleTreeGen
{
/* Put your state count, neighbor count, and function here */
final static int numStates = 6;
final static int numOscillators = 2;
final static int numNeighbors = 8;
final static int ruleTable[][] =
{
{0,0,0,1,0,0,0,1,1},
{2,1,1,2,1,1,1,1,2},
{3,3,3,3,3,3,3,3,3},
{0,0,0,0,0,0,0,0,0}
};
/* order for nine neighbors is nw, ne, sw, se, n, w, e, s, c */
/* order for five neighbors is n, w, e, s, c */
int adjustNeighbor(int n)
{
if (n >= (numStates - numOscillators))
return n - numStates + numOscillators + 1;
return n;
}
int f(int[] a)
{
int cell = a[8];
int count = 0;
for (int i = 0; i < 8; i++)
{
int t = adjustNeighbor(a[i]);
if (t == 1)
count += t;
}
if (cell >= (numStates - numOscillators))
{
if (cell == (numStates - 1))
return numStates - numOscillators;
return cell + 1;
}
return ruleTable[cell][count];
}
final static int numParams = numNeighbors + 1;
HashMap<String, Integer> world = new HashMap<String, Integer>();
ArrayList<String> r = new ArrayList<String>();
int[] params = new int[numParams];
int nodeSeq = 0;
int getNode(String n)
{
Integer found = world.get(n);
if (found == null)
{
found = nodeSeq++;
r.add(n);
world.put(n, found);
}
return found;
}
int recur(int at)
{
if (at == 0)
return f(params);
String n = "" + at;
for (int i=0; i<numStates; i++)
{
params[numParams-at] = i;
n += " " + recur(at-1);
}
return getNode(n);
}
void writeRuleTree()
{
System.out.println("@RULE Caterpillars_O2");
System.out.println("@TREE");
System.out.println("num_states=" + numStates);
System.out.println("num_neighbors=" + numNeighbors);
System.out.println("num_nodes=" + r.size());
for (int i=0; i<r.size(); i++)
System.out.println(r.get(i));
System.out.println("@COLORS");
System.out.println("0 0 0 0");
System.out.println("1 255 0 0");
System.out.println("2 0 255 0");
System.out.println("3 0 0 255");
System.out.println("4 255 255 0");
System.out.println("5 0 255 255");
}
public static void main(String[] args) throws Exception
{
RuleTreeGen rtg = new RuleTreeGen();
rtg.recur(numParams);
rtg.writeRuleTree();
}
}
Lines 6 thru 44 define the Caterpillars rule modified to include two additional oscillating states 4 and 5. When considered as neighbors these two states behave like states 1 and 2 respectively. But when run they simply provide period two oscillators. The behavior of patterns that do not include States 4 or 5 is unchanged.
Here is the modified rule:
Code: Select all
@RULE Caterpillars_O2
@TREE
num_states=6
num_neighbors=8
num_nodes=38
1 0 2 3 0 5 4
1 0 1 3 0 5 4
2 0 1 0 0 1 0
2 1 1 1 1 1 1
3 2 3 2 2 3 2
1 1 2 3 0 5 4
2 1 5 1 1 5 1
3 3 6 3 3 6 3
4 4 7 4 4 7 4
2 5 1 5 5 1 5
3 6 9 6 6 9 6
4 7 10 7 7 10 7
5 8 11 8 8 11 8
3 9 3 9 9 3 9
4 10 13 10 10 13 10
5 11 14 11 11 14 11
6 12 15 12 12 15 12
3 3 3 3 3 3 3
4 13 17 13 13 17 13
5 14 18 14 14 18 14
6 15 19 15 15 19 15
7 16 20 16 16 20 16
1 1 1 3 0 5 4
2 1 22 1 1 22 1
3 3 23 3 3 23 3
4 17 24 17 17 24 17
5 18 25 18 18 25 18
6 19 26 19 19 26 19
7 20 27 20 20 27 20
8 21 28 21 21 28 21
2 22 5 22 22 5 22
3 23 30 23 23 30 23
4 24 31 24 24 31 24
5 25 32 25 25 32 25
6 26 33 26 26 33 26
7 27 34 27 27 34 27
8 28 35 28 28 35 28
9 29 36 29 29 36 29
@COLORS
0 0 0 0
1 255 0 0
2 0 255 0
3 0 0 255
4 255 255 0
5 0 255 255
Typically these additional states provide guns.
Here is an example:
Code: Select all
x = 2, y = 23, rule = Caterpillars_O2
.D$.D$.D$.D$.D$.D12$.D$.D$2D$2D$.D$.D!
Adding three oscillators generates this rule variant:
Code: Select all
@RULE Caterpillars_O3
@TREE
num_states=7
num_neighbors=8
num_nodes=38
1 0 2 3 0 5 6 4
1 0 1 3 0 5 6 4
2 0 1 0 0 1 0 0
2 1 1 1 1 1 1 1
3 2 3 2 2 3 2 2
1 1 2 3 0 5 6 4
2 1 5 1 1 5 1 1
3 3 6 3 3 6 3 3
4 4 7 4 4 7 4 4
2 5 1 5 5 1 5 5
3 6 9 6 6 9 6 6
4 7 10 7 7 10 7 7
5 8 11 8 8 11 8 8
3 9 3 9 9 3 9 9
4 10 13 10 10 13 10 10
5 11 14 11 11 14 11 11
6 12 15 12 12 15 12 12
3 3 3 3 3 3 3 3
4 13 17 13 13 17 13 13
5 14 18 14 14 18 14 14
6 15 19 15 15 19 15 15
7 16 20 16 16 20 16 16
1 1 1 3 0 5 6 4
2 1 22 1 1 22 1 1
3 3 23 3 3 23 3 3
4 17 24 17 17 24 17 17
5 18 25 18 18 25 18 18
6 19 26 19 19 26 19 19
7 20 27 20 20 27 20 20
8 21 28 21 21 28 21 21
2 22 5 22 22 5 22 22
3 23 30 23 23 30 23 23
4 24 31 24 24 31 24 24
5 25 32 25 25 32 25 25
6 26 33 26 26 33 26 26
7 27 34 27 27 34 27 27
8 28 35 28 28 35 28 28
9 29 36 29 29 36 29 29
@COLORS
0 0 0 0
1 255 0 0
2 0 255 0
3 0 0 255
4 255 255 0
5 0 255 255
6 255 0 255
which provides this gun:
Code: Select all
x = 1, y = 6, rule = Caterpillars_O3
D$D$D$D$D$D!
This rule extension can also be applied to any Life-Like rule.
Brian Prentice