For the record, here are the new Lua conversion scripts that I came up with for the Super algo. The old ones fail to recognize "Investigator" as a valid suffix, so they do Very Wrong Things when faced with any [Rule]Investigator pattern, telling the user that "Investigator" is not supported by Super and suggesting a Ctrl+Z Undo when that isn't actually appropriate, and so on.
I've done a level of testing on these modifications that could generously be described as "sanity checking". What's probably really needed is a test bed of as wide a variety of input patterns and conversion paths as possible. I would be surprised if all the interesting and useful edge cases are getting handled in the best possible way. Please try these out, either when the new 4.3b2 is available, or preferably even before that!
toInvestigator.lua:
Code: Select all
-- Fast [Rule] to [Rule]Investigator converter,
-- intended to be mapped to a keyboard shortcut, e.g., Alt+I
-- v1.0, 11 May 2024: initial version
local g = golly()
local rule = g.getrule()
local algo = g.getalgo()
-- deal with bounded-universe syntax appropriately
suffix = ""
baserule = rule
ind = string.find(rule, ":")
if ind then
suffix = rule:sub(ind)
baserule = rule:sub(1,ind-1)
end
-- No effect if the current rule ends with "Investigator"
if algo == "Super" then
if baserule:sub(-12) == "Investigator" then
g.exit("The current rule is already a [Rule]Investigator rule.")
elseif baserule:sub(-7) == "History" or baserule:sub(-5) == "Super" then
g.exit("Please use Alt/Option+J (toStandard.lua) to convert to a Standard rule "..
"before using this script to convert the pattern to an Investigator rule.")
end
end
step = g.getstep()
-- attempt to set the new Investigator rule to see if it is valid
local function tryrule()
g.setrule(baserule.."Investigator"..suffix)
end
local status, err = pcall(tryrule)
if err then
g.note("Conversion failed. This '"..baserule.."' rule is not supported by the Super algo.\n"
.. "To revert to the original rule, please click OK, then press Z to undo the rule change.")
g.exit("Press Z to revert to the original rule.")
end
g.setstep(step)
toSuper.lua:
Code: Select all
-- [Rule] or [Rule]History to [Rule]Super converter,
-- intended to be mapped to a keyboard shortcut, e.g., Alt+G
-- v1.1, 30 April 2023: better error-checking by GUYTU6J
-- v1.2, 11 May 2024: support [Rule]Investigator patterns
local g = golly()
local rule = g.getrule()
local algo = g.getalgo()
-- deal with bounded-universe syntax appropriately
suffix = ""
baserule = rule
ind = string.find(rule, ":")
if ind then
suffix = rule:sub(ind)
baserule = rule:sub(1,ind-1)
end
-- No effect if the current rule ends with "Super"
if algo == "Super" and baserule:sub(-5) == "Super" then
g.exit("The current rule is already a [Rule]Super rule.")
end
step = g.getstep()
-- If rulestring contains "History" suffix, remove it and continue
if algo == "Super" then
if baserule:sub(-7) == "History" then
baserule = baserule:sub(1, #baserule-7)
elseif baserule:sub(-12) == "Investigator" then
g.exit("Please use Alt/Option+J (toStandard.lua) to convert to a Standard rule "..
"before using this script to convert the pattern to a Super rule.")
end
end
-- attempt to set the new Super rule to see if it is valid
local function tryrule()
g.setrule(baserule.."Super"..suffix)
end
local status, err = pcall(tryrule)
if err then
g.note("Conversion failed. This '"..baserule.."' rule is not supported by the Super algo.\n"
.. "To revert to the original rule, please click OK, then press Z to undo the rule change.")
g.exit("Press Z to revert to the original rule.")
end
g.setstep(step)
toHistory.lua:
Code: Select all
-- Fast [Rule] or [Rule]Super or [Rule]Investigator to [Rule]History converter,
-- intended to be mapped to a keyboard shortcut, e.g., Alt+H
-- Sanity checks and Lua translation by Dave Greene, May 2017
-- Creates special rule and runs it for one generation, then switches to Life
-- Replace 2k + 1-> 1 and 2k -> 0
-- Preserves step and generation count
-- v1.1: skip the SuperToHistory conversion unless the current name has a "Super" suffix
-- v1.2, 30 April 2023: better error-checking and recovery by GUYTU6J
-- v1.3, 11 May 2024: include check for [Rule]Investigator patterns, don't attempt to convert
local g = golly()
local rule = g.getrule()
local algo = g.getalgo()
ruletext = [[@RULE SuperToHistory
@TABLE
n_states:26
neighborhood:oneDimensional
symmetries:none
var a={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25}
var b={a}
var withtrailON ={9,11}
var withtrailOFF={10,12}
var notrailON ={13,15,17,19,21,23,25}
var notrailOFF ={14,16,18,20,22,24}
var markedON ={7}
var markedOFF ={8}
notrailOFF ,a,b,0
withtrailON ,a,b,1
notrailON ,a,b,1
withtrailOFF,a,b,2
markedON ,a,b,3
markedOFF ,a,b,4]]
local function CreateRule()
local fname = g.getdir("rules").."SuperToHistory.rule"
local f=io.open(fname,"r")
if f~=nil then
io.close(f) -- rule already exists
else
local f = io.open(fname, "w")
if f then
f:write(ruletext)
f:close()
else
g.warn("Can't save SuperToHistory rule in filename:\n"..filename)
end
end
end
-- deal with bounded-universe syntax appropriately
suffix = ""
baserule = rule
ind = string.find(rule, ":")
if ind then
suffix = rule:sub(ind)
baserule = rule:sub(1,ind-1)
end
-- No effect if the current rule ends with "History"
if algo == "Super" and baserule:sub(-7) == "History" then
g.exit("The current rule is already a [Rule]History rule.")
end
step = g.getstep()
-- If rulestring contains "Super" suffix, remove it and continue
if algo == "Super" then
if baserule:sub(-5) == "Super" then
baserule = baserule:sub(1,#baserule-5)
CreateRule()
g.setrule("SuperToHistory")
g.run(1)
g.setgen("-1")
elseif baserule:sub(-12) == "Investigator" then
g.exit("Please use Alt/Option+J (toStandard.lua) to convert to a Standard rule "..
"before using this script to convert the pattern to a History rule.")
end
end
-- attempt to set the new History rule to see if it is valid
local function tryrule()
g.setrule(baserule.."History"..suffix)
end
-- DMG: just run "tryrule()" here on a StateInvestigator pattern
-- after breaking the above Investigator check. Where is this failing?
local status, err = pcall(tryrule)
if err then
g.note("Conversion failed. This '"..baserule.."' rule is not supported by the Super algo.\n"
.. "To revert to the original rule, please click OK, then press Z to undo the rule change.")
g.exit("Press Z to revert to the original rule.")
end
g.setstep(step)
toStandard.lua:
Code: Select all
-- Fast [Rule][History|Super] to [Rule] converter by Michael Simkin,
-- intended to be mapped to a keyboard shortcut, e.g., Alt+J
-- Sanity checks and Lua translation by Dave Greene, May 2017
-- Creates special rule and runs it for one generation, then switches to Life
-- Replace 2k + 1-> 1 and 2k -> 0
-- Preserves step and generation count
-- v1.1, 11 May 2024: support [Rule]Investigator patterns
local g = golly()
local rule = g.getrule()
local algo = g.getalgo()
local function CreateRule(filename, ruletext)
local fname = g.getdir("rules")..filename..".rule"
local f=io.open(fname,"r")
if f~=nil then
io.close(f) -- rule already exists
else
local f = io.open(fname, "w")
if f then
f:write(ruletext)
f:close()
else
g.warn("Can't save SuperToStandard rule in filename:\n"..filename)
end
end
end
-- deal with bounded-universe syntax appropriately
ind = string.find(rule, ":")
suffix = ""
baserule = rule
if ind then
suffix = rule:sub(ind)
baserule = rule:sub(1,ind-1)
end
-- No effect if the current rule is not a Super algo rule
if algo ~= "Super" then g.exit("The current rule is not a [Rule]History, [Rule]Super, or [Rule]Investigator rule.") end
ruletextSuper = [[@RULE SuperToStandard
@TABLE
n_states:26
neighborhood:oneDimensional
symmetries:none
var a={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25}
var b={a}
var c={2,4,6,8,10,12,14,16,18,20,22,24}
var d={3,5,7,9,11,13,15,17,19,21,23,25}
c,a,b,0
d,a,b,1]]
CreateRule("SuperToStandard", ruletextSuper)
ruletextInvestigator = [[@RULE InvestigatorToStandard
@TABLE
n_states:21
neighborhood:oneDimensional
symmetries:none
var a={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}
var b={a}
var c={2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}
c,a,b,0]]
CreateRule("InvestigatorToStandard", ruletextInvestigator)
-- If rulestring contains "Super", "History", or "Investigator" suffix, remove it and continue
if baserule:sub(-5) == "Super" then
baserule = baserule:sub(1,#baserule-5)
g.setrule("SuperToStandard")
elseif baserule:sub(-7) == "History" then
baserule = baserule:sub(1, #baserule-7)
g.setrule("SuperToStandard")
elseif baserule:sub(-12) == "Investigator" then
baserule = baserule:sub(1,#baserule-12)
g.setrule("InvestigatorToStandard")
else
g.show("Rule is not one of the known formats supported by the Super algorithm.")
g.exit()
end
-- If rulestring is "LifeV" then convert it to B3/S23V
if baserule:lower() == "lifev" then baserule = "B3/S23V" end
-- If rulestring is "LifeH" then convert it to B3/S23H
if baserule:lower() == "lifeh" then baserule = "B3/S23H" end
g.run(1)
step = g.getstep()
g.setrule(baserule .. suffix)
g.setalgo("HashLife")
g.setstep(step)
g.setgen("-1")