コード例 #1
0
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]
コード例 #2
0
ファイル: golly2ikpx.py プロジェクト: AlexGreason/iqpx
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])
コード例 #3
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)
コード例 #4
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("")
コード例 #5
0
ファイル: goto_expression.py プロジェクト: Nesk8er/WebLife1
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("")
コード例 #6
0
ファイル: goto_expression.py プロジェクト: Nesk8er/WebLife1
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)
コード例 #7
0
ファイル: evolveMovingCells.py プロジェクト: 7yl4r/LifeGenes
    def __init__(self):
        logging.info('script started')
        lg_envmt = lifegenes_environment()
        lg_envmt.drawColor()
        logging.info('setup complete; beginning evolution cycles')
        try:
            while(True):    #until stopped by golly
                g.show('cells moving')
                for i in range(5): # rounds of cell movement
                    #logging.debug('movement round '+str(i))
                    lg_envmt.cellMotions()
                    #logging.debug('cells moved')
                    lg_envmt.drawColor()
                    #logging.debug('cells recolored')
                    g.update()
                    #logging.debug('golly updated')
                    #time.sleep(1)

                g.show('cells evolving')
                # one round of evolution:
                #logging.debug('evolution round started')
                g.step()
                #g.update()
                #logging.debug('golly evolution complete')
                lg_envmt.update()
                #logging.debug('cellList updated')
                lg_envmt.drawColor()
                #logging.debug('cells recolored')
                g.update()
                #logging.debug('golly updated')
                #time.sleep(1)
        finally:
                logging.info('cycling halted from external source (probably golly)')
                g.show('closing gracefully, hold on just a sec...')
                lg_envmt.teardown()
コード例 #8
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)
コード例 #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)
コード例 #10
0
ファイル: GlueMonochromaticP1.py プロジェクト: simsim314/Glue
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()
コード例 #11
0
ファイル: gotoAPI.py プロジェクト: simsim314/Caterloopilar
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)
コード例 #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)
コード例 #13
0
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]
コード例 #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
コード例 #15
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]
コード例 #16
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
コード例 #17
0
	def __init__(self):
		logging.info('script started')
		lg_envmt = lifegenes_environment()
		lg_envmt.drawColor()
		logging.info('setup complete; beginning evolution cycles')
		try:
			while(True):	#until stopped by golly
				g.step()
				#g.update()
				lg_envmt.update()
				lg_envmt.drawColor()
				g.update()
		finally:
				logging.info('cycling halted from external source (probably golly)')
				g.show('closing gracefully, hold on just a sec...')
				lg_envmt.teardown()
コード例 #18
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]
コード例 #19
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
コード例 #20
0
ファイル: WSSSearch.py プロジェクト: simsim314/Glue
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
コード例 #21
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
コード例 #22
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
コード例 #23
0
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
コード例 #24
0
ファイル: grills.py プロジェクト: AlexGreason/iqpx
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)
コード例 #25
0
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
コード例 #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
コード例 #27
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
コード例 #28
0
def get_pop(numsteps=44100, x=256, y=256):
    if numsteps < 1:
        g.exit("numsteps must be greater than 0.")

    randfill(x, y)

    poplist = [int(g.getpop())]
    extinction = sys.maxint

    rule = g.getrule()
    oldsecs = time.time()
    for i in xrange(numsteps - 1):
        if g.empty():
            extinction = int(g.getgen())
            break
        g.step()
        poplist.append(int(g.getpop()))
        newsecs = time.time()
        if newsecs - oldsecs >= 1.0:
            oldsecs = newsecs
            g.show("Rule {}, Step {} of {}".format(rule, i + 1, numsteps))

    return (poplist, extinction)
コード例 #29
0
	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
コード例 #30
0
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.
コード例 #31
0
ファイル: WSSSearch.py プロジェクト: simsim314/Glue
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 
コード例 #32
0
import golly
s = golly.getstring('rules split by ";"', golly.getclipstr())
rs = [x for x in s.split(';') if x]
# golly.setrule(rs[0]);
L = len(rs)
for i in range(100):
    # golly.run(1)
    golly.step()
    golly.setrule(rs[i % L])
コード例 #33
0
ファイル: stress_test.py プロジェクト: 7yl4r/LifeGenes
    def __init__(self):
        try:
            g.show('setting up test')


            testSize = 100 #this is the size of one side of the square testing area
            g.select([-testSize/2,-testSize/2,testSize,testSize])
            #clear the canvas
            g.clear(1)
            g.clear(0)
            g.randfill(50)
            g.update()

            g.show('stressTest started')

            startTime = time()
            lg_envmt = lifegenes_environment()
            endTime = time()
            logging.debug('\tsetup t\t=\t\t'+str(endTime-startTime))
            g.update()

            startTime = time()
            lg_envmt.drawColor()
            endTime = time()
            logging.debug('\tcolorDraw t\t=\t' + str( endTime - startTime))
            g.update()
            
            startTime = time()
            lg_envmt.cellMotions()
            endTime = time()
            logging.debug('\tmovement t\t=\t' + str( endTime - startTime))
            g.update()

            startTime = time()
            lg_envmt.drawColor()
            endTime = time()
            logging.debug('\tcolor update t \t= ' + str( endTime - startTime))
            g.update()

            g.step()

            startTime = time()
            lg_envmt.update()
            endTime = time()
            logging.debug('\tevolve update t\t= ' + str( endTime - startTime))

            startTime = time()
            lg_envmt.cellMotions()
            endTime = time()
            logging.debug('\tmovement t\t=\t' + str( endTime - startTime))
            g.update()

            startTime = time()
            lg_envmt.drawColor()
            endTime = time()
            logging.debug('\tcolor update t\t= ' + str( endTime - startTime))
            g.update()



            g.update()
            g.show('test complete')
        finally:
                logging.info('cycling halted from external source (probably golly)')
コード例 #34
0
#!/usr/bin/env python2.6

# Q: http://www.hacker.org/challenge/chal.php?id=117
# A: http://www.hacker.org/challenge/chal.php?answer=821%2C319&id=117&go=Submit

# Use Golly, a Game of Life simulator. It can be shown that after 1500 generations, the populations are always 116. So only need to search the first 1500 generations to find the max population.

import golly as g

GENERATION_NUM = 1500

max_population = -1
best_generation = -1

for generation in range(GENERATION_NUM):
    population = int(g.getpop())
    if population > max_population:
        max_population = population
        best_generation = generation
    
    g.step()

g.note('%d,%d' % (best_generation, max_population))
コード例 #35
0
ファイル: GlueMonochromaticP1.py プロジェクト: simsim314/Glue
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 
コード例 #36
0
        left = -int(tilewd / 2)
        top = -int(tilewd / 2)
        boxsel = [-int(tilewd / 2), -int(tilewd / 2), tilewd, tilewd]
        tileit(i, tilewd)
        wd = tilewd * pbox.wd
        ht = tilewd * pbox.ht
        boxsel = [-int(wd / 2), -int(wd / 2), wd, ht]
        randfill_mash(boxsel, density)

        poplist = [int(yfunc())]
        genlist = [int(xfunc())]
        xlimlist = [int(g.getrect()[1])]
        oldsecs = time()
        for i in xrange(numsteps):

            g.step()
            poplist.append(int(yfunc()))
            genlist.append(int(xfunc()))
            newsecs = time()
            if newsecs - oldsecs >= 1.0:  # show pattern every second
                oldsecs = newsecs
                fit_if_not_visible()
                g.update()
            g.show("Step %i of %i, Topo %i" % (i + 1, numsteps, posi))

            event = g.getevent()
            if event.startswith("key"):
                evt, ch, mods = event.split()
                if ch == "q":
                    out = 1
                    numsteps = i
コード例 #37
0
# MAIN
logging.info('script started')
nruns = 10

print 'testing environment...'
from LifeGenes.lifegenes_core.environment import environment as lifegenes_environment
lg_envmt = lifegenes_environment()
testNames = list()
testTimes = list()

g.getcellsconfig = 'const growing'
g.generation = 0
print 'testing drawColor for constantly growing cell list'
testNames.append('drawColor')
testTimes.append( timedRuns(lg_envmt.drawColor,nruns,lambda:[g.step(),lg_envmt.update()]) )
#wait()

g.getcellsconfig = 'const growing'
g.generation = 0 
print 'testing update() for constantly growing cell list'
testNames.append('update()')
testTimes.append( timedRuns(lg_envmt.update,nruns,g.step) )
#wait()

g.getcellsconfig = 'const growing'
g.generation = 0 
print 'testing cellMotions() for constantly growing cell list'
testNames.append('cellMotions()')
testTimes.append( timedRuns(lg_envmt.cellMotions,nruns,lambda:[g.step(),lg_envmt.update()]) )
#wait()
コード例 #38
0
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.