(10,14)c/184.
Here is a script that can convert alternating rules to Golly-readable rule tables, which supports Generations rules.
Code: Select all
import golly as g
import re
d = {'0c': [], '1c': [1], '1e': [0], '2c': [1, 3], '2e': [0, 2], '2k': [0, 3], '2a': [0, 1], '2i': [0, 4], '2n': [1, 5], '3c': [1, 3, 5], '3e': [0, 2, 4], '3k': [2, 4, 7], '3a': [0, 1, 2], '3i': [1, 2, 3], '3n': [1, 2, 7], '3y': [1, 4, 7], '3q': [0, 3, 7], '3j': [0, 2, 7], '3r': [0, 4, 7], '4c': [1, 3, 5, 7], '4e': [0, 2, 4, 6], '4k': [1, 4, 6, 7], '4a': [0, 1, 2, 3], '4i': [0, 1, 3, 4], '4n': [0, 1, 5, 7], '4y': [1, 2, 5, 7], '4q': [0, 3, 6, 7], '4j': [0, 2, 4, 7], '4r': [0, 2, 6, 7], '4t': [0, 1, 4, 7], '4w': [0, 2, 3, 7], '4z': [0, 1, 4, 5], '5c': [0, 2, 4, 6, 7], '5e': [1, 3, 5, 6, 7], '5k': [0, 1, 3, 5, 6], '5a': [3, 4, 5, 6, 7], '5i': [0, 4, 5, 6, 7], '5n': [0, 3, 4, 5, 6], '5y': [0, 2, 3, 5, 6], '5q': [1, 2, 4, 5, 6], '5j': [1, 3, 4, 5, 6], '5r': [1, 2, 3, 5, 6], '6c': [0, 2, 4, 5, 6, 7], '6e': [1, 3, 4, 5, 6, 7], '6k': [1, 2, 4, 5, 6, 7], '6a': [2, 3, 4, 5, 6, 7], '6i': [1, 2, 3, 5, 6, 7], '6n': [0, 2, 3, 4, 6, 7], '7c': [0, 2, 3, 4, 5, 6, 7], '7e': [1, 2, 3, 4, 5, 6, 7], '8c': [0, 1, 2, 3, 4, 5, 6, 7]}
d2 = {
"0":"c",
"1":"ce",
"2":"cekain",
"3":"cekainyqjr",
"4":"cekainyqjrtwz",
"5":"cekainyqjr",
"6":"cekain",
"7":"ce",
"8":"c",
}
def RuleStringToDict(s):
rule = s.split("/")
if len(rule) == 3:
states = int(rule[2])
rule = rule[0:2]
else:
states = 2
if rule[0] and rule[0][0] == 'B':
B = rule[0][1:]
S = rule[1][1:]
else:
B = rule[1]
S = rule[0]
if "0" in B:
g.exit("B0 rules are not supported!")
def f(s):
ls = []
for i in re.findall(r"\d[-]?[a-z]*", s):
num = i[0]
if len(i) == 1 or i[1] == "-":
for j in d2[num]:
if j not in i:
ls.append(num+j)
else:
for j in i[1:]:
ls.append(num+j)
return ls
B2 = f(B)
S2 = f(S)
return {"B":B2, "S":S2, "states":states}
prev_rule = g.getrule()
for i in prev_rule:
if i not in "BS0123456789cekainyqjrtwz-_":
prev_rule = "B3/S23|B36/S23"
break
InputString = g.getstring('Input two rules:',prev_rule).replace(" ", "").replace("_", "/").replace("--", "|")
Rule1, Rule2 = InputString.split("|")
Dict1 = RuleStringToDict(Rule1)
Dict2 = RuleStringToDict(Rule2)
states = max(Dict1["states"], Dict2["states"])
states2 = min(Dict1["states"], Dict2["states"])
larger = 1 if Dict1["states"] > Dict2["states"] else 2
all_set = {i for i in range(states+1)}
death_set = {i for i in range(2, states)}
death_set.add(0)
output_rule = "@RULE " + InputString.replace("/", "_").replace("|", "--") + f"""
@TABLE
n_states:{states+1}
neighborhood:Moore
symmetries:rotate4reflect
var all = {all_set}
var bll = all
var cll = all
var dll = all
var ell = all
var fll = all
var gll = all
var hll = all
var ill = all
var D0 = {death_set}
var D1 = D0
var D2 = D0
var D3 = D0
var D4 = D0
var D5 = D0
var D6 = D0
var D7 = D0
"""
ls = [None] + list(range(1, states)) + [0]
if larger == 1:
death_1, death_2 = ls[2], ls[2+states-states2]
else:
death_2, death_1 = ls[2], ls[2+states-states2]
for i in ((Dict1,1), (Dict2,states)):
dic, state = i
for j in dic["B"]:
line = [0,0,0,0,0,0,0,0,0,states+1-state]
for k in d[j]:
line[k+1] = state
line = [str(i) for i in line]
w = 0
for k in range(1, 9):
if line[k] == "0":
line[k] = f"D{w}"
w+=1
output_rule += ",".join(line)+"\n"
for j in dic["S"]:
line = [state,0,0,0,0,0,0,0,0,states+1-state]
for k in d[j]:
line[k+1] = state
line = [str(i) for i in line]
w = 0
for k in range(1, 9):
if line[k] == "0":
line[k] = f"D{w}"
w+=1
output_rule += ",".join(line)+"\n"
output_rule += f"1, all, bll, cll, dll, ell, fll, gll, hll, {death_1}\n"
output_rule += f"{states}, all, bll, cll, dll, ell, fll, gll, hll, {death_2}\n"
for i in range(2, states-1):
output_rule += f"{i}, all, bll, cll, dll, ell, fll, gll, hll, {i+1}\n"
output_rule += f"{states-1}, all, bll, cll, dll, ell, fll, gll, hll, 0\n"
output_rule += """
@COLORS
0 0 0 0
1 200 255 255
""" + f"{states} 255 200 200\n"
w = states+1-3
for i in range(2, states):
output_rule += f"{i} {int(255-255*(i-1)/(w+1))} {int(255-255*(i-1)/(w+1))} {int(255-255*(i-1)/(w+1))}\n"
g.setclipstr(output_rule)
g.exit("Copied to clipboard")