Page 1 of 1

Alternating rules

Posted: September 16th, 2017, 3:38 am
by Saka
This is an interesting rulespace. Alternating rules are rules in which state 1 and state 2 run different Bx/Sx rules, and all cells change state every generation.

I have made a script to generate these but it only takes totalistic rules for now (unless someone wants to help me make the transition generator)

Code: Select all

# altRuleGen.py
# Script to generate alternating totalistic rules.
# By Saka

#NEVER ENTER B0

import golly as g
import os

r = g.getstring("Rule? Enter in format Bx_Sx-Bx_Sx","B3_S23-B36_S23")
rules = r.split("-")
rule1 = rules[0].split("_")
rule2 = rules[1].split("_")
br1 = rule1[0].translate(None, "B")
sr1 = rule1[1].translate(None, "S")
br2 = rule2[0].translate(None, "B")
sr2 = rule2[1].translate(None, "S")

trans1 = {
    "0": ",0,0,0,0,0,0,0,0,2",
    "1": ",1,0,0,0,0,0,0,0,2",
    "2": ",1,1,0,0,0,0,0,0,2",
    "3": ",1,1,1,0,0,0,0,0,2",
    "4": ",1,1,1,1,0,0,0,0,2",
    "5": ",1,1,1,1,1,0,0,0,2",
    "6": ",1,1,1,1,1,1,0,0,2",
    "7": ",1,1,1,1,1,1,1,0,2",
    "8": ",1,1,1,1,1,1,1,1,2"
    }
trans2 = {
    "0": ",0,0,0,0,0,0,0,0,1",
    "1": ",2,0,0,0,0,0,0,0,1",
    "2": ",2,2,0,0,0,0,0,0,1",
    "3": ",2,2,2,0,0,0,0,0,1",
    "4": ",2,2,2,2,0,0,0,0,1",
    "5": ",2,2,2,2,2,0,0,0,1",
    "6": ",2,2,2,2,2,2,0,0,1",
    "7": ",2,2,2,2,2,2,2,0,1",
    "8": ",2,2,2,2,2,2,2,2,1"
    }
def genTransitions(B,S):
    t = []
    for i in range(0,len(B)):
        t.append("0" + trans1[B[i]])
    for i in range(0,len(S)):
        t.append("1" + trans1[S[i]])
    return t

def genTransitions2(B,S):
    t = []
    for i in range(0,len(B)):
        t.append("0" + trans2[B[i]])
    for i in range(0,len(S)):
        t.append("2" + trans2[S[i]])
    return t

def makeRuleTable(ruleName,nStates,neighborhood,symmetries,transitionsList):
    rule = '@RULE '+ruleName+'\n\n'
    table = '@TABLE\n'+'n_states:'+str(nStates)+'\n'+'neighborhood:'+neighborhood+'\n'+'symmetries:'+symmetries+'\n'
    transitions = '\n'
    for i in range(0,len(transitionsList)):
        transitions = transitions+str(transitionsList[i])+'\n'
        i += 1
    return rule+table+transitions

trans = []
trans.append("var a={0,1,2}")
trans.append("var b=a")
trans.append("var c=a")
trans.append("var d=a")
trans.append("var e=a")
trans.append("var f=a")
trans.append("var g=a")
trans.append("var h=a")
trans.append("#Rule 1")
trans.extend(genTransitions(br1,sr1))
trans.append("1,a,b,c,d,e,f,g,h,0")
trans.append("#Rule 2")
trans.extend(genTransitions2(br2,sr2))
trans.append("2,a,b,c,d,e,f,g,h,0")
theRule = makeRuleTable(r,3,"Moore","permute",trans)

def saverule(name,ruleFile):
    ruledir = g.getdir("rules")
    filename = ruledir + name + ".rule"
    
    # Only create a rule file if it doesn't already exist.
    if not os.path.exists(filename):
        try:
            f = open(filename, 'w')
            f.write(ruleFile)
            f.close()
        except:
            g.warn("Unable to create rule table:\n" + filename)

saverule(r,theRule)
g.setrule(r)
g.show("Rule " + r + " succesfuly created")
A few things I've found:
3c/4o in an explosive rule

Code: Select all

x = 5, y = 10, rule = B3_S23-B2_3
.A.A$2A.2A$2A.2A$A3.A3$A3.A3$.A.A!
Happy 2c/4o in a searchable rule

Code: Select all

x = 7, y = 5, rule = B3_S23-B2_S78
.2A.2A3$A5.A$.5A!
2c/2o in an exploding rule

Code: Select all

x = 2, y = 3, rule = B3_S23-B1_S
B$2B$2B!
3c/8d in a searchable rule

Code: Select all

x = 4, y = 6, rule = B3_S3-B2_S2
2A$3A$.2A$A.A$3.A$3.A!
8c/44d in a searchable rule

Code: Select all

x = 6, y = 6, rule = B3_S23-B35_S23
4.2A$4.2A2$3A$A.A$2A!
p216 in the same rule!

Code: Select all

x = 11, y = 16, rule = B3_S23-B35_S23
6.2A$6.2A3$9.2A$8.2A5$.2A$2A3$3.2A$3.2A!

Re: Alternating rules

Posted: September 16th, 2017, 6:36 am
by muzik

Re: Alternating rules

Posted: September 16th, 2017, 8:08 am
by Saka
muzik wrote:This exists
NOOOOOOOOOooooo whatever. Let's continue the exploration of these!

Code: Select all

x = 5, y = 6, rule = B1_S3-B4_S4560
2.3B$2B2.B$B$B3.B$.B2.B$.3B!
Stable version with a bonus sparky osc

Code: Select all

x = 23, y = 9, rule = B1_S4-B45_S0456
4.A16.A$.A5.A11.A$19.A2.A2$A3.A3.A3$.A5.A$4.A!

Re: Alternating rules

Posted: September 16th, 2017, 8:34 am
by muzik
Extremely boring 1D CA simulator:

Code: Select all

x = 94, y = 1, rule = B123_S012-B6_S8
2A.3A2.A.A3.A.A5.A2.A.4A.A.A.4A.2A.7A2.A.2A.A.2A.6A3.2A3.A7.A2.4A.A!

Re: Alternating rules

Posted: September 16th, 2017, 8:43 am
by Saka
Wacky 18c/36o in a stable rule that can eat gliders from it's side

Code: Select all

x = 120, y = 73, rule = B34_S34-B378_S0124
118.2B$118.B$118.2B2$3.2A$2.4A2$2.4A$3.2A$3.2A3$2A4.2A$2A4.2A$3.2A$2A
4.2A$A6.A$.2A2.2A$3.2A9$2.4A$.A4.A$3.2A2$2A4.2A16$59.2A$58.4A2$58.4A$
57.A4.A$57.A.2A.A$57.A4.A$56.A.4A.A$56.A.4A.A$55.A8.A$56.2A4.2A6$56.A
6.A$56.2A4.2A$56.2A4.2A$55.A3.2A3.A$57.A.2A.A$53.A3.A4.A3.A$54.A3.A2.
A3.A2$54.3A2.2A2.3A$55.3A.2A.3A!
Wacky c/2d's in a wacky rule

Code: Select all

x = 33, y = 16, rule = B123_S345678-B45_S01
31.A$29.B2.A$29.B.B$29.2B.B$2.A27.3B$B2.A$B.B.A.A$3B2$7.A2.A3$7.A2.A
3.A3$10.A!
This version of the rule is just as wacky but is stable

Code: Select all

x = 32, y = 28, rule = B123_S345678-B4_S01
4$25.A$24.A2.B$11.A11.A.B.B$13.B11.3B$13.B$12.2B$8.5B$8.B.B3.A$8.3B2.
A$12.A$9.A$11.A!
This too:

Code: Select all

x = 32, y = 25, rule = B123_S345678-B46_S01
9$6.A$8.B$4.A3.B11.A$7.2B10.A2.B$6.2B12.B.B$9.A9.4B$8.A9.B.B$18.3B!
Even wackier stable version:

Code: Select all

x = 35, y = 34, rule = B123_S345678-B56_S01
32.3B$31.2B.B$30.2B.2B$29.2B.2B$28.2B.2B$27.2B.2B$26.2B.2B$25.2B.2B$
24.2B.2B$23.2B.2B$22.2B.2B$21.2B.2B$20.2B.2B$19.2B.2B$18.2B.2B$17.2B.
2B$16.2B.2B$15.2B.2B$14.2B.2B$13.2B.2B$12.2B.2B$11.2B.2B$10.2B.2B$9.
2B.2B$8.2B.2B$7.2B.2B$6.2B.2B$5.2B.2B$4.2B.2B$3.2B.2B$3.B.2B$A.B.2B$
3.2B$.3B!

Re: Alternating rules

Posted: September 16th, 2017, 4:33 pm
by praosylen
Nice p18:

Code: Select all

x = 5, y = 6, rule = B3_S23-B2_S1
2B.2B5$2B.2B!

Re: Alternating rules

Posted: September 16th, 2017, 11:16 pm
by Saka
2c/4o in a replicator-exploding (Sometimes the replicators cause explosions) rule

Code: Select all

x = 3, y = 3, rule = B8_S3-B1_S1
B$B$2.B!
c/2 and 3c/24d in an explosive rule

Code: Select all

x = 16, y = 5, rule = B4_S01-B1_S1
B$15.B$.B.B11.B2$2.2B9.B!
2c/8d and 10c/100o in a stable rule!

Code: Select all

x = 29, y = 10, rule = B2_S01-B4_S12
A25.B$3A21.5B$20.B3.5B$18.4B2.B$17.B2.B3.B$17.B8.3B$20.3B3.3B$21.B$
18.B2.B2.2B$21.B!
p20 in the same rule

Code: Select all

x = 8, y = 2, rule = B2_S01-B4_S12
2.A2.A$3A2.3A!
EDIT:
3c/12 and a 2c/16

Code: Select all

x = 5, y = 17, rule = B3_S23-B56_S012345678
.3B$B$B$B3.B$.B$2.B.B7$2.A$A$A$A$2.A!

Re: Alternating rules

Posted: September 17th, 2017, 10:58 am
by praosylen
Saka wrote:2c/4o in a replicator-exploding (Sometimes the replicators cause explosions) rule

Code: Select all

x = 3, y = 3, rule = B8_S3-B1_S1
B$B$2.B!
Nice p20 in the same rule:

Code: Select all

x = 5, y = 10, rule = B8_S3-B1_S1
B7$.B$4.B$3.B!
Saka wrote:c/2 and 3c/24d in an explosive rule

Code: Select all

x = 16, y = 5, rule = B4_S01-B1_S1
B$15.B$.B.B11.B2$2.2B9.B!
2c/4:

Code: Select all

x = 5, y = 7, rule = B4_S01-B1_S1
B2.B2$4.B2$4.B2$B2.B!
Saka wrote:EDIT:
3c/12 and a 2c/16

Code: Select all

x = 5, y = 17, rule = B3_S23-B56_S012345678
.3B$B$B$B3.B$.B$2.B.B7$2.A$A$A$A$2.A!
p44:

Code: Select all

x = 3, y = 18, rule = B3_S23-B56_S012345678
.2A$.2A4$A3$.A$.A$.A$.A$.A$.A3$.2A$.2A!
EDIT: A rule with 3c/4 counterfeit glider rakes (as well as a multitude of high-period 3c/4 ships):

Code: Select all

x = 62, y = 17, rule = B2_S345-B3_S34
58.A$58.A$58.A.2A2$57.A.A$59.A$55.2A4.A$20.A34.A.2A$18.A.2A.2A30.A.3A
$3.A9.A.2A3.A.A.A30.A.2A$2A2.2A.A5.2A5.A.A34.A$A3.A3.A4.2A3.A.A14.A$
3.A11.A2.A2.A9.A3.A2.2A$A3.A11.A19.A$3A13.A13.A.A4.A$2.A34.A$35.A!
Sadly, it turns out to be explosive. Flipping the S5 condition to odd generations results in an explosive rule with this c/4d that evolves (in 4 copies) from the block and not much else:

Code: Select all

x = 6, y = 6, rule = B2_S34-B3_S345
.2A$A.A$2A2.A$4.2A$2.2A$3.A!

Re: Alternating rules

Posted: September 23rd, 2017, 8:01 am
by Saka
This exploding rule is super weird, it has strange ships that are shaped like the Life c/2s

Code: Select all

x = 232, y = 30, rule = B23_S-B_S23
3.2A17.2A14.3A13.2A8.2A20.2A2.2A14.2A15.4A51.5A20.6A16.2A$2.A2.A15.A
2.A12.A3.A11.A2.A6.A2.4A15.A2.2A2.A12.A2.A13.A4.A49.A5.4A15.A6.A14.A
2.A$.A4.A13.A15.A.3A.A9.A9.A.2A4.A13.A8.A10.A.2A.A11.A6.A47.A.5A4.A
13.A2.5A.A17.A$A6.A11.A.A.2A10.A7.A9.A.2A4.A4.4A.A11.A10.A25.A8.A45.A
7.4A.A22.A12.2A.A.A$3.3A2.A25.A4.A4.A15.A3.A7.A9.A2.2A4.2A2.A8.2A2.2A
9.A2.2A6.A43.A3.A10.A11.A2.A3.A3.A17.A$2A20.2A31.A9.A3.A3.A13.4A36.A
3.A41.A12.A3.A34.2A4.A$4.A2.2A25.A2.5A2.A15.A21.2A10.2A9.4A10.2A7.A3.
A41.A27.3A4.A2.A$19.4A47.A2.A55.A3.5A49.A2.A35.2A3.A$3.2A34.A24.A18.
3A6.3A11.2A15.A14.A32.A3.A.A33.A17.A.A$2.A69.A13.A4.A36.A4.5A.A30.A6.
A11.A$3.A35.A44.2A6.2A34.A2.2A7.A28.A7.A$129.A3.A3.A3.A26.A2.A5.A$2.A
127.3A34.A2.2A$133.A4.A2.A25.A61.A$167.A$140.A26.A$167.A.A$127.A.A37.
A.A4.A$126.A3.A37.A6.2A$169.A4.A$126.A43.A4.A$127.A43.A.3A$128.A.A41.
A3.A$129.A29.2A12.3A$158.A2.A$157.A4.A$156.A6.A$159.2A3.A$158.A2.A3.A
$164.A!

Re: Alternating rules

Posted: September 23rd, 2017, 4:15 pm
by SuperSupermario24
Lua version of the script (with some other minor adjustments):

Code: Select all

-- altRuleGen.lua
-- Script to generate alternating totalistic rules.
--
-- Original script by Saka, translated from Python to Lua by SuperSupermario24.
--
-- NOTE: NEVER ENTER B0

local g = golly()
local gp = require "gplus"

local r = g.getstring("Enter rule, in format Bx_Sx-Bx_Sx","B3_S23-B36_S23")
local rule1, rule2 = gp.split(r, "-")
local br1, sr1 = gp.split(rule1, "_")
br1 = string.gsub(br1, "B", "")
sr1 = string.gsub(sr1, "S", "")
local br2, sr2 = gp.split(rule2, "_")
br2 = string.gsub(br2, "B", "")
sr2 = string.gsub(sr2, "S", "")

local trans1 = {
",0,0,0,0,0,0,0,0,2",
",1,0,0,0,0,0,0,0,2",
",1,1,0,0,0,0,0,0,2",
",1,1,1,0,0,0,0,0,2",
",1,1,1,1,0,0,0,0,2",
",1,1,1,1,1,0,0,0,2",
",1,1,1,1,1,1,0,0,2",
",1,1,1,1,1,1,1,0,2",
",1,1,1,1,1,1,1,1,2"
}
local trans2 = {
",0,0,0,0,0,0,0,0,1",
",2,0,0,0,0,0,0,0,1",
",2,2,0,0,0,0,0,0,1",
",2,2,2,0,0,0,0,0,1",
",2,2,2,2,0,0,0,0,1",
",2,2,2,2,2,0,0,0,1",
",2,2,2,2,2,2,0,0,1",
",2,2,2,2,2,2,2,0,1",
",2,2,2,2,2,2,2,2,1"
}

local function getChar(a, l)
  return string.sub(a, l, l)
end

local function genTransitions(B,S)
  t = {}
  for i = 1, string.len(B) do
    table.insert(t, "0"..trans1[tonumber(getChar(B, i)) + 1]) -- +1 because Lua starts at 1
  end
  for i = 1, string.len(S) do
    table.insert(t, "1"..trans1[tonumber(getChar(S, i)) + 1])
  end
  return t
end

local function genTransitions2(B,S)
  t = {}
  for i = 1, string.len(B) do
    table.insert(t, "0"..trans2[tonumber(getChar(B, i)) + 1])
  end
  for i = 1, string.len(S) do
    table.insert(t, "2"..trans2[tonumber(getChar(S, i)) + 1])
  end
  return t
end

local function makeRuleTable(ruleName,nStates,neighborhood,symmetries,transitionsList)
  local rule = "@RULE "..ruleName.."\n\nAutomatically generated by a Lua script.\n\n"
  local ruletable = "@TABLE\n".."n_states:"..tostring(nStates).."\n".."neighborhood:"..neighborhood.."\n".."symmetries:"..symmetries.."\n"
  local transitions = "\n"
  for i = 1, #transitionsList do
    transitions = transitions..tostring(transitionsList[i]).."\n"
  end
  return rule..ruletable..transitions
end

local trans = {}
local transr1 = genTransitions(br1, sr1)
local transr2 = genTransitions2(br2, sr2)
table.insert(trans, "var a={0,1,2}")
table.insert(trans, "var b=a")
table.insert(trans, "var c=a")
table.insert(trans, "var d=a")
table.insert(trans, "var e=a")
table.insert(trans, "var f=a")
table.insert(trans, "var g=a")
table.insert(trans, "var h=a")
table.insert(trans, "#Rule 1")
for i = 1, #transr1 do
  table.insert(trans, transr1[i])
end
table.insert(trans, "1,a,b,c,d,e,f,g,h,0")
table.insert(trans, "#Rule 2")
for i = 1, #transr2 do
  table.insert(trans, transr2[i])
end
table.insert(trans, "2,a,b,c,d,e,f,g,h,0")

local theRule = makeRuleTable(r,3,"Moore","permute",trans)

local function fileExists(name)
  local a
  local f = io.open(name, "r")
  if f == nil then
    return false
  else
    f:close()
    return true
  end
end

local a = 0
local function saveRule(name, ruleFile)
  local ruledir = g.getdir("rules")
  local filename = ruledir..name..".rule"
  if not fileExists(filename) then
    a = 1
    local file = assert(io.open(filename, "w"), "Unable to create rule table:\n"..filename)
    file:write(ruleFile)
    file:close()
  end
end
saveRule(r, theRule)
g.setrule(r)
if a == 1 then
  g.show("Created and switched to rule "..r..".")
else
  g.show("Switched to rule "..r..".")
end
I can't actually verify that this works the same as the Python version of the script (Python refuses to work with Golly for me for some reason), but I've verified the script to work with most of the rules and patterns posted in this thread, so it should be good. If anyone encounters any issues with it, though, let me know.

Re: Alternating rules

Posted: October 1st, 2017, 2:11 am
by SuperSupermario24
And, a version that supports non-totalistic rules (separate rules with two dashes instead of one):

Code: Select all

-- altRuleGen.lua
-- Script to generate alternating non-totalistic rules.
-- (Note: this makes no attempt to canonize the rulestrings.)
--
-- Original Python script by Saka.
--
-- Translated to Lua and then modified to include
-- non-totalistic rules by SuperSupermario24.
--
-- NOTE: NEVER ENTER B0

local g = golly()
local gp = require "gplus"

local r = g.getstring("Enter rule, in format Bx_Sx--Bx_Sx","B3_S2-i34q--B3_S23")
local rule1, rule2 = gp.split(r, "--")

local br1, sr1 = gp.split(rule1, "_")
br1 = string.gsub(br1, "B", "")
sr1 = string.gsub(sr1, "S", "")
local br2, sr2 = gp.split(rule2, "_")
br2 = string.gsub(br2, "B", "")
sr2 = string.gsub(sr2, "S", "")

trans0 = {
",0,0,0,0,0,0,0,0,y"
}

trans1 = {
["c"] = ",0,0,0,0,0,0,0,x,y",
["e"] = ",x,0,0,0,0,0,0,0,y"
}

trans2 = {
["c"] = ",0,x,0,0,0,0,0,x,y",
["e"] = ",x,0,0,0,0,0,x,0,y",
["k"] = ",0,0,x,0,0,0,0,x,y",
["a"] = ",x,0,0,0,0,0,0,x,y",
["i"] = ",x,0,0,0,x,0,0,0,y",
["n"] = ",0,0,0,x,0,0,0,x,y"
}

trans3 = {
["c"] = ",0,x,0,0,0,x,0,x,y",
["e"] = ",x,0,x,0,0,0,x,0,y",
["k"] = ",0,0,x,0,x,0,0,x,y",
["a"] = ",x,0,0,0,0,0,x,x,y",
["i"] = ",x,x,0,0,0,0,0,x,y",
["n"] = ",0,x,x,0,0,0,0,x,y",
["y"] = ",0,x,0,0,x,0,0,x,y",
["q"] = ",x,0,0,x,0,0,0,x,y",
["j"] = ",x,0,x,0,0,0,0,x,y",
["r"] = ",x,0,0,0,x,0,0,x,y"
}

trans4 = {
["c"] = ",0,x,0,x,0,x,0,x,y",
["e"] = ",x,0,x,0,x,0,x,0,y",
["k"] = ",0,x,0,0,x,0,x,x,y",
["a"] = ",x,x,x,0,0,0,0,x,y",
["i"] = ",0,x,x,0,0,0,x,x,y",
["n"] = ",x,x,0,0,0,x,0,x,y",
["y"] = ",0,x,x,0,0,x,0,x,y",
["q"] = ",x,0,0,x,0,0,x,x,y",
["j"] = ",x,0,x,0,x,0,0,x,y",
["r"] = ",x,0,x,0,0,0,x,x,y",
["t"] = ",x,x,0,0,x,0,0,x,y",
["w"] = ",x,0,x,x,0,0,0,x,y",
["z"] = ",x,0,0,x,x,0,0,x,y"
}

trans5 = {
["c"] = ",x,0,x,x,x,0,x,0,y",
["e"] = ",0,x,0,x,x,x,0,x,y",
["k"] = ",x,x,0,x,0,x,x,0,y",
["a"] = ",0,x,x,x,x,x,0,0,y",
["i"] = ",0,0,x,x,x,x,x,0,y",
["n"] = ",x,0,0,x,x,x,x,0,y",
["y"] = ",x,0,x,x,0,x,x,0,y",
["q"] = ",0,x,x,0,x,x,x,0,y",
["j"] = ",0,x,0,x,x,x,x,0,y",
["r"] = ",0,x,x,x,0,x,x,0,y"
}

trans6 = {
["c"] = ",x,0,x,x,x,x,x,0,y",
["e"] = ",0,x,x,x,x,x,0,x,y",
["k"] = ",x,x,0,x,x,x,x,0,y",
["a"] = ",0,x,x,x,x,x,x,0,y",
["i"] = ",0,x,x,x,0,x,x,x,y",
["n"] = ",x,x,x,0,x,x,x,0,y"
}

trans7 = {
["c"] = ",x,x,x,x,x,x,x,0,y",
["e"] = ",0,x,x,x,x,x,x,x,y"
}

trans8 = {
",x,x,x,x,x,x,x,x,y"
}

config0 = {1}
config1 = {"c", "e"}
config2 = {"c", "e", "k", "a", "i", "n"}
config3 = {"c", "e", "k", "a", "i", "n", "y", "q", "j", "r"}
config4 = {"c", "e", "k", "a", "i", "n", "y", "q", "j", "r", "t", "w", "z"}

local function getChar(a, l)
  return string.sub(a, l, l)
end

transitions = {
["0"] = trans0,
["1"] = trans1,
["2"] = trans2,
["3"] = trans3,
["4"] = trans4,
["5"] = trans5,
["6"] = trans6,
["7"] = trans7,
["8"] = trans8
}
configs = {
["0"] = config0,
["1"] = config1,
["2"] = config2,
["3"] = config3,
["4"] = config4,
["5"] = config3,
["6"] = config2,
["7"] = config1,
["8"] = config0
}

local function fixTransition(s, n)
  if(n == 1) then
    s = string.gsub(s, "x", 1)
    s = string.gsub(s, "y", 2)
  elseif(n == 2) then
    s = string.gsub(s, "x", 2)
    s = string.gsub(s, "y", 1)
  end
  return s
end

local function genTransitions(B, S, n)
  t = {}
  for i in string.gmatch(B, "%d[%-%a]*") do
    if(getChar(i, 2) == "-") then
      local t2 = {table.unpack(configs[getChar(i, 1)])}
      for j = 3, string.len(i) do
        for k = 1, #t2 do
          if(getChar(i, j) == t2[k]) then table.remove(t2, k) end
        end
      end
      for j = 1, #t2 do
        table.insert(t, "0"..fixTransition(transitions[getChar(i, 1)][t2[j]], n))
      end
    elseif(getChar(i, 2) == "") then
      for j = 1, #configs[i] do
        table.insert(t, "0"..fixTransition(transitions[i][configs[i][j]], n))
      end
    else
      for j = 2, string.len(i) do
        table.insert(t, "0"..fixTransition(transitions[getChar(i, 1)][getChar(i, j)], n))
      end
    end
  end
  for i in string.gmatch(S, "%d[%-%a]*") do
    if(getChar(i, 2) == "-") then
      local t2 = {table.unpack(configs[getChar(i, 1)])}
      for j = 3, string.len(i) do
        for k = 1, #t2 do
          if(getChar(i, j) == t2[k]) then table.remove(t2, k) end
        end
      end
      for j = 1, #t2 do
        table.insert(t, n..fixTransition(transitions[getChar(i, 1)][t2[j]], n))
      end
    elseif(getChar(i, 2) == "") then
      for j = 1, #configs[i] do
        table.insert(t, n..fixTransition(transitions[i][configs[i][j]], n))
      end
    else
      for j = 2, string.len(i) do
        table.insert(t, n..fixTransition(transitions[getChar(i, 1)][getChar(i, j)], n))
      end
    end
  end
  return t
end

local function makeRuleTable(ruleName,nStates,neighborhood,symmetries,transitionsList)
  local rule = "@RULE "..ruleName.."\n\nAutomatically generated by a Lua script.\n\n"
  local ruletable = "@TABLE\n".."n_states:"..tostring(nStates).."\n".."neighborhood:"..neighborhood.."\n".."symmetries:"..symmetries.."\n"
  local transitions = "\n"
  for i = 1, #transitionsList do
    transitions = transitions..tostring(transitionsList[i]).."\n"
  end
  return rule..ruletable..transitions
end

local trans = {}
local transr1 = genTransitions(br1, sr1, 1)
local transr2 = genTransitions(br2, sr2, 2)
table.insert(trans, "var a={0,1,2}")
table.insert(trans, "var b=a")
table.insert(trans, "var c=a")
table.insert(trans, "var d=a")
table.insert(trans, "var e=a")
table.insert(trans, "var f=a")
table.insert(trans, "var g=a")
table.insert(trans, "var h=a")
table.insert(trans, "#Rule 1")
for i = 1, #transr1 do
  table.insert(trans, transr1[i])
end
table.insert(trans, "1,a,b,c,d,e,f,g,h,0")
table.insert(trans, "#Rule 2")
for i = 1, #transr2 do
  table.insert(trans, transr2[i])
end
table.insert(trans, "2,a,b,c,d,e,f,g,h,0")

local theRule = makeRuleTable(r,3,"Moore","rotate4reflect",trans)

local function fileExists(name)
  local a
  local f = io.open(name, "r")
  if f == nil then
    return false
  else
    f:close()
    return true
  end
end

local a = 0
local function saveRule(name, ruleFile)
  local ruledir = g.getdir("rules")
  local filename = ruledir..name..".rule"
  if not fileExists(filename) then
    a = 1
    local file = assert(io.open(filename, "w"), "Unable to create rule table:\n"..filename)
    file:write(ruleFile)
    file:close()
  end
end
saveRule(r, theRule)
g.setrule(r)
if a == 1 then
  g.show("Created and switched to rule "..r..".")
else
  g.show("Switched to rule "..r..".")
end
This should work for any rule, but if I've made any mistakes in the transitions let me know.

Re: Alternating rules

Posted: October 1st, 2017, 7:53 am
by Saka
Great! Here is the alt-rule version of B026/S1:

Code: Select all

x = 614, y = 26, rule = B13i_S02i--B_S2i8
A.A2.5A3.7A5$7A2.A.A2.3A2.A2.A3.3A2.A2.A5$A3.3A3.A2.A.A2.A3.A2.11A2.A
2.3A4.2A5$A3.3A3.A2.A2.A2.A2.3A3.7A2.A.A2.3A2.A2.A2.A2.A4.7A3.A3.A3.
5A2.A.A2.A3.5A2.A.A.A.A2.5A3.6A3.5A3.A2.A.A.A.A2.A3.6A2.A.A2.A4.A2.A.
A.A2.A2.A.A.A.A2.A3.A2.A.A.A2.3A2.A.A.A2.3A3.3A3.3A2.A2.A3.A3.3A3.A3.
A3.3A2.A.A.A2.A2.A.A.A2.A3.A3.3A3.3A3.A2.A2.A3.A2.A2.A2.A2.A2.10A3.3A
2.A.A2.2A2.A.A.A2.3A2.A2.A3.3A3.A3.A2.A.A2.11A3.5A2.A2.15A2.A2.7A3.5A
2.A.A.A.A.A.A.A2.A2.A3.3A3.5A2.A.A2.A2.A.A.A2.5A3.3A2.A.A2.A2.A2.6A2.
A2.A2.A2.A3.3A2.A.A.A2.6A3.7A3.7A2.A.A.A.A2.3A3.A2.A.A.A2.2A5$A3.3A3.
A2.A2.A3.7A3.5A2.A.A2.A3.A2.A2.A3.2A2.A.A.A2.3A2.A2.3A3.A2.A2.A2.A3.A
2.A.A2.A3.3A3.2A3.A3.7A3.3A2.A2.9A2.A.A2.A3.A3.5A3.A2.A.A.A2.A2.A.A2.
A2.A2.3A3.3A3.3A2.A.A2.11A2.A2.A2.A2.3A2.A2.3A2.A2.A3.3A2.A.A2.3A3.5A
2.A.A.A.A.A.A.A.A2.5A3.5A2.A2.A2.A2.3A2.A.A2.A3.3A3.3A3.5A3.5A2.A2.7A
3.A2.A2.A2.A2.3A3.5A2.A2.11A3.3A2.A2.5A3.A5$2A3.3A2.A.A.A.A2.A2.A2.A
3.7A3.7A2.A2.7A3.A3.A2.A!
It's also non-explosive!

Funny rule:

Code: Select all

x = 4, y = 2, rule = B2a_S1c--B2k_S1e
.2A$A2.A!

Code: Select all

x = 2, y = 3, rule = B1c3a_S2a4ar--B4r_S3a4a5cj
.A$2A$2A!
4,2c/10 knightship

Code: Select all

x = 3, y = 6, rule = B3_S23--B2ae_S1e2ae3ae4ae
.2A$3A$A2$A$3A!
c/76d

Code: Select all

x = 7, y = 11, rule = B3_S23--B2a3i_S1e2ae3ae4ae
5.2A$.2A2.2A$3A$3A.A$4.A$3A$2A$.A$2.2A2$4.2A!

Re: Alternating rules

Posted: October 2nd, 2017, 4:58 am
by Saka
Weird:

Code: Select all

x = 4, y = 4, rule = B2-kn3aein_S--B_S23
.2A$A2.A$A2.A$.2A!
especially when the giantmegalithicgrowingdiamonds collide:

Code: Select all

x = 224, y = 75, rule = B2-kn3aein_S--B_S23
221.2A$220.A2.A$220.A2.A$221.2A68$.2A$A2.A$A2.A$.2A!
Cute ship in a different rule:

Code: Select all

x = 2, y = 3, rule = B1e_S23--B3_S3
.A$A$2A!

Re: Alternating rules

Posted: October 2nd, 2017, 7:32 am
by Rhombic
For the lua script, I get the following error:

Code: Select all

.\gplus\init.lua:157: attempt to index a nil value (local 's')
EDIT: works in Golly 3.0+

Code: Select all

x = 25, y = 24, rule = B2-a_S12--B2c3_S12
3$9.A2$8.A$8.A5.A$9.2A3.A$14.2A2.A$16.2A6$11.A$9.A3.A$9.A$11.A2.A2$
12.2A!

Code: Select all

x = 7, y = 7, rule = B2-a_S12--B2c3_S12-a
$2B$5B$2B.2B$.3B!

Re: Alternating rules

Posted: December 31st, 2017, 12:43 am
by Saka
blump

Code: Select all

x = 58, y = 89, rule = B36i_S123--B1e_S125i8
7.2B2$5.3A$3.A14$47.2B$46.4B2$46.4A11$55.B$55.2B2$53.B$53.B6$54.2B2$
13.2B41.2A2$8.2B8.2B2$8.4A6.4A2$4.2A7.4A$A$2.A43.A$2.A$50.2A2.2A2$55.
2B$46.A$51.B$51.B11$47.4A2$42.4A6.4A$47.3A$54.2B11$51.2A2$49.4B2$51.
2A!

Re: Alternating rules

Posted: May 1st, 2018, 6:22 am
by Rhombic
This probably is the most unusual alternating rule family I have discovered, see for yourself the c/4d and the ludicrous (7,2)c/94 oblique spaceship!

Code: Select all

x = 16, y = 7, rule = B1e_S0123nqr--B3-i_S2a
.2A7.2A.2A$A.A7.A3.A$15.A2$10.A4.A2$15.A!