Exemplo n.º 1
0
# add new converters here as they become available:
Converters = {
    "vonNeumann":ConvertRuleTableTransitionsToRuleTree,
    "Moore":ConvertRuleTableTransitionsToRuleTree,
    "triangularVonNeumann":EmulateTriangular,
    "triangularMoore":EmulateTriangular,
    "Margolus":EmulateMargolus,
    "square4_figure8v":EmulateMargolus,
    "square4_figure8h":EmulateMargolus,
    "square4_cyclic":EmulateMargolus,
    "oneDimensional":EmulateOneDimensional,
    "hexagonal":EmulateHexagonal,
}

golly.show("Reading from rule table file...")
n_states, neighborhood, transitions = ReadRuleTable(filename)

if not neighborhood in Converters:
    golly.warn("Unsupported neighborhood: "+neighborhood)
    golly.show('')
    golly.exit()

# all converters now create a .rule file
golly.show("Building rule...")
rule_name = Converters[neighborhood]( neighborhood,
                                      n_states,
                                      transitions,
                                      filename )

golly.new(rule_name+'-demo.rle')
golly.setalgo('RuleLoader')
f.write('# convert any MCell Margolus specification into a rule table.\n')
f.write('#\n')
f.write('n_states:2\nneighborhood:Margolus\nsymmetries:none\n\n')

# the 16 cases of the (two-state) Margolus partition are:
dot = (0,0,0,0),(1,0,0,0),(0,1,0,0),(1,1,0,0),(0,0,1,0),(1,0,1,0),(0,1,1,0),(1,1,1,0),\
      (0,0,0,1),(1,0,0,1),(0,1,0,1),(1,1,0,1),(0,0,1,1),(1,0,1,1),(0,1,1,1),(1,1,1,1)
# cell order: 1  2
#             3  4
# (see: http://psoup.math.wisc.edu/mcell/rullex_marg.html )

for i in range(16):
    if not i == becomes[i]:
        # (we can skip no-change transitions)
        f.write(','.join(map(str,dot[i]))+' : '+\
            ','.join(map(str,dot[becomes[i]]))+\
            '   # '+str(i)+' -> '+str(becomes[i])+'\n')
f.flush()
f.close()

# emulate the rule table with tree data in a .rule file
n_states, neighborhood, transitions = ReadRuleTable(tablepath)
golly.show("Building rule...")
rule_name = EmulateMargolus(neighborhood, n_states, transitions, tablepath)
os.remove(tablepath)

golly.new(rule_name + '-demo.rle')
golly.setalgo('RuleLoader')
golly.setrule(rule_name)
golly.show('Created ' + rule_name + '.rule and selected that rule.')
Exemplo n.º 3
0
                    break
                if export != 1:
                    if line[:6] == "@TABLE":
                        export = 1
                else:
                    if line[:1] == "@":
                        export = 2
                    else:
                        f1.write(line)
        if export == -1:
            # rule already constants @TREE so copy the rule to the output folder
            shutil.copy(rulefilename, outfolder)
        else:
            # attempt to read the rule
            readtime = time.time()
            n_states, neighborhood, transitions, message = ReadRuleTable(
                filename, loadtimelimit)
            seconds = time.time() - readtime

            # check if read was successful
            if n_states == -1:
                # check if read timed out
                if message == "Exceeded loading time limit":
                    message = message + " (" + str(
                        loadtimelimit) + " seconds)."
                    elapsed = "[{0:02d}:{1:02d}]".format(
                        int(seconds / 60), int(seconds % 60))
                    status = "LOAD"
                    n_loadtimeout = n_loadtimeout + 1
                else:
                    status = "ERROR"
                    n_error = n_error + 1