viewtopic.php?f=7&t=1080&start=25
But what about rules like B1x2/S23V?
Here's a modified version of the script that generates Bx2 rules
Code: Select all
# Sphenocorona's WolfVN but using Bx2 this time.
# Author: Eric Goldstein, June 17, 2013, eric at goldstein dot net
# This was thrown together in a hurry from spare parts.
# Sphenocorona's WolfVN rulefamily proposal:
# 1. taking the states of its neighbors NW-N-NE
# 2. applying an elementary 1-dimensional rule (e.g. rule 110) to those cells,
# and returning the value of the center cell (in this case north)
# 3. repeating step 2 with the sets NE-E-SE, SE-S-SW, and SW-W-NW, and finally
# 4. taking the four returned values and using them to determine the state of cell C through
# an outer-totalistic Von-Neumann neighborhood CA such as B1/S23V.
# The solution below starts with the observation that Stephen Wolfram's "Elementary" CA rules
# can be expressed in MCell's Weighted Life format.
# For example, Rule 110 can be expressed as
# NW0,NN0,NE0,WW2,ME0,EE1,SW0,SS0,SE0,HI0,RS0,RS1,RS2,RB1,RB3
# If you're not familiar with Weighted Life, see the discussion here:
# http://www.conwaylife.com/forums/viewtopic.php?f=11&t=935&start=0&hilit=weighted+life
# and also see the script listed here:
# http://www.conwaylife.com/forums/viewtopic.php?f=9&t=933#p6814
import golly
from glife.RuleTree import *
rulestring = golly.getstring('''Create one of Sphenocorona's WolfVN rules using Bx2.
Enter a Wolfram elementary CA rule (even numbered rules only), and a semi-totalistic rule in the Von Neumann neighborhood.
Use the form Wnnn_Bnnn/SnnnnV:''', "W110_B1/S23V")
if "S" not in rulestring:
golly.exit("The von Neumann neighborhood Bnn/Snnn rule must include the letter S")
rulestring = rulestring.replace(" ", "")
rulestring = rulestring.upper()
rulestring_parts = rulestring.split("_")
rulestring_wolfram_part = rulestring_parts[0]
rulestring_vn_part = rulestring_parts[1]
VN_B_rulestring = rulestring_vn_part.split("S")[0]
VN_S_rulestring = rulestring_vn_part.split("S")[1]
VN_birth_rule = []
VN_survival_rule = []
VN_birth_canonical = ""
VN_survival_canonical = ""
valid_neighbors = ["0","1","2","3","4"]
for i in valid_neighbors:
if i in VN_B_rulestring:
VN_birth_rule.append(int(i))
VN_birth_canonical = VN_birth_canonical + i
if i in VN_S_rulestring:
VN_survival_rule.append(int(i))
VN_survival_canonical = VN_survival_canonical + i
name = "WolfVN-Bx2-" + rulestring_wolfram_part + "_" + "B" + VN_birth_canonical + "_S" + VN_survival_canonical + "V"
# Wolfram rules are converted into Weighted Life rules here.
# Survival rules in Weighted Life have the RS prefix, and
# Birth rules in Weighted Life have the RB prefix.
RS = []
RB = []
Wolfnum = int(rulestring_wolfram_part.split("W")[1])
if (Wolfnum >> 7) & 1:
RS.append(3)
if (Wolfnum >> 6) & 1:
RS.append(2)
if (Wolfnum >> 5) & 1:
RB.append(3)
if (Wolfnum >> 4) & 1:
RB.append(2)
if (Wolfnum >> 3) & 1:
RS.append(1)
if (Wolfnum >> 2) & 1:
RS.append(0)
if (Wolfnum >> 1) & 1:
RB.append(1)
if (Wolfnum >> 0) & 1:
RB.append(0)
n_states = 3
n_neighbors = 8
def transition_function(a):
# order for 8 neighbors is NW, NE, SW, SE, N, W, E, S, C
nw_cell, ne_cell, sw_cell, se_cell, n_cell, w_cell, e_cell, s_cell, me_cell = a
# Rule 110 for the central cell (unused, but I'm including it for reference)
# NW0,NN0,NE0,WW2,ME0,EE1,SW0,SS0,SE0,HI0,RS0,RS1,RS2,RB1,RB3
# Calculate an elementary CA rule on the North cell
NW_weight = 2
NE_weight = 1
north_sum = NW_weight*(nw_cell == 2) + NE_weight*(ne_cell == 2) + (n_cell == 2)
if n_cell == 2 and north_sum in RS:
north_wolf = 1
elif n_cell == 0 and north_sum in RB:
north_wolf = 1
else:
north_wolf = 0
# Calculate an elementary CA rule on the East cell
NE_weight = 2
SE_weight = 1
east_sum = NE_weight*(ne_cell == 2) + SE_weight*(se_cell == 2) + (e_cell == 2)
if e_cell == 2 and east_sum in RS:
east_wolf = 1
elif e_cell == 0 and east_sum in RB:
east_wolf = 1
else:
east_wolf = 0
# Calculate an elementary CA rule on the South cell
SE_weight = 2
SW_weight = 1
south_sum = SW_weight*(sw_cell == 2) + SE_weight*(se_cell == 2) + (s_cell == 2)
if s_cell == 2 and south_sum in RS:
south_wolf = 1
elif s_cell == 0 and south_sum in RB:
south_wolf = 1
else:
south_wolf = 0
# Calculate an elementary CA rule on the West cell
SW_weight = 2
NW_weight = 1
west_sum = NW_weight*(nw_cell == 2) + SW_weight*(sw_cell == 2) + (w_cell == 2)
if w_cell == 2 and west_sum in RS:
west_wolf = 1
elif w_cell == 0 and west_sum in RB:
west_wolf = 1
else:
west_wolf = 0
# Now lets calculate the VN rule from the four WolframRule-derived values
final_sum = north_wolf + east_wolf + south_wolf + west_wolf
if me_cell == 0 and final_sum in VN_birth_rule:
return 1
if me_cell == 1 and final_sum in VN_birth_rule:
return 2
if me_cell == 2 and final_sum in VN_survival_rule:
return 2
return 0
##########################################################
# The code below this line is copied from make-ruletree.py
##########################################################
try:
MakeRuleTreeFromTransitionFunction( n_states, n_neighbors, transition_function,
golly.getdir("rules")+name+".tree" )
# use name.tree to create name.rule (with no icons);
# note that if name.rule already exists then we only replace the info in
# the @TREE section to avoid clobbering any other info added by the user
ConvertTreeToRule(name, n_states, [])
golly.setalgo("RuleLoader")
golly.setrule(name)
golly.show("Created "+golly.getdir("rules")+name+".rule and switched to that rule.")
except:
import sys
import traceback
exception, msg, tb = sys.exc_info()
golly.warn(\
'''A problem was encountered with the supplied rule:'''+ '\n'.join(traceback.format_exception(exception, msg, tb)))
golly.exit()