Exemple #1
0
def main():

    g.setstep(0)
    g.setalgo('QuickLife')

    velocity = g.getstring('Please specify velocity', '(2,1)c/6')
    a, b, p = parse_velocity(velocity)
    params = partial_derivatives(a, b, p)

    dvdx = params['dvdx']
    dudx = params['dudx']
    dvdy = params['dvdy']
    dudy = params['dudy']
    dvdt = params['dvdt']
    dudt = params['dudt']

    cells = []

    for t in xrange(p):

        things = g.getcells(g.getrect())
        things = zip(things[::2], things[1::2])
        cells += [(dudx * x + dudy * y + dudt * t,
                   dvdx * x + dvdy * y + dvdt * t) for (x, y) in things]
        g.step()

    g.setlayer(g.addlayer())
    g.putcells([x for y in cells for x in y])
def GunArea(cells, curGunPeriod):

	maxBox = [10000, 10000, -1000, -1000]
	
	for i in xrange(0, curGunPeriod, 4):
		
		g.new(str(i))
		g.putcells(g.evolve(cells, i))
		
		g.setbase(8)
		g.setstep(3)
		g.step()
		g.step()
		g.step()
		g.step()
		
		
		edgeGlider = EdgeGlider()

		while PerformDelete(edgeGlider, curGunPeriod):
			edgeGlider = DevolveGlider(edgeGlider, curGunPeriod)
		
		for j in xrange(0, 4):
			maxBox = AppendBox(maxBox, g.getrect())
			g.run(1)
		
		if i == 0:
			somegun = g.getcells(g.getrect())
		
	return [BoxValue(maxBox), somegun, maxBox]
def GunArea(cells, curGunPeriod):

	maxBox = []
	minpop = -100000
	
	for i in xrange(0, curGunPeriod, 4):
		
		g.new(str(i))
		g.putcells(g.evolve(cells, i))
		
		g.setbase(8)
		g.setstep(3)
		g.step()
		g.step()
		
		edgeGlider = EdgeGlider()

		while PerformDelete(edgeGlider, curGunPeriod):
			edgeGlider = DevolveGlider(edgeGlider, curGunPeriod)
		
		for j in xrange(0, 4):
		
			if g.getpop() > minpop:
				maxpop = g.getpop()
				maxpopgun = g.getcells(g.getrect())
				
			maxBox = AppendBox(maxBox, g.getrect())
			g.run(1)
		
	return [BoxValue(maxBox), maxpopgun, maxBox]
Exemple #4
0
def gofast(newgen, delay):
    ''' Fast goto '''
    #Save current settings
    oldbase = g.getbase()
    # oldhash = g.setoption("hashing", True)

    g.show('gofast running, hit escape to abort')
    oldsecs = time()

    #Advance by binary powers, to maximize advantage of hashing
    g.setbase(2)
    for i, b in enumerate(intbits(newgen)):
        if b:
            g.setstep(i)
            g.step()
            g.dokey(g.getkey())
            newsecs = time()
            if newsecs - oldsecs >= delay:  # do an update every sec
                oldsecs = newsecs
                g.update()
            if g.empty():
                break

    g.show('')

    #Restore settings
    # g.setoption("hashing", oldhash)
    g.setbase(oldbase)
Exemple #5
0
def goto(newgen, delay):
    g.show("goto running, hit escape to abort...")
    oldsecs = time()

    # before stepping we advance by 1 generation, for two reasons:
    # 1. if we're at the starting gen then the *current* step size
    #    will be saved (and restored upon Reset/Undo) rather than a
    #    possibly very large step size
    # 2. it increases the chances the user will see updates and so
    #    get some idea of how long the script will take to finish
    #    (otherwise if the base is 10 and a gen like 1,000,000,000
    #    is given then only a single step() of 10^9 would be done)
    if delay <= 1.0:
        g.run(1)
        newgen -= 1

    # use fast stepping (thanks to PM 2Ring)
    for i, d in enumerate(intbase(newgen, g.getbase())):
        if d > 0:
            g.setstep(i)
            for j in range(d):
                if g.empty():
                    g.show("Pattern is empty.")
                    return
                g.step()
                newsecs = time()
                if newsecs - oldsecs >= delay:  # time to do an update?
                    oldsecs = newsecs
                    g.update()
    g.show("")
Exemple #6
0
def goto(newgen, delay):
   g.show("goto running, hit escape to abort...")
   oldsecs = time()
   
   # before stepping we advance by 1 generation, for two reasons:
   # 1. if we're at the starting gen then the *current* step size
   #    will be saved (and restored upon Reset/Undo) rather than a
   #    possibly very large step size
   # 2. it increases the chances the user will see updates and so
   #    get some idea of how long the script will take to finish
   #    (otherwise if the base is 10 and a gen like 1,000,000,000
   #    is given then only a single step() of 10^9 would be done)
   if delay <= 1.0:
     g.run(1)
     newgen -= 1
   
   # use fast stepping (thanks to PM 2Ring)
   for i, d in enumerate(intbase(newgen, g.getbase())):
      if d > 0:
         g.setstep(i)
         for j in xrange(d):
            if g.empty():
               g.show("Pattern is empty.")
               return
            g.step()
            newsecs = time()
            if newsecs - oldsecs >= delay:  # time to do an update?
               oldsecs = newsecs
               g.update()
   g.show("")
Exemple #7
0
def gofast(newgen, delay):
   ''' Fast goto '''
   #Save current settings
   oldbase = g.getbase()
   # oldhash = g.setoption("hashing", True)
   
   g.show('gofast running, hit escape to abort')
   oldsecs = time()
   
   #Advance by binary powers, to maximize advantage of hashing
   g.setbase(2)
   for i, b in enumerate(intbits(newgen)):
      if b:
         g.setstep(i)
         g.step()
         g.dokey(g.getkey())
         newsecs = time()
         if newsecs - oldsecs >= delay:  # do an update every sec
            oldsecs = newsecs
            g.update()
         if   g.empty():
            break
   
   g.show('')
   
   #Restore settings
   # g.setoption("hashing", oldhash)
   g.setbase(oldbase)
def GotoLimited(gen, power):
	g.setbase(8)
	g.setstep(power)

	while gen > int(g.getgen()) + g.getbase()**power:
		g.step()
		g.update()
		
	goto(gen)
Exemple #9
0
def GotoLimited(gen, power):
    g.setbase(8)
    g.setstep(power)

    while gen > int(g.getgen()) + g.getbase()**power:
        g.step()
        g.update()

    goto(gen)
Exemple #10
0
def EvolveRecipe(recipe):
	g.new("")
	g.setstep(3)
	
	g.putcells(blck)
	
	for r in recipe:
		g.putcells(gld, 40, 40 + r)
		g.step()
		g.step()
Exemple #11
0
def main():
    #Vertical distance between pixels. Maybe get this from user. minimum = 16
    pdy = 16

    #Generate & display a dot matrix printer from current selection
    dmprinter(pdy, copies=1)

    golly.setcursor("Zoom In")
    golly.setalgo("HashLife")
    golly.setbase(2)
    golly.setstep(6)
Exemple #12
0
def goto(newgen):
    currgen = int(g.getgen())

    if newgen < currgen:
        # try to go back to starting gen (not necessarily 0) and
        # then forwards to newgen; note that reset() also restores
        # algorithm and/or rule, so too bad if user changed those
        # after the starting info was saved;
        # first save current location and scale
        midx, midy = g.getpos()
        mag = g.getmag()
        g.reset()
        # restore location and scale
        g.setpos(midx, midy)
        g.setmag(mag)
        # current gen might be > 0 if user loaded a pattern file
        # that set the gen count
        currgen = int(g.getgen())
        if newgen < currgen:
            g.error("Can't go back any further; pattern was saved " +
                    "at generation " + str(currgen) + ".")
            return
    if newgen == currgen: return

    oldsecs = time()

    # before stepping we advance by 1 generation, for two reasons:
    # 1. if we're at the starting gen then the *current* step size
    #    will be saved (and restored upon Reset/Undo) rather than a
    #    possibly very large step size
    # 2. it increases the chances the user will see updates and so
    #    get some idea of how long the script will take to finish
    #    (otherwise if the base is 10 and a gen like 1,000,000,000
    #    is given then only a single step() of 10^9 would be done)
    g.run(1)
    currgen += 1

    # use fast stepping (thanks to PM 2Ring)
    oldstep = g.getstep()
    for i, d in enumerate(intbase(newgen - currgen, g.getbase())):
        if d > 0:
            g.setstep(i)
            for j in xrange(d):
                if g.empty():
                    g.show("Pattern is empty.")
                    return
                g.step()
                newsecs = time()
                if newsecs - oldsecs >= 1.0:  # do an update every sec
                    oldsecs = newsecs
                    g.update()
    g.setstep(oldstep)
Exemple #13
0
def goto(newgen):
    currgen = int(g.getgen())
    
    if newgen < currgen:
        # try to go back to starting gen (not necessarily 0) and
        # then forwards to newgen; note that reset() also restores
        # algorithm and/or rule, so too bad if user changed those
        # after the starting info was saved;
        # first save current location and scale
        midx, midy = g.getpos()
        mag = g.getmag()
        g.reset()
        # restore location and scale
        g.setpos(midx, midy)
        g.setmag(mag)
        # current gen might be > 0 if user loaded a pattern file
        # that set the gen count
        currgen = int(g.getgen())
        if newgen < currgen:
            g.error("Can't go back any further; pattern was saved " +
                    "at generation " + str(currgen) + ".")
            return
    if newgen == currgen: return

    oldsecs = time()

    # before stepping we advance by 1 generation, for two reasons:
    # 1. if we're at the starting gen then the *current* step size
    #    will be saved (and restored upon Reset/Undo) rather than a
    #    possibly very large step size
    # 2. it increases the chances the user will see updates and so
    #    get some idea of how long the script will take to finish
    #    (otherwise if the base is 10 and a gen like 1,000,000,000
    #    is given then only a single step() of 10^9 would be done)
    g.run(1)
    currgen += 1

    # use fast stepping (thanks to PM 2Ring)
    oldstep = g.getstep()
    for i, d in enumerate(intbase(newgen - currgen, g.getbase())):
        if d > 0:
            g.setstep(i)
            for j in xrange(d):
                if g.empty():
                    g.show("Pattern is empty.")
                    return
                g.step()
                newsecs = time()
                if newsecs - oldsecs >= 1.0:  # do an update every sec
                    oldsecs = newsecs
                    g.update()
    g.setstep(oldstep)
Exemple #14
0
def AdaptiveGoto(hwssRecipe, enablePrinting=True):

    #g.setrule("LifeHistory")
    fense50 = g.parse(
        "F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F!"
    )

    helixD = CalcHelix(hwssRecipe)

    curgen = -helixD * 2
    curgen += 2 * distForward

    goto(curgen)
    g.setbase(8)
    g.setstep(3)

    delta = 10
    lastmaxi = delta
    idx = 0

    for i in hwssRecipe:

        if enablePrinting and (100 * (idx + 1)) / len(hwssRecipe) != (
                100 * idx) / len(hwssRecipe):
            percent = (100 * (idx + 1)) / len(hwssRecipe)
            g.update()

            g.show("Iterating forward progress " + str(percent) + "%")

        curgen += 2 * distForward
        idx += 1

        while int(g.getgen()) < curgen:
            g.step()

        if i == 'SKIP':
            continue

        if i > lastmaxi:

            g.select([fenseX, helixD + fenseY + lastmaxi - delta, 1, delta])
            g.clear(0)
            lastmaxi += delta
            #g.update()

        if i < lastmaxi - delta:
            g.putcells(fense50, fenseX, helixD + fenseY + lastmaxi - 2 * delta)
            lastmaxi -= delta
Exemple #15
0
def Validate(recipe):

    g.new("")
    g.setstep(3)

    g.putcells(block_cells)

    for r in recipe:
        g.putcells(glider_cells, 120, 120 + r)
        #g.putcells(glider_cells, 80, 80 + 2 - r )
        g.step()
        g.step()

    rect = g.getrect()

    return rect
def LeftMost(recipe):

	g.new("")
	g.setstep(3)
	
	g.putcells(block_cells)
	
	for r in recipe:
		#g.putcells(glider_cells, 80, 80 + r )
		g.putcells(glider_cells, 80, 80 + 2 - r )
		g.step()
		g.step()
		
	rect = g.getrect()
	
	return rect[0]
Exemple #17
0
def LeftMost(recipe):

    g.new("")
    g.setstep(3)

    g.putcells(block_cells)

    for r in recipe:
        #g.putcells(glider_cells, 80, 80 + r )
        g.putcells(glider_cells, 80, 80 + 2 - r)
        g.step()
        g.step()

    rect = g.getrect()

    return rect[0]
def Validate(recipe):

	g.new("")
	g.setstep(3)
	
	g.putcells(block_cells)
	
	for r in recipe:
		g.putcells(glider_cells, 120, 120 + r)
		#g.putcells(glider_cells, 80, 80 + 2 - r )
		g.step()
		g.step()
		
	rect = g.getrect()
	
	return rect
Exemple #19
0
def EvolveRecipe(recipe):
	g.new("")
	g.setstep(3)
	
	g.putcells(blck)
	
	minx = g.getrect()[0]
	
	for r in recipe:
		g.putcells(gld, 40, 40 + r)
		g.step()
		g.step()
		
		if minx > g.getrect()[0]:
			minx > g.getrect()[0]
	
	return minx
def AdaptiveGoto(hwssRecipe, enablePrinting = True):

	#g.setrule("LifeHistory")
	fense50 = g.parse("F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F!")

	helixD = CalcHelix(hwssRecipe)
		
	curgen = -helixD * 2
	curgen += 2 * distForward
	
	goto(curgen)
	g.setbase(8)
	g.setstep(3)
	
	delta = 10
	lastmaxi = delta
	idx = 0
	
	for i in hwssRecipe:
		
		if enablePrinting and (100 * (idx + 1)) / len(hwssRecipe) != (100 * idx) / len(hwssRecipe):
			percent = (100 * (idx + 1)) / len(hwssRecipe)
			g.update()
			
			g.show("Iterating forward progress " + str(percent) + "%")
			
		curgen += 2 * distForward
		idx += 1
		
		while int(g.getgen()) < curgen:
			g.step()
			
		if i == 'SKIP':
			continue 
			
		if i > lastmaxi:
			
			g.select([fenseX, helixD + fenseY + lastmaxi - delta, 1, delta])
			g.clear(0)
			lastmaxi += delta
			#g.update()
			
		if i < lastmaxi - delta:
			g.putcells(fense50, fenseX, helixD + fenseY + lastmaxi - 2 * delta)
			lastmaxi -= delta
Exemple #21
0
def find_all_glider_idx(mask):
   
   idxs = extract_indexes(mask)
   idxs.sort(key=lambda idx: (1.01 * gliders_in[idx][0] + gliders_in[idx][1]))
   copy_idxs = idxs[:]

   for edge_i in enum_shooters(mask):
      reaction_cells = shoot_defs[edge_i][4]
      stable_cells = shoot_defs[edge_i][5]

      for g_i in list(copy_idxs):
      
         g.new("")
 
         for g_j in idxs:
            x, y, idx = gliders_in[g_j]
            if g_j == g_i:
               g.putcells(g.evolve(reaction_cells, idx), x, y)
            else:
               g.putcells(g.evolve(gld, idx), x - 128, y + 128)

         g.setbase(8)
         g.setstep(3)
         g.step()
         
         x, y, _ = gliders_in[g_i]

         # test if the pattern consists of the stable cells plus the
         # necessary gliders and nothing else

         g.putcells(stable_cells, x, y, 1, 0, 0, 1, "xor")

         if int(g.getpop()) != 5 * len(idxs):
            continue

         for g_j in idxs:
               x, y, idx = gliders_in[g_j]
               g.putcells(g.evolve(gld, idx), x, y, 1, 0, 0, 1, "xor")

         if g.empty():
            copy_idxs.remove(g_i)
            yield g_i,edge_i
def PeriodCalculator():
	
	g.setbase(8)
	g.setstep(3)
	g.step()
	g.step()

	cells = g.getrect()
	
	rect = g.getrect()
	cells = g.getcells(rect)
	
	for i in xrange(0, 10000):
		g.run(1)
		if str(g.getcells(rect)) == str(cells):
			#g.show(str(i + 1))
			#g.reset
			return i + 1
	
	return -1
Exemple #23
0
def golly_lhistory():

    ngens = int(g.getstring('How many generations to run the pattern?', '1'))

    d = threes_and_fours(0)

    g.setstep(0)
    for i in range(ngens):
        g.step()
        d.update(threes_and_fours(i + 1))

    exes = [k[0] for k in d]
    whys = [k[1] for k in d]
    zeds = [k[2] for k in d]

    minx = min(exes)
    maxx = max(exes)
    miny = min(whys)
    maxy = max(whys)

    width = (maxx - minx) + 10
    height = maxy - miny

    g.addlayer()
    g.setrule('Grills')

    for (k, v) in d.iteritems():

        x = (k[0] - minx) + (k[2] * width)
        y = k[1] - miny
        c = {3: LIVE_VARIABLE_STATE, 4: DEAD_VARIABLE_STATE}[v]
        g.setcell(x, y, c)

    for i in range(1, max(zeds) + 1):
        for j in range(height + 1):
            g.setcell(i * width - 5, j, VERTICAL_LINE_STATE)

    for i in range(max(zeds) + 1):
        g.setcell(i * width + 3, -3, ORIGIN_STATE)
        g.setcell(i * width + 3, -4, ZEROTH_GENERATION_STATE + i)
def FinadOptimalRecipe(slv, idx):
	moveTable = slv.SLsMoveTable[idx]
	bests = [-1, -1]
	slCount = [1000, 1000]
	
	g.setrule("B3/S23")
	g.setalgo("HashLife")
	
	for i in xrange(0, len(moveTable)):
		g.new("")
		
		slv.ApplyRecipeSmart(i, idx)
		slv.PlaceRecipe()
		
		g.setstep(5)
		g.step()
		
		numSL = len(CountSL())
		laneID = (moveTable[i][1] + 10000) % 2
		
		if slCount[laneID] > numSL:
			slCount[laneID] = numSL
			bests[laneID] = i
		
		slv.Reset()
		
	g.setrule("LifeHistory")
	
	for i in xrange(0, len(bests)):
		slv.ApplyRecipeSmart(bests[i], idx)
		slv.PlaceRecipe(i * 100, 0, i == 0)
		slv.Reset()
	
	g.show(str(bests))
	#11 - [32, 249]
	#12 - [138, 123]
	#13 - [29, 27]
	#14 - [89, 15]
	return bests
def AdaptiveGoto(hwssRecipe):

	#g.setrule("LifeHistory")
	fense50 = g.parse("F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F!")

	helixD = -step * len(hwssRecipe) - 1000
		
	while helixD % 7500 != 0:
		helixD -= 1
	
	curgen = -helixD * 2
	curgen += 2 * distForward
	goto(curgen)
	g.setstep(3)
	
	delta = 10
	lastmaxi = delta
	
	for i in hwssRecipe:
		curgen += 2 * distForward
		
		while int(g.getgen()) < curgen:
			g.step()
		
	
		if i == 'SKIP':
			continue 
			
		if i > lastmaxi:
			
			g.select([240, helixD + fenseY + lastmaxi - delta, 1, delta])
			g.clear(0)
			lastmaxi += delta
			#g.update()
			
		if i < lastmaxi - delta:
			g.putcells(fense50, 240, helixD + fenseY + lastmaxi - 2 * delta)
			lastmaxi -= delta
Exemple #26
0
def AdaptiveGoto(hwssRecipe):

	#g.setrule("LifeHistory")
	fense50 = g.parse("F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F!")

	helixD = -step * len(hwssRecipe) - 1000
		
	while helixD % 7500 != 0:
		helixD -= 1
	
	curgen = -helixD * 2
	curgen += 2 * distForward
	goto(curgen)
	g.setstep(3)
	
	delta = 10
	lastmaxi = delta
	
	for i in hwssRecipe:
		curgen += 2 * distForward
		
		while int(g.getgen()) < curgen:
			g.step()
		
	
		if i == 'SKIP':
			continue 
			
		if i > lastmaxi:
			
			g.select([240, helixD + fenseY + lastmaxi - delta, 1, delta])
			g.clear(0)
			lastmaxi += delta
			#g.update()
			
		if i < lastmaxi - delta:
			g.putcells(fense50, 240, helixD + fenseY + lastmaxi - 2 * delta)
			lastmaxi -= delta
Exemple #27
0
def main():

    g.setstep(0)
    g.setalgo('QuickLife')

    velocity = g.getstring('Please specify velocity', '(2,1)c/6')
    a, b, p = parse_velocity(velocity)
    params = partial_derivatives(a, b, p)

    dvdy = params['dvdy']
    dudy = params['dudy']
    dvdt = params['dvdt']

    cells = g.getcells(g.getrect())
    cells = zip(cells[::2], cells[1::2])
    gcells = []

    for (u, v) in cells:
        for t in xrange(p):
            xp = dvdy * u - dudy * v - a * t
            yq = v - t * dvdt
            if (xp % p != 0):
                continue
            if (yq % dvdy != 0):
                continue
            x = xp // p
            y = yq // dvdy
            gcells.append((t, x, y))

    spacing = max([x for (_, x, _) in gcells]) - min([x for (_, x, _) in gcells])
    spacing += 10

    gcells = [(x + spacing * t, y) for (t, x, y) in gcells]

    g.setlayer(g.addlayer())
    g.putcells([x for y in gcells for x in y])
    g.fit()
	def CanApplyRecipe(self, recipe, expected):
		g.new("")
		g.setstep(3)
		
		g.putcells(blck)
		g.putcells(self.init)
		
		for r in self.recipe:
			g.putcells(gld, 80, 80 + r)
			g.step()
		
		g.select([self.block0[0], self.block0[1], 2, 2])
		g.clear(0)
		cells = g.getcells(g.getrect())
		g.putcells(blck, self.block0[0], self.block0[1])
		delta = self.block0[1] - self.block0[0]
		
		for r in recipe:
			g.putcells(gld, 80, 80 + r + delta)
			g.step()
		
		for i in xrange(0, len(cells), 2):
			x = cells[i]
			y = cells[i + 1]
			
			if g.getcell(x, y) == 0:
				return False
				
		for i in xrange(0, len(expected), 2):
		
			x = expected[i] + self.block0[0]
			y = expected[i + 1] + self.block0[1]
			
			if g.getcell(x, y) == 0:
				return False
				
		return True
Exemple #29
0
if attempt_id is None and os.getenv("LIFEBOX_DEBUG") is not None:
    attempt_id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeffffff"

BASE_RESULTS_PATH = os.path.join(os.sep, "tmp", attempt_id)

if not os.path.exists(BASE_RESULTS_PATH):
    os.makedirs(BASE_RESULTS_PATH)

RESULTS_FN = os.path.join(BASE_RESULTS_PATH, "results.log")
open(RESULTS_FN,"a").write("Opening up MC file..\n")

g.open("adventure_lifebooox.mc")
g.setrule('Varlife')
g.show("Starting....")
g.update()
g.setstep(6)
start_time = time.time()

open(RESULTS_FN,"a").write("BOOTING..\n")

PATTERN_FN = os.path.join(BASE_RESULTS_PATH, "pattern.dat")
results = add_data(PATTERN_FN)
open(RESULTS_FN,"a").write(results + "\n")

boot_completed = False

for x in range(0, 40):

    g.run(1000000)

    end_time = time.time() - start_time
for j in xrange(selheight):
   for i in xrange(selwidth):
      golly.show("Placing (" + str(i+1) + "," + str(j+1) + ") tile" +
                 " in a " + str(selwidth) + " by " + str(selheight) + " rectangle.")
      if livecell[i][j]:
         ONcell.put(2048 * i - 5, 2048 * j - 5)
      else:
         OFFcell.put(2048 * i - 5, 2048 * j - 5)
      g.fit()
   
g.show("")
g.setalgo("HashLife")               # no point running a metapattern without hashing
g.setoption("hyperspeed", False)    # avoid going too fast
g.setbase(8)
g.setstep(4)
g.step()                            # save start and populate hash tables

# g.run(35328) # run one full cycle (can lock up Golly if construction has failed)
#
# Note that the first cycle is abnormal, since it does not advance the metapattern by
# one metageneration:  the first set of communication signals to adjacent cells is 
# generated during this first cycle.  Thus at the end of 35328 ticks, the pattern
# is ready to start its first "normal" metageneration (where cell states may change).
#
# It should be possible to define a version of ONcell that is not fully populated
# with LWSSs and HWSSs until the end of the first full cycle.  This would be much
# quicker to generate from a script definition, and so it wouldn't be necessary to
# save it to a file.  The only disadvantage is that ONcells would be visually
# indistinguishable from OFFcells until after the initial construction phase.
    90,
    116,
    90,
    113,
    90
]  # 7move-29 -- widen the space between the two elbows
# The final number in each recipe below represents the amount of time that must elapse
#     before another recipe can be safely appended.
# To string recipes together, remove all leading "0"s except for the first, and
#     remove the final number from the last recipe to avoid a pi explosion at the end
#     (or append the elbowdestroy recipe to delete the elbow block completely).

g.addlayer()
g.setrule("LifeHistory")
g.putcells(g.transform(elbow, -5, -2))
g.setstep(4)
g.fit()
g.setmag(1)
makerecipe(recipe)
"""
# Sample recipes from slmake repository:  https://gitlab.com/apgoucher/slmake/blob/master/data/simeks/pp.txt

recipe = [0, 109, 90, 93, 91, 90, 90, 90, 90]    # elbowdestroy

# elbow duplicators
recipe = [0, 109, 91, 93, 91, 127, 91, 90, 145, 91, 90, 90, 146, 90, 91, 91, 92, 90]    # 7move9 7move-7
recipe = [0, 109, 90, 93, 91, 91, 90, 90, 100, 90, 90, 146, 96, 90, 90, 90, 92, 156, 144, 90]    # 7move19 0move-12
recipe = [0, 109, 91, 94, 91, 91, 128, 126, 90, 152, 91, 176, 125, 90, 90, 90, 91, 90, 90, 108, 90, 99, 90]    # 0move-4 0move-30
recipe = [0, 109, 91, 94, 91, 91, 128, 126, 90, 152, 91, 176, 125, 90, 90, 90, 91, 90, 90, 108, 90, 109, 90]    # 0move-4 7move-33
recipe = [0, 109, 90, 93, 91, 90, 95, 90, 90, 91, 90, 91, 90, 147, 90, 151, 126, 90, 107, 90, 111, 90, 99, 90]    # 0move-18 7move-37
recipe = [0, 109, 91, 93, 91, 156, 91, 91, 126, 90, 91, 91, 91, 147, 90, 122, 95, 91, 91, 90, 119, 91, 112, 90]    # 7move3 0move-28
Exemple #32
0
# use same file name as in goto.lua
GotoINIFileName = g.getdir("data") + "goto.ini"
previousgen = ""
try:
    f = open(GotoINIFileName, 'r')
    previousgen = f.readline()
    f.close()
    if not validint(previousgen):
        previousgen = ""
except:
    # should only happen 1st time (GotoINIFileName doesn't exist)
    pass

gen = g.getstring("Enter the desired generation number,\n" +
                  "or -n/+n to go back/forwards by n:",
                  previousgen, "Go to generation")
if len(gen) == 0:
    g.exit()
elif gen == "+" or gen == "-":
    # clear the default
    savegen(GotoINIFileName, "")
elif not validint(gen):
    g.exit('Sorry, but "' + gen + '" is not a valid integer.')
else:
    # best to save given gen now in case user aborts script
    savegen(GotoINIFileName, gen)
    oldstep = g.getstep()
    goto(gen.replace(",",""))
    g.setstep(oldstep)
Exemple #33
0
# use same file name as in goto.pl
GotoINIFileName = g.getdir("data") + "goto.ini"
previousgen = ""
try:
    f = open(GotoINIFileName, 'r')
    previousgen = f.readline()
    f.close()
    if not validint(previousgen):
        previousgen = ""
except:
    # should only happen 1st time (GotoINIFileName doesn't exist)
    pass

gen = g.getstring(
    "Enter the desired generation number,\n" +
    "or -n/+n to go back/forwards by n:", previousgen, "Go to generation")
if len(gen) == 0:
    g.exit()
elif gen == "+" or gen == "-":
    # clear the default
    savegen(GotoINIFileName, "")
elif not validint(gen):
    g.exit('Sorry, but "' + gen + '" is not a valid integer.')
else:
    # best to save given gen now in case user aborts script
    savegen(GotoINIFileName, gen)
    oldstep = g.getstep()
    goto(gen.replace(",", ""))
    g.setstep(oldstep)
Exemple #34
0
def FindAllHs(cells, minx):
	g.new("")
	g.putcells(cells)
	rect = g.getrect()
	
	min = 10000
	max = -10000
	
	for i in xrange(1, len(cells), 2):
		cx = cells[i - 1]
		cy = cells[i]
		
		dx = 40 - cx
		cy += dx
		
		if cy < min:
			min = cy
		
		if cy > max:
			max = cy
		
	answer = [[],[]] 
	
	if (min - 9) % 2 != 0:
		min += 1
		
	for i in xrange(min - 9 - 40, max + 6 - 40, 2):
		g.new("")
		g.putcells(cells)
		g.putcells(gld, 40, 40 + i)
		g.setstep(3)
		g.step()
		g.step()
		
		if int(g.getpop()) > 60:
			continue 
			
		if int(g.getpop()) == 0:
			continue 
		
		if g.getrect()[0] < -120:
			continue 
		
		edgeType = HasEdgeShooter(minx)
		
		if edgeType != False:
			answer[0].append([i, 0, 0, [edgeType]])
			
		rect = g.getrect()
		
		if rect[2] > 12 or rect[3] > 12:
			continue
		
		s = str(g.getcells(g.getrect()))
		g.run(2)
		
		if s == str(g.getcells(g.getrect())):
			
			key = str(rect) + ":" + str(g.getpop())
			
			if not (key in existingKeys):
				existingDic[key] = []
				existingKeys.append(key)
				
			if s in existingDic[key]:
				continue 
			else:
				existingDic[key].append(s)
		
			answer[1].append(i)
			
	return answer 
Exemple #35
0
    if parts[1] == "ZZ":
        parts = [parts[0], "Z", parts[2], parts[3]]
    actions = parts[3].split(", ")
    for j in actions:
        if j != "":
            g.putcells(splitter, -182 - outputdict[j] * 64 + i * 64,
                       167 + outputdict[j] * 64 + i * 64)
    nextstate = parts[2]
    if nextstate != "":
        offset = statedict[nextstate]
        g.putcells(transrefl,
                   -150 - len(outputlist) * 64 + i * 64 - offset * 16,
                   165 + len(outputlist) * 64 + i * 64 + offset * 16)

    # keep track of the placement of the first reflector, needed to place pattern correctly relative to GPC
    if firstreflx == -1:
        firstreflx = -150 - len(outputlist) * 64 + i * 64 - offset * 16
        firstrefly = 165 + len(outputlist) * 64 + i * 64 + offset * 16

g.putcells(ZNZbackstop, -49 + numstates * 64, -11 + numstates * 64)
g.fit()

if GPClayer != -1:
    calcpat = g.getcells(g.getrect())
    g.setlayer(GPClayer)
    g.putcells(
        calcpat, 77924 - firstreflx, 38284 - firstrefly
    )  # this is the location of the key first reflector in calculator, in the GPC
    if g.getname()[:6] == "GPC-2^":
        g.setstep(int(g.getname()[6:8]))
def main ():
  g.update ()
  g.check (False)

  path = g.getstring ("Output directory:")
  files = glob.glob (os.path.join (path, "*.out"))

  mingls = g.getstring ("Min number of gliders at accept:")
  if mingls == "":
    mingl = 0
    minpop = 0
    maxpop = 1024
  else:
    mingl = int (mingls)
    minpops = g.getstring ("Min population except catalyzers:")
    if minpops == "":
      minpop = 0
      maxpop = 1024
    else:
      minpop = int (minpops)
      maxpop = int (g.getstring ("Max population except catalyzers:"))

  if g.getname () != "catbellman_temp":
    g.addlayer ()

  hashdir = {}
  catlist = []
  catix = 0

  g.new ("catbellman_temp")
  g.setrule ("LifeBellman")

  for fix, filename in enumerate (files):
    patt = g.getrect ()
    if patt != []:
      g.select (patt)
      g.clear (0)
  
    g.setgen ("0")
	
    with open(filename, 'r') as f:
      filetext = f.read ()
      if fix % 16 == 0:
        g.show ("Analysing " + str (fix) + "/" + str (len (files)))
		
      (gogen, glcnt) = convbellman (filetext, 0, 0)
      if gogen == -1:
	    gogen = 128
	  
      (use, hash) = analyse (gogen, glcnt, minpop, maxpop, mingl)

      if use:
        if not hash in hashdir:
          catlist.append ([])
          hashdir [hash] = catix
          catix += 1

        cat = hashdir [hash]
        catlist [cat].append (filetext)

  g.new ("catbellman_temp")
  g.setrule ("LifeBellman")

  fix = 0
  y = 0
  for cat in catlist:
    x = 96 * (len (cat) - 1)
    for filetext in cat:
      convbellman (filetext, x, y)
      x -= 96
      fix += 1
      if fix % 32 == 0:
        g.show ("Rendering " + str (fix) + "/" + str (len (files)))
        g.fit ()
        g.check (True)
        g.update ()
        g.check (False)

    y += 96

  g.show ("Done")
  g.fit ()
  g.setstep (-1)
  g.check (True)
Exemple #37
0
def FindAllHs(cells):
	g.new("")
	g.putcells(cells)
	rect = g.getrect()
	
	
	min = 10000
	max = -10000
	
	for i in xrange(1, len(cells), 2):
		cx = cells[i - 1]
		cy = cells[i]
		
		dx = 40 - cx
		cy += dx
		
		if cy < min:
			min = cy
		
		if cy > max:
			max = cy
		
	answer = [[],[]] 
	
	if (min - 9) % 2 != 0:
		min += 1
		
	for i in xrange(min - 9 - 40, max + 6 - 40, 2):
		g.new("")
		g.putcells(cells)
		g.putcells(gld, 40, 40 + i)
		g.setstep(3)
		g.step()
		g.step()
		
		if int(g.getpop()) > 80 or int(g.getpop()) == 0:
			continue 
		
		if g.getrect()[0] < -120:
			continue 
		
		rect = g.getrect()
		
		if rect[2] > 25 or rect[3] > 25:
			continue
		
		s = str(g.getcells(g.getrect()))
		g.run(1)
		
		if s == str(g.getcells(g.getrect())):
			
			key = str(rect) + ":" + str(g.getpop())
			
			SLs = []
			
			if rect[2] < 8 and rect[3] < 8:
				SLs = CountSL()
			
			if len(SLs) == 1: 
				SLs[0].sort(key=lambda r: 100000 * r[1] + r[0])
				
				x1 = SLs[0][0][0]
				y1 = SLs[0][0][1]
				
				for o in xrange(0, len(SLs[0])):
					SLs[0][o][0] -= x1
					SLs[0][o][1] -= y1

				answer[0].append([i, x1, y1, SLs[0]])
			
			if not (key in existingKeys):
				existingDic[key] = []
				existingKeys.append(key)
				
			if s in existingDic[key]:
				continue 
			else:
				existingDic[key].append(s)
		
			answer[1].append(i)
			
	return answer 
# Slow glider page, for Mozilla CA presentation

import golly as g
from glife.base import glider, flip_x
import time

# Conway's Life
g.setrule("B3/S23")

glider.display("Slow Glider", x=-20, y=20, A = flip_x)
g.setpos('0', '0')
g.setoption('fullscreen', True)
g.setstep(0)

while True:
    time.sleep(.5)
    g.step()
    g.update()