This can then be used like a version of Hensel notation, but for hex rules instead. For example:
In the rule B2-p/S2-m4H cells behave as follows:
- OFF cells with two neighbors which aren't directly opposite turn ON.
- ON cells with two neighbors which are either adjacent or opposite of each other stay ON.
- ON cells with four neighbors stay ON.
- All other cells stay or turn OFF.
An example pattern:
Code: Select all
x = 2, y = 2, rule = B2-p_S2-m4H
o$2o!
Code: Select all
@RULE B2-p_S2-m4H
@TABLE
n_states:2
neighborhood:hexagonal
symmetries:rotate6reflect
var a = {0,1}
var b = a
var c = a
var d = a
var e = a
var f = a
var g = a
0,1,1,0,0,0,0,1
0,1,0,1,0,0,0,1
1,1,1,0,0,0,0,1
1,1,0,0,1,0,0,1
1,1,1,1,1,0,0,1
1,1,1,1,0,1,0,1
1,1,1,0,1,1,0,1
a,b,c,d,e,f,g,0
Code: Select all
import golly as g
def translateRule(string):
if "_" in string:
birth,survival = string.split("_")
else:
birth = string
survival = ""
#expand strings
longbirth = []
longsurvival = []
for i in range(len(birth)):
if birth[i] in "0156":
longbirth.append(birth[i])
elif birth[i] in "234":
cond = []
negativeMode = False
for j in birth[i+1:]:
if j in "B0123456H":
break
elif j == "-":
negativeMode = True
cond += ["o","m","p"]
elif negativeMode:
cond.remove(j)
else:
cond.append(j)
if cond == []:
cond = ["o","m","p"]
for k in cond:
longbirth.append(birth[i] + k)
else:
pass
for i in range(len(survival)):
if survival[i] in "0156":
longsurvival.append(survival[i])
elif survival[i] in "234":
cond = []
negativeMode = False
for j in survival[i+1:]:
if j in "S0123456H":
break
elif j == "-":
negativeMode = True
cond += ["o","m","p"]
elif negativeMode:
cond.remove(j)
else:
cond.append(j)
if cond == []:
cond = ["o","m","p"]
for k in cond:
longsurvival.append(survival[i] + k)
else:
pass
return longbirth, longsurvival
def assembleRule(original,(longbirth,longsurvival)):
rules = {
"0" :",0,0,0,0,0,0,",
"1" :",1,0,0,0,0,0,",
"2o":",1,1,0,0,0,0,",
"2m":",1,0,1,0,0,0,",
"2p":",1,0,0,1,0,0,",
"3o":",1,1,1,0,0,0,",
"3m":",1,1,0,1,0,0,",
"3p":",1,0,1,0,1,0,",
"4o":",1,1,1,1,0,0,",
"4m":",1,1,1,0,1,0,",
"4p":",1,1,0,1,1,0,",
"5" :",1,1,1,1,1,0,",
"6" :",1,1,1,1,1,1,",
}
rule = """@RULE {rule}
@TABLE
n_states:2
neighborhood:hexagonal
symmetries:rotate6reflect
var a = {{0,1}}
var b = a
var c = a
var d = a
var e = a
var f = a
var g = a
""".format(rule=original)
for line in longbirth:
rule += "0"
rule += rules[line]
rule += "1\n"
rule += "\n"
for line in longsurvival:
rule += "1"
rule += rules[line]
rule += "1\n"
rule += "\na,b,c,d,e,f,g,0"
return rule
def main():
converted = g.getstring("Which rule file do you want to be created? ").replace("/","_")
#print(assembleRule(converted,translateRule(converted)))
file = open(g.getdir("rules") + converted + ".rule", "w")
file.write(assembleRule(converted,translateRule(converted)))
file.close()
g.setrule(converted)
#if __name__ == '__main__':
# main()
main()