예제 #1
0
def validate_designed_seed(g, seed_path, max_area):
    """
  This function checks whether we can convert a human-made pattern file
  into a seed.
  """
    #
    # We only want *.rle or *.lif
    #
    file_base, file_extension = os.path.splitext(seed_path)
    if (file_extension != ".rle") and (file_extension != ".lif"):
        return 0
    #
    # Golly has two kinds of cell lists, one that contains an even number
    # of members and one that contains an odd number of members. The
    # former is intended for two states (0 and 1) and the latter is intended
    # for more than two states. Here we are only interested in patterns designed
    # for the Game of Life, which only has two states.
    #
    cell_list = g.load(seed_path)
    #
    # Make sure cell_list is not too small
    #
    too_small = 5
    #
    if (len(cell_list) <= too_small):
        return 0
    #
    # We can only handle cell_list if it has an even number of members.
    #
    if (len(cell_list) % 2 != 0):
        return 0
    #
    # See how big this pattern is.
    #
    min_x = cell_list[0]
    max_x = cell_list[0]
    min_y = cell_list[1]
    max_y = cell_list[1]
    #
    for i in range(0, len(cell_list), 2):
        pair = (cell_list[i], cell_list[i + 1])
        (x, y) = pair
        if (x < min_x):
            min_x = x
        if (x > max_x):
            max_x = x
        if (y < min_y):
            min_y = y
        if (y > max_y):
            max_y = y
    #
    # Make sure it's not too big.
    #
    if (max_x * max_y > max_area):
        return 0
    #
    # Passed all tests.
    #
    return 1
예제 #2
0
def load_designed_seed(g, seed_path):
    """
  Given the path to a human-designed Game of Life pattern, load the
  file and convert it to a seed.
  """
    #
    # Golly has two kinds of cell lists, one that contains an even number
    # of members and one that contains an odd number of members. The
    # former is intended for two states (0 and 1) and the latter is intended
    # for more than two states. Here we are only interested in patterns designed
    # for the Game of Life, which only has two states.
    #
    cell_list = g.load(seed_path)
    #
    # Make sure that cell_list is the type of list that contains an even
    # number of members. Make sure cell_list is not unreasonably small.
    #
    assert len(cell_list) % 2 == 0
    assert len(cell_list) > 10
    #
    # Convert cell_list to a list of (x, y) pairs.
    #
    pair_list = []
    min_x = cell_list[0]
    max_x = cell_list[0]
    min_y = cell_list[1]
    max_y = cell_list[1]
    #
    for i in range(0, len(cell_list), 2):
        pair = (cell_list[i], cell_list[i + 1])
        pair_list.append(pair)
        (x, y) = pair
        if (x < min_x):
            min_x = x
        if (x > max_x):
            max_x = x
        if (y < min_y):
            min_y = y
        if (y > max_y):
            max_y = y
    #
    # Convert pair_list to a seed. Start with a seed full of
    # zeros and set the cells given in pair_list to ones.
    #
    assert min_x == 0
    assert min_y == 0
    assert max_x > 0
    assert max_y > 0
    #
    s_xspan = max_x + 1
    s_yspan = max_y + 1
    #
    seed = mclass.Seed(s_xspan, s_yspan, mparam.pop_size)
    #
    for pair in pair_list:
        (x, y) = pair
        seed.cells[x][y] = 1
    #
    return seed
예제 #3
0
Brle = Srle = "b10$b10$b26$b10$b10$b26$b10$b10$b!"
for ch in Bvalues:
    ind = 32-int(ch)*4 # because B and S values are highest at the top!
    Brle = Brle[:ind] + "o" + Brle[ind+1:]
for ch in Svalues:
    ind = 32-int(ch)*4
    Srle = Srle[:ind] + "o" + Srle[ind+1:]
RuleBits = pattern(Brle, 148, 1404) + pattern(Srle, 162, 1406)

# load or generate the OFFcell tile:
OFFcellFileName = g.getdir("data") + "metapixel-OFF.rle"
ONcellFileName = g.getdir("data") + "metapixel-ON.rle"
if os.access(OFFcellFileName, os.R_OK) and os.access(ONcellFileName, os.R_OK):
    g.show("Opening metapixel-OFF and metapixel-ON from saved pattern file.")
    OFFcell = pattern(g.transform(g.load(OFFcellFileName),-5,-5,1,0,0,1))
    ONcell = pattern(g.transform(g.load(ONcellFileName),-5,-5,1,0,0,1))

else:
    g.show("Building OFF metacell definition...")
    # slide #21: programmables --------------------
    
    LWSS = pattern("b4o$o3bo$4bo$o2bo!", 8, 0)
    
    DiagProximityFuse = pattern("""
    bo$obo$bo2$4b2o$4b2o$59b2o$59b2o3$58b2o2b2o$9b2o3bo5bo5bo5bo5bo5bo5bo
    7b2o2b2o$9bo3bobo3bobo3bobo3bobo3bobo3bobo3bobo$10bo2bo2bo2bo2bo2bo2bo
    2bo2bo2bo2bo2bo2bo2bo2bo$11bobo3bobo3bobo3bobo3bobo3bobo3bobo3bo5b2o$
    12bo5bo5bo5bo5bo5bo5bo5bo3bobo$55bo2bo$56bobo$57bo!
    """, -5, -5)
    
예제 #4
0
LHoutfolder = os.path.join(scriptpath, "LHguns")
infolder = os.path.join(scriptpath, "template")
specialfolder = os.path.join(scriptpath, "template", "specialcases")
fixedfolder = os.path.join(scriptpath, "glider_guns-master", "fixed")
vargunfolder = os.path.join(scriptpath, "glider_guns-master", "variable")
readmefolder = os.path.join(scriptpath, "glider_guns-master")

if not os.path.exists(outfolder): os.makedirs(outfolder)
if not os.path.exists(LHoutfolder): os.makedirs(LHoutfolder)

onlyfiles = [f for f in listdir(infolder) if isfile(os.path.join(infolder, f))]
baseguns = dict()
for file in onlyfiles:
    name, dx, dy, offset = file[:-4].split(",")  # remove '.rle'
    baseguns[name] = [
        g.load(os.path.join(infolder, file)),
        int(dx),
        int(dy),
        int(offset)
    ]
specialguns = dict()
specialfiles = [
    f for f in listdir(specialfolder) if isfile(os.path.join(specialfolder, f))
]
for file in specialfiles:  # these are not adjustable guns and are saved in final form,
    # so no need for dx, dy, or offset
    name, dx, dy, offset = file[:-4].split(",")  # remove '.rle'
    specialguns[name] = [
        g.load(os.path.join(specialfolder, file)),
        int(dx),
        int(dy),
예제 #5
0
orientlist = []
ticklist = []

f = open(libraryFN, 'r')
patnames = f.readlines()
f.close()

matchtype = 0

for name in patnames:
    tickstorun = 0
    basename = removecomments(name)
    temp = basename.split(" ")
    if len(temp) == 2: basename, tickstorun = temp
    if len(temp) == 3: basename, tickstorun, matchtype = temp
    base = g.load(libpath + basename + ".rle")
    # oddly, g.load() doesn't pay attention to CXRLE -- it just
    #  loads the pattern at (0,0).  So we have to normalize anyway...!
    offx, offy = findTL(base)
    base = g.transform(base, -offx,
                       -offy)  # move upper left live cell to (0,0)
    writepatdef(
        basename, base
    )  #TODO:  write script in two phases, including only patterns actually used
    g.show("Loading pattern '" + basename + "' into memory.")
    n, p, x, o, t = getallorientations(basename, base, int(tickstorun),
                                       int(matchtype))
    namelist += n
    patlist += p
    xformlist += x
    orientlist += o
예제 #6
0
outfolder = os.path.join(scriptpath, "guns")
LHoutfolder = os.path.join(scriptpath, "LHguns")
infolder = os.path.join(scriptpath, "template")
specialfolder = os.path.join(scriptpath,"template", "specialcases")
fixedfolder = os.path.join(scriptpath,"glider_guns-master", "fixed")
vargunfolder = os.path.join(scriptpath,"glider_guns-master", "variable")
readmefolder = os.path.join(scriptpath,"glider_guns-master")

if not os.path.exists(outfolder): os.makedirs(outfolder)
if not os.path.exists(LHoutfolder): os.makedirs(LHoutfolder)

onlyfiles = [f for f in listdir(infolder) if isfile(os.path.join(infolder, f))]
baseguns=dict()
for file in onlyfiles:
  name, dx, dy, offset = file[:-4].split(",")  # remove '.rle'
  baseguns[name]=[g.load(os.path.join(infolder, file)),int(dx), int(dy), int(offset)]
specialguns=dict()
specialfiles = [f for f in listdir(specialfolder) if isfile(os.path.join(specialfolder, f))]
for file in specialfiles:  # these are not adjustable guns and are saved in final form,
                           # so no need for dx, dy, or offset
  name, dx, dy, offset = file[:-4].split(",")  # remove '.rle'
  specialguns[name]=[g.load(os.path.join(specialfolder, file)),int(dx), int(dy), int(offset)]
g.addlayer()

with open(os.path.join(readmefolder, "README"), "r") as f:
  readme = f.readlines()
  
gunlistbegin, gunlistend = 0,0
for i in range(len(readme)):
  if readme[i]=="Gun List\n":
    gunlistbegin=i+2
예제 #7
0
Brle = Srle = "b10$b10$b26$b10$b10$b26$b10$b10$b!"
for ch in Bvalues:
    ind = 32 - int(ch) * 4  # because B and S values are highest at the top!
    Brle = Brle[:ind] + "o" + Brle[ind + 1:]
for ch in Svalues:
    ind = 32 - int(ch) * 4
    Srle = Srle[:ind] + "o" + Srle[ind + 1:]
RuleBits = pattern(Brle, 148, 1404) + pattern(Srle, 162, 1406)

# load or generate the OFFcell tile:
OFFcellFileName = g.getdir("data") + "metapixel-OFF.rle"
ONcellFileName = g.getdir("data") + "metapixel-ON.rle"
if os.access(OFFcellFileName, os.R_OK) and os.access(ONcellFileName, os.R_OK):
    g.show("Opening metapixel-OFF and metapixel-ON from saved pattern file.")
    OFFcell = pattern(g.transform(g.load(OFFcellFileName), -5, -5, 1, 0, 0, 1))
    ONcell = pattern(g.transform(g.load(ONcellFileName), -5, -5, 1, 0, 0, 1))

else:
    g.show("Building OFF metacell definition...")
    # slide #21: programmables --------------------

    LWSS = pattern("b4o$o3bo$4bo$o2bo!", 8, 0)

    DiagProximityFuse = pattern(
        """
    bo$obo$bo2$4b2o$4b2o$59b2o$59b2o3$58b2o2b2o$9b2o3bo5bo5bo5bo5bo5bo5bo
    7b2o2b2o$9bo3bobo3bobo3bobo3bobo3bobo3bobo3bobo$10bo2bo2bo2bo2bo2bo2bo
    2bo2bo2bo2bo2bo2bo2bo2bo$11bobo3bobo3bobo3bobo3bobo3bobo3bobo3bo5b2o$
    12bo5bo5bo5bo5bo5bo5bo5bo3bobo$55bo2bo$56bobo$57bo!
    """, -5, -5)
예제 #8
0
def load(fn):
   # note that top left cell of bounding box will be at 0,0
   return pattern(golly.load(fn))
예제 #9
0
def load(fn):
    # note that top left cell of bounding box will be at 0,0
    return pattern(golly.load(fn))