示例#1
0
	def __init__(self, shift):
	
		self.dup_br = Duplicator(rle_BR_sl, (99, 180), (76, 155))
		self.dup_tr = Duplicator(rle_TR_sl, (243, 303), (215, 273))
		self.dup_bl = Duplicator(rle_BL_sl, (163, 112), (140, 87))
		self.dup_tl = Duplicator(rle_TL_sl, (283,184), (78, -23))
		self.top_blocks = g.parse(cblocks_top, 139 + 10, -204 - 10)
		self.bottom_blocks = g.parse(cblocks_top, 83 + 139, 102-204)
		self.shift = shift 
示例#2
0
def MakeForwardSalvo(distance, dx, dy, helixSLdy, toPlaceHelixSL = False, toPlaceFirstSL = False):

   frontHelixSL = g.parse("6bo$5bobo$5bobo$6bo2$b2o7b2o$o2bo5bo2bo$b2o7b2o2$6bo$5bobo$5bobo$6bo!", 0, 0)
   frontHelixSL2GliderWSS = g.parse("2b3o$bo2bo$4bo$o3bo$4bo$bobo!", 7, 16)
   frontHelixReflect = g.parse("8b3o$7bo2bo$10bo$10bo$7bobo2$3o$o2bo$o$o3bo$o$bobo!", 54, 71)
   frontHelixGlider2SL = g.parse("bo$3o$ob2o$b3o$b3o$b2o!", 5, 123)

   frontErasingReflectorWSS = g.parse("28bo$27b3o$26b2obo$26b3o$27b2o23$5bo$4b3o$3b2obo$3b3o$4b2o5$2bo$b3o$2obo$3o$b2o!", 68, 172)
   frontSL = g.parse("bo$obo$o2bo$b2o!", 132, 314)
   frontFrontPart = g.parse("2b3o$2bo2bo$2bo$2bo3bo$2bo$3bobo24$20bo$19b3o$19bob2o$20b3o$20b3o$20b2o35$4b3o$3bo2bo$6bo$2bo3bo$6bo$3bobo8$22b3o$22bo2bo$22bo$22bo$23bobo17$29bo$28b3o$28bob2o$29b3o$29b2o6$bo$3o$ob2o$b3o$b2o!", 122, 287)
   frontReflectingPart = g.parse("2bo$b3o$2obo$3o$3o$b2o2$12b3o$12bo2bo$12bo$12bo3bo$12bo$13bobo12$17b3o$16bo2bo$19bo$15bo3bo$19bo$16bobo!", 80, 464)
   frontBackPart = g.parse("11b3o$11bo2bo$11bo$11bo3bo$11bo$12bobo4$3o$o2bo$o$o3bo$o3bo$o$bobo!", 132, 556)
  
   d = (distance - 98) / 2
   
   if toPlaceHelixSL:
	g.putcells(frontHelixSL, -d + dx, -d + dy + helixSLdy)
   
   g.putcells(frontHelixSL2GliderWSS, -d + dx, -d + dy)
   g.putcells(frontHelixReflect, dx, dy)
   g.putcells(frontHelixGlider2SL, -d + dx, d + dy)
   g.putcells(frontErasingReflectorWSS, dx, dy)

   g.putcells(frontFrontPart, d + dx, d + dy)
   g.putcells(frontReflectingPart, 0 + dx, 2 * d + dy)
   g.putcells(frontBackPart, d + dx, 3 * d + dy)
   
   if toPlaceFirstSL:
	g.putcells(frontSL, d + dx, d + dy + helixSLdy)
示例#3
0
def MakeBackwardSalvo(distance, dx, dy, helixSLdy, toPlaceHelixSL = False, toPlaceFirstSL = False):
   
   backHelixSL = g.parse("bo$obo$obo$bo!", 201, 1083)
   backHelixSL2GliderWSS = g.parse("bobo$o$o3bo$o$o2bo$3o!", 196, 1076)
   backHelixReflect = g.parse("b2o$b3o$ob2o$3o$bo16$2bobo$bo$bo3bo$bo$bo2bo$b3o!", 131, 853)
   backHelixGlider2SL = g.parse("bobo$4bo$o3bo$4bo$bo2bo$2b3o!", 200, 635)

   backErasingReflectorWSS = g.parse("bobo$o$o3bo$o$o2bo$3o73$23bobo$26bo$22bo3bo$26bo$23bo2bo$24b3o69$42bobo$45bo$41bo3bo$45bo$42bo2bo$43b3o!", 63, 641)
   backSL = g.parse("b2o$o2bo$obo$bo!", 6, 629)
   backFrontPart = g.parse("bobo$o$o$o2bo$3o42$65bobo$64bo$64bo3bo$64bo$64bo2bo$64b3o23$59bobo$58bo$58bo$58bo2bo$58b3o35$51b2o$51b3o$50bob2o$50b3o$51bo6$31bobo$30bo$30bo3bo$30bo$30bo2bo$30b3o10$24b2o$24b3o$23bob2o$23b3o$24bo64$43b2o$42b3o$42b3o$42b2obo$43b3o$44bo10$52b2o$51b3o$51b3o$51b2obo$52b3o$53bo!", -30, 387)
   backReflectingPart = g.parse("36bobo$39bo$39bo$36bo2bo$37b3o11$b2o$3o$2obo$b3o$2bo14$9bobo$12bo$12bo$9bo2bo$10b3o!", 67, 257)
   backBackPart = g.parse("b2o$3o$2obo$b3o$2bo!", 2, 0)
   
   d = (distance - 144) / 2
   
   if toPlaceHelixSL:
	g.putcells(backHelixSL, d + dx, d * 3 + dy + helixSLdy)
   
   g.putcells(backHelixSL2GliderWSS, d + dx, d * 3 + dy)
   g.putcells(backHelixReflect, dx, dy)
   g.putcells(backHelixGlider2SL, d + dx, -d * 3 + dy)
   g.putcells(backErasingReflectorWSS,dx, dy)
   g.putcells(backFrontPart, -d + dx, -d + dy)
   g.putcells(backReflectingPart, 0 + dx, -4 * d + dy)
   g.putcells(backBackPart, -d + dx, -d * 7 + dy)
   
   if toPlaceFirstSL:
	g.putcells(backSL, -d + dx, -d + dy)
示例#4
0
def SaveWss(file):

	g.setrule("b3/s23")
	wss = [g.parse("bobo$4bo$o3bo$o3bo$4bo$bo2bo$2b3o!"), g.parse("bobo$4bo$o3bo$4bo$bo2bo$2b3o!"), g.parse("obo$3bo$3bo$o2bo$b3o!")]

	wssList = []
	for w in wss:
		for i in xrange(0, 4):
			wssList.append(PrepareList(g.evolve(w, i)))
			wssList.append(PrepareList(g.transform(g.evolve(w, i), 0, 0, 1, 0, 0, -1)))
	
	pickle.dump(wssList, open(path.join(g.getdir("data"),file), "wb"))
示例#5
0
   def __init__(self, P = [], x0 = 0, y0 = 0, A = identity):
      """\
Initialize a pattern from argument P.
P may be another pattern, a cell list, or a multi-line string.
A cell list should look like [x1, y1, x2, y2, ...];
a string may be in one of the two autodetected formats:
'visual' or 'RLE'.
o  'visual' format means that the pattern is represented
   in a visual way using symbols '*' (on cell), '.' (off cell)
   and '\\n' (newline), just like in Life 1.05 format.
   (Note that an empty line should contain at least one dot).
o  'RLE' format means that a string is Run-Length Encoded.
   The format uses 'o' for on-cells, 'b' for off-cells and
   '$' for newlines.
   Moreover, any of these symbols may be prefixed by a number,
   to denote that symbol repeated that number of times.

When P is a string, an optional transformation
(x0, y0, A) may be specified.
"""
      self.__phases = dict()

      if type(P) == list:
         list.__init__(self, P)
      elif type(P) == pattern:
         list.__init__(self, list(P))
      elif type(P) == str:
         list.__init__(self, golly.parse(P, x0, y0, *A))
      else:
         raise TypeError("list or string is required here")
      self.__phases[0] = self
示例#6
0
    def __init__(self, P = [], x0 = 0, y0 = 0, A = identity):
        """\
  Initialize a pattern from argument P.
  P may be another pattern, a cell list, or a multi-line string.
  A cell list should look like [x1, y1, x2, y2, ...];
  a string may be in one of the two autodetected formats:
  'visual' or 'RLE'.
  o  'visual' format means that the pattern is represented
     in a visual way using symbols '*' (on cell), '.' (off cell)
     and '\\n' (newline), just like in Life 1.05 format.
     (Note that an empty line should contain at least one dot).
  o  'RLE' format means that a string is Run-Length Encoded.
     The format uses 'o' for on-cells, 'b' for off-cells and
     '$' for newlines.
     Moreover, any of these symbols may be prefixed by a number,
     to denote that symbol repeated that number of times.

  When P is a string, an optional transformation
  (x0, y0, A) may be specified.
  """
        self.__phases = dict()

        if type(P) == list:
            list.__init__(self, P)
        elif type(P) == pattern:
            list.__init__(self, list(P))
        elif type(P) == str:
            list.__init__(self, golly.parse(P, x0, y0, *A))
        else:
            raise TypeError("list or string is required here")
        self.__phases[0] = self
示例#7
0
def reconstruct(gstr, stepback=2):
    """Reconstruct a pattern representing a glider set from its (canonical)
    string. The transformation is assumed to be the identity. Returns a single
    Golly cell list with all gliders at <stepback> gen prior to canonical time.
    """
    fields, at, trans_str = gstr.partition("@")
    res = []
    glider = g.parse("bo$2bo$3o") # SE
    # Process transformation
    # XXX unimplemented (but not required here)
    t, o, shift_x, shift_y = 0, "identity", 0, 0
    # Step back to separate gliders (same as Shinjuku uses for realising syntheses)
    t += stepback
    # Process glider sets
    for i, field in enumerate(gstr.split("/")):
        salvo = []
        for (time, lane) in zip(*[iter(field.split())] * 2):
            time, lane = - int(time) - t - 4, int(lane)
            dist, time = time // 4, time % 4
            salvo += g.evolve(g.transform(glider, dist, dist - lane), time)
        if   i == 1: salvo = g.transform(salvo, 0, 0, r270[0], r270[1], r270[2], r270[3]) # "rot270"
        elif i == 2: salvo = g.transform(salvo, 0, 0, r180[0], r180[1], r180[2], r180[3]) # "rot180"
        elif i == 3: salvo = g.transform(salvo, 0, 0, r90[0], r90[1], r90[2], r90[3]) # "rot90"
        res += salvo
    return g.transform(res, shift_x, shift_y)
示例#8
0
	def __init__(self, inshift):
	
		self.dup_br = Duplicator(rle_BR_sl, (99, 180), (76, 155))
		self.dup_tr = Duplicator(rle_TR_sl, (243, 303), (215, 273))
		self.dup_bl = Duplicator(rle_BL_sl, (163, 112), (140, 87))
		self.dup_tl = Duplicator(rle_TL_sl, (283,184), (78, -23))
		self.construction = g.parse(cblocks, 139, -204)
		self.shift = inshift
示例#9
0
def SaveWss(file):

    g.setrule("b3/s23")
    wss = [
        g.parse("bobo$4bo$o3bo$o3bo$4bo$bo2bo$2b3o!"),
        g.parse("bobo$4bo$o3bo$4bo$bo2bo$2b3o!"),
        g.parse("obo$3bo$3bo$o2bo$b3o!")
    ]

    wssList = []
    for w in wss:
        for i in xrange(0, 4):
            wssList.append(PrepareList(g.evolve(w, i)))
            wssList.append(
                PrepareList(g.transform(g.evolve(w, i), 0, 0, 1, 0, 0, -1)))

    pickle.dump(wssList, open(path.join(g.getdir("data"), file), "wb"))
def NewLogicalPatternRLE(rle, diff, inputs, outputs, period):
	result = LogicPattern()
	x, y = diff
	result.cells = g.parse(rle, x, y)
	result.inputs = inputs
	result.outputs = outputs
	result.period = period 
	
	return result
示例#11
0
def NewLogicalPatternRLE(rle, diff, inputs, outputs, period):
    result = LogicPattern()
    x, y = diff
    result.cells = g.parse(rle, x, y)
    result.inputs = inputs
    result.outputs = outputs
    result.period = period

    return result
示例#12
0
def MakeForwardRecipe(helixSLdy, distance, dx, dy, recipe): 
	d = (distance - 98) / 2

	frontSL = g.parse("bo$obo$o2bo$b2o!", 132 + d + dx, 314 + d + dy)
	curd = helixSLdy + distance

	for r in recipe: 
	  if r != 'SKIP':	
		g.putcells(frontSL, 0, curd + r)

	  curd += distance
def fill_void():
    # sample incremental 46P4H1V0 synthesis
    pat = g.parse(
        """1422bo$1422bobo$1422b2o6$1217bo$1218bo191bo$1216b3o141bo50b2o$1226bo
133bobo47b2o$1226bobo127bo3b2o$1226b2o53bo75b2o37bobo29bobo$1276bobo2b
obo72b2o39b2o15bo13b2o$1277b2o2b2o70bo43bo14bobo14bo$1277bo73bobo59b2o
$1343bo8b2o53bo11bo$1284bo57bobo3bo57bobo3bo5bobo$642bo517bo123bo58b2o
3bo39bobo16b2o3bo5b2o16bobo$62bo13bo54bo510bobo513bobo123bo63bo40b2o6b
o14bo16bo6b2o$60bobo13bobo52bobo3bobo365bo132bo3b2o397bo117b2o3bo224bo
5bobo31bobo5bo$61b2o13b2o53b2o4b2o43bobo133bo58bo125bobo133b2o81bobo
119bo68bo127bobo108b2o8b2o52b2o7b2o44b3o6b2o7b2o53b2o7b2o41b2o10b2o7b
2o10b2o$138bo44b2o133bobo57b2o124b2o68bo63b2o82b2o118bobo66b2o128b2o
57bo50bobo9b2o50bobo7bobo45bo5bobo7bobo51bobo7bobo51bobo7bobo$140bo42b
o13bo63bo56b2o5bo51b2o10bo63bo63bo54bobo6bo63bo63bo13bo49bo63bo5b2o56b
o10b2o51bo63bo63bo6bobo48bo5bo57bo5bo5bo44bo6bo5bo5bo51bo5bo5bo51bo5bo
5bo$o60b3o11b3o53bo3bo3b2o45bobo7bobo61bobo53bo7bobo61bobo61bobo61bobo
54b2o5bobo61bobo61bobo7bobo51bobo61bobo7bo53bobo61bobo61bobo61bobo5b2o
48b2o4bobo55b2o4bobo4b2o49b2o4bobo4b2o49b2o4bobo4b2o49b2o4bobo4b2o$b2o
60bo11bo54bobobobo2bobo45b2o7bobo61bobo51bobo7bobo53b2o6bobo61bobo61bo
bo61bobo61bobo61bobo7b2o52bobo61bobo7bobo51bobo6b2o53bobo61bobo61bobo
61bobo61bobo61bobo61bobo61bobo$2o60bo13bo54b2ob2o51bo7b2ob2o59b2ob2o
51b2o6b2ob2o51bo2bo4b2ob2o59b2ob2o59b2ob2o54bo4b2ob2o59b2ob2o59b2ob2o
7bo51b2ob2o59b2ob2o6b2o51b2ob2o4bo2bo51b2ob2o54bo4b2ob2o54bo4b2ob2o4bo
54b2ob2o59b2ob2o59b2ob2o59b2ob2o59b2ob2o$257bo7bo55bo7bo50b2o3bo7bo55b
o7bo55bo7bo51bobobo7bo52bo2bo7bo55bo63bo7bo55bo7bo55bo7bo3b2o50bo7bo
51bobobo7bo51bobobo7bobobo48bo2bo7bo2bo42bo6bo2bo7bo2bo6bo42bo2bo7bo2b
o49bo2bo7bo2bo49bo2bo7bo2bo$6bo42b2o5bo25bo5b2o39b4ob4o45bo9b4ob4o55b
4ob4o55b4ob4o45bo9b4ob4o55b4ob4o55b4ob4o52b2ob4ob4o52b7ob4o55b4ob4o9bo
45b4ob4o55b4ob4o55b4ob4o9bo45b4ob4o52b2ob4ob4o52b2ob4ob4ob2o49b7ob7o
40bobo6b7ob7o6bobo40b7ob7o49b7ob7o49b7ob7o$6bobo39bobo6bo9bo3bo9bo6bob
o38bo2bobo2bo46bo8bo2bobo2bo58bobo61bobo49b2o10bobo61bobo61bobo61bobo
61bobo61bobo2bo8bo49bobo61bobo61bobo10b2o49bobo61bobo61bobo61bobo47b2o
12bobo12b2o47bobo61bobo41bo19bobo19bo$2bo3b2o42bo4b3o8bobobobo8b3o4bo
41bobobobo45b3o3bo5bobobobo56b2obobob2o55b2obobob2o45b2o2b3o3b2obobob
2o53b4obobob2o53b4obobob2o52b5obobob2o52b5obobob2o55b2obobobo5bo3b3o
42b4obobob2o53b4obobob2o53b4obobob2o3b3o2b2o43b4obobob4o50b5obobob4o
50b5obobob5o49b5obobob5o44b2o3b5obobob5o3b2o40b2o2b5obobob5o2b2o41b2o
2b5obobob5o2b2o31b2o8b2o2b5obobob5o2b2o8b2o$3b2o62b2ob2o59b2ob2o53bo5b
2ob2o57bob2ob2obo55bob2ob2obo51bo3bob2ob2obo52bo2bob2ob2obo52bo2bob2ob
2obo52bo2bob2ob2obo52bo2bob2ob2obo55bob2ob2o5bo48bo2bob2ob2obo52bo2bob
2ob2obo52bo2bob2ob2obo3bo48bo2bob2ob2obo2bo49bo2bob2ob2obo2bo49bo2bob
2ob2obo2bo49bo2bob2ob2obo2bo43bobo3bo2bob2ob2obo2bo3bobo39b2o2bo2bob2o
b2obo2bo2b2o41b2o2bo2bob2ob2obo2bo2b2o30bobo8b2o2bo2bob2ob2obo2bo2b2o
8bobo$2b2o183b3o182b3o5bo65b2o61bobo205b3o46b2o62b2o62b2o14bo5b3o38bob
o11b2o62bobo172bo21bo$54b3o25b3o289bo67bo67bo405bo41bo17bo59bo$56bo25b
o105bo184bo8b2o59b2o273bo188b2o8bo56b2o$55bo27bo103b2o65b2o121b2o2bo2b
o57b2o8b2o264b2o59b2o125bo2bo2b2o51b2o8b2o$187bobo59b3ob2o121bobo2bo2b
o63bo2b2o50b2o212bobo60b2ob3o120bo2bo2bobo51b2o2bo71b2o$194b2o55bo3bo
122bo3b2o64b2o3bo50b2o205b2o66bo3bo123b2o3bo52bo3b2o70b2o$194bobo53bo
196bobo53bo3b2o201bobo71bo184bobo66b2o3bo348b3o21b3o13b3o$194bo245b3o
56b2o5b2o204bo263b3o60b2o5b2o346bo6b2o13bo7b2o6bo$442bo57b2o6bo467bo
61bo6b2o346bo8b2o8b2o3bo5b2o8bo$441bo57bo477bo69bo353bo9bobo11bo$443b
3o527b3o437bo$443bo531bo$444bo529bo!""")
    g.putcells(pat)
示例#14
0
 def construct(self):
     g.new('')
     g.setrule("LifeHistory")
     events = sorted(self.timeline, reverse=True)
     time = -240 * 20
     nextrow = time + 240
     top_y = 0
     for y in range(60):
         g.setcell(self.left, y, 6)
         g.setcell(self.right, y, 6)
     rephasing = [0] * len(self.columns)
     while events:
         if events[-1][0] < nextrow:
             t, c = events.pop()
             g.run(t-time)
             time = t
             x, y, excess = self.columns[c]
             #place bhep, reflecting in the odd columns
             g.putcells(self.b_hep,
                        x + (c%2),
                        rephasing[c] + y,
                        -1 if (c%2) else 1)
             #add blocks to absorb excess gliders
             for i in range(excess):
                 g.putcells(self.absorber,
                            x + (c%2),
                            rephasing[c] + y - 31 * i,
                            -1 if (c%2) else 1)
                 
             rephasing[c] += 31 - 9
         else:
             for x, y, _ in self.columns:
                 g.putcells(g.parse("2o$2o!", x, 2*top_y+y))
                 g.putcells(g.parse("2o$2o!", x, 2*top_y-31+y))
             for _ in range(31):
                 top_y -= 1
                 g.setcell(self.left, top_y, 6)
                 g.setcell(self.right, top_y, 6)
             g.run(nextrow-time)
             time = nextrow
             nextrow += 240
示例#15
0
	def __init__(self, path = None, SLpaths = None, SLExpected = None):
		self.blockX = 0
		self.blockY = 0
		self.sequence = []
		self.recipe = []
		self.block0 = [0,0]
		self.block1 = [0,0]
		self.splitterData1 = [[-4, -14],[-8,7],[12,5],  g.parse("5$22b2o$22b2o$2b2o$2b2o!", -10, 0)]
		self.splitterData2 = [[5, 15],[7,-8],[5,12], g.parse("2$7b2o$7b2o19$5b2o$5b2o!", 0, -10)]
		self.recipeIdxList = []
		self.lastGotoIdx = -1 
		self.SLsMoveTable = []
		self.SLsExpected = SLExpected
		self.init = g.getcells(g.getrect())
		
		if path != None:
			self.moveTable = self.LoadMoveTable(path, True)
		
		if SLpaths != None:
			for pt in SLpaths:
				self.SLsMoveTable.append(self.LoadMoveTable(pt, False))
示例#16
0
def MakeBackwardRecipe(distance, dx, dy, recipe): 
   d = (distance - 144) / 2
   backSL = g.parse("b2o$o2bo$obo$bo!", 6 - d + dx, 629 - d + dy)
   curd = distance + 2
   
   recipe.insert(0, -4)
   
   for r in recipe: 
   	  if r != 'SKIP':	
		g.putcells(backSL, 0, curd - r)

   	  curd += distance
示例#17
0
def writepatdef(patname, pat):
    with open(libpath + basename + ".rle", "r") as libfile:
        rle = libfile.readlines()
    rlestring = ""
    for line in rle:
        if line[:1] in ['#', 'x', 'm']: continue
        rlestring += line[:-1]
    x, y = findTL(g.parse(rlestring))
    f = open(scriptFN, 'a')
    f.write(patname + " = pattern(g.parse('" + rlestring + "'," + str(-x) +
            "," + str(-y) + "))\n")
    f.close()
	def __init__(self):
		self.signalsFullData = []
		self.signals = []
		
		self.components =  [g.parse("bo$2bo$3o!", -1, -1)]

		for idx in xrange(0, len(self.components)):
			comp = self.components[idx]
			
			for i in xrange(-1, 2, 2):
				for j in xrange(-1, 2, 2):
					for k in xrange(0, 4):
						self.signalsFullData.append((g.transform(g.evolve(comp, k), 0, 0, i, 0, 0, j), i, j, k, idx))
						self.signals.append(g.transform(g.evolve(comp, k), 0, 0, i, 0, 0, j))
示例#19
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
示例#20
0
    def __init__(self):
        self.signalsFullData = []
        self.signals = []

        self.components = [g.parse("bo$2bo$3o!", -1, -1)]

        for idx in xrange(0, len(self.components)):
            comp = self.components[idx]

            for i in xrange(-1, 2, 2):
                for j in xrange(-1, 2, 2):
                    for k in xrange(0, 4):
                        self.signalsFullData.append(
                            (g.transform(g.evolve(comp, k), 0, 0, i, 0, 0,
                                         j), i, j, k, idx))
                        self.signals.append(
                            g.transform(g.evolve(comp, k), 0, 0, i, 0, 0, j))
示例#21
0
def run_pattern_in_golly(pattern, comments, extended):
    if extended:
        try:
            extended = int(pattern[pattern.index('%')+1:])
        except ValueError: #sometimes there's a % sign in the comments
            extended = False
    pattern_rle = pattern
    pattern = g.parse(pattern)
    if len(pattern) % 2 == 1: #multistate rule for some reason
        g.warn(pattern_rle)
        g.warn(str(pattern))
    initial_pattern = pattern.copy()
    xs = pattern[::2]
    ys = pattern[1::2]
    min_x = 0
    max_x = max(xs)
    min_y = 0
    max_y = max(ys)
    min_min_x = min_x #these four are the permanent minima and maxima, used for determining maximum pattern size
    max_max_x = max_x
    min_min_y = min_y
    max_max_y = max_y
    for period in range(1, 1000): #maximum oscillator period
        if period == 999 and extended:
            pattern = g.evolve(pattern, extended - 999)
        pattern = g.evolve(pattern,1)
        if not pattern:
            g.warn('Not an oscillator, dies out completely: %s' % initial_pattern)
            return
        xs = pattern[::2]
        ys = pattern[1::2]
        min_min_x = min(min_min_x, min(xs)) #sets new absolute minima and maxima
        max_max_x = max(max_max_x, max(xs))
        min_min_y = min(min_min_y, min(ys))
        max_max_y = max(max_max_y, max(ys))
        if pattern == initial_pattern:
            if extended:
                return (comments + convert_grid_to_rle(pattern), extended, max_max_x-min_min_x+1, max_max_y-min_min_y+1, -min_min_x, -min_min_y)
            else:
                return (comments + convert_grid_to_rle(pattern), period, max_max_x-min_min_x+1, max_max_y-min_min_y+1, -min_min_x, -min_min_y)
            #0: RLE. 1: period. 2, 3: maximum bounding box for x and y. 4, 5: Greatest negative for calculating offset.
        #if extended == 'file': #one at a time
        #    return pattern
    g.warn('Not an oscillator, maximum generations reached: %s' % initial_pattern)
    return
示例#22
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
def run_patt(known_cells):
    global patt_count, meth_count
    g.new("PlutoniumSearch")
    g.reset()
    g.update()
    patt_count += 1
    #patt = g.parse(known_cells + "!")
    patt = g.parse(known_cells[1:] + "!")
    #g.note(known_cells[1:] + "!")
    g.putcells(patt)
    g.update()
    hashlist = {}
    for gene in range(999):
        if g.empty():
            break
        if g.hash(g.getrect()) in hashlist:
            p = int(g.getgen()) - hashlist[g.hash(g.getrect())]
            if not p in boring_periods:
                g.reset()
                g.save("p" + str(p) + "_" + str(cnt[p]) + ".rle", "rle")
                cnt[p] += 1
            break
        else:
            hashlist[g.hash(g.getrect())] = int(g.getgen())
            g.run(1)
        """
		except:
			# Pattern dies
			if int(g.getgen()) > min_lifespan:
				meth_count += 1
				newlifespan = int(g.getgen())
				g.new("Saving methuselah")
				g.putcells(patt)
				try:
					g.save("diehard-" + str(newlifespan) + ".rle", "rle")
				except:
					pass
				g.update()
				#max_final_pop = newpop
			break"""
    #g.warn(str(hashlist))
    g.show(str(patt_count) + "/" + str(2**(bx * by)))
示例#24
0
文件: sss.py 项目: apaap/sssss
def canon5Sship(ship, maxgen=2000):
    minpop, rulestr, dx, dy, period, shiprle = ship
    shipPatt = g.parse(shiprle)
    # Transform ship to canonical direction
    if abs(dx) >= abs(dy):
        a, b, c, d = sign(dx), 0, 0, sign(dy)
    else:
        a, b, c, d = 0, sign(dy), sign(dx), 0
    dy, dx = minmaxofabs((dx, dy))
    shipPatt = g.transform(shipPatt, 0, 0, a, b, c, d)
    # Clear the layer and place the ship
    r = g.getrect()
    if r:
        g.select(r)
        g.clear(0)
    g.putcells(shipPatt)
    shiprle = giveRLE(g.getcells(g.getrect()))
    g.setrule(rulestr)
    # Determine the minimal isotropic rule
    setminisorule(period)
    return minpop, g.getrule(), dx, dy, period, shiprle
示例#25
0
def convert_rle_to_grid(rle):
    comments = ''
    rle = rle.replace('rule = b3/s23', 'rule = B3/S23')
    if 'rule = B3/S23' in rle:
        comments = rle[:rle.index('x =')]
        rle = rle[rle.index('rule = B3/S23')+13:] #starts after the dimension and rule identifiers
    else:
        show_message('"rule = B3/S23 not in RLE": ' + rle,0.5)
        return {}
    pattern = {}
    rle_decoded = g.parse(rle)
    for i in range(len(rle_decoded)):
        if i % 2:
            continue
        pattern[(rle_decoded[i],rle_decoded[i+1])] = 1
    max_x = max(rle_decoded[::2])
    max_y = max(rle_decoded[1::2])
    for i in range(max_x+1):
        for j in range(max_y+1):
            pattern[(i,j)] = pattern.get((i,j), 0)
    return (pattern, comments)
示例#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
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
文件: elbow.py 项目: ceebo/elbow
LANE1 = -5
LANE2 = 5
FULL_DEPTH = 4
CLEANUP_DEPTH = 1
MAX_POP = [40, 40, 40, 40, 30, 30, 30, 30]

GENS = 200
MAX_DIFF = 60

OUTFILE = '/home/user/life/outfile%d.txt' % time()

def to_pairs(cells):
    return zip(cells[::2], cells[1::2])

G_NE = g.parse('3o$2bo$bo!')
G_NW = g.parse('3o$o$bo!')
G_SW = g.transform(g.parse('bo$o$3o!'), 0, -2)
G_SE = g.transform(g.parse('bo$2bo$3o!'), -2, -2)

LWSS_W = g.transform(g.parse('bo2bo$o$o3bo$4o!'), 0, -1)
LWSS_S = g.transform(g.parse('bobo$o$o$o2bo$3o!'), -2, -4)

GLIDERS_SW = [to_pairs(g.evolve(G_SW, i)) for i in range(4)]
GLIDERS_SE = [to_pairs(g.evolve(G_SE, i)) for i in range(4)]
GLIDERS_NW = [to_pairs(g.evolve(G_NW, i)) for i in range(4)]
LWSSES_W = [to_pairs(g.evolve(LWSS_W, i)) for i in range(4)]
LWSSES_S = [to_pairs(g.evolve(LWSS_S, i)) for i in range(4)]

assert(all((0,0) in gl for gl in GLIDERS_SW))
assert(all((0,0) in gl for gl in GLIDERS_SE))
示例#29
0
文件: elbow0.py 项目: ceebo/elbow
LANE2 = 0
FULL_DEPTH = 4
CLEANUP_DEPTH = 1
MAX_POP = [40, 40, 40, 40, 30, 30, 30, 30]

GENS = 200
MAX_DIFF = 72

OUTFILE = "/home/user/life/elbow_0hd_%d.txt" % time()


def to_pairs(cells):
    return zip(cells[::2], cells[1::2])


G_NE = g.parse("3o$2bo$bo!")
G_NW = g.parse("3o$o$bo!")
G_SW = g.transform(g.parse("bo$o$3o!"), 0, -2)
G_SE = g.transform(g.parse("bo$2bo$3o!"), -2, -2)

LWSS_W = g.transform(g.parse("bo2bo$o$o3bo$4o!"), 0, -1)
LWSS_S = g.transform(g.parse("bobo$o$o$o2bo$3o!"), -2, -4)

GLIDERS_SW = [to_pairs(g.evolve(G_SW, i)) for i in range(4)]
GLIDERS_SE = [to_pairs(g.evolve(G_SE, i)) for i in range(4)]
GLIDERS_NW = [to_pairs(g.evolve(G_NW, i)) for i in range(4)]
LWSSES_W = [to_pairs(g.evolve(LWSS_W, i)) for i in range(4)]
LWSSES_S = [to_pairs(g.evolve(LWSS_S, i)) for i in range(4)]

assert all((0, 0) in gl for gl in GLIDERS_SW)
assert all((0, 0) in gl for gl in GLIDERS_SE)
示例#30
0
ins = open(inputFile, "r")
recipes = []
blokcDist = [] 
lines = [] 

for line in ins:
	
	splitVals = line.split(':')[1].split(",")
	lines.append(line)
	res = []
	for i in xrange(0, len(splitVals)):
		res.append(int(splitVals[i]))
		
	recipes.append(res)

gld = g.parse("3o$o$bo!")
block = g.parse("2o$2o!", 0, 0)

d = 0 
for r in recipes:
	g.putcells(block, d)
	for i in xrange(0, len(r)):
		g.putcells(gld, 200 * (i + 1) + d, 200 * (i + 1) + r[i])
		
	d += 1000

g.run(50000)
wssList = pickle.load(open(path.join(g.getdir("data"),"WssData.pkl"),"rb") )
objects = FindObjects(wssList)
objects.sort()
示例#31
0
         str([
             "Number of missing cells files = ",
             len(missingcells), "Count of pnames = ", count
         ]))
     # To be consistent with the code below, .cells files should be created in a separate pass
     # -- but we've already had a chance to collect width, height, and RLE from the RLE scan
     # So we'll just make a .cells files using that info, as soon as a missing .cells is found.
     #
     # Notice that this means that .cells files are only created _after_ RLE files are already on the server.
     # That is, we're not going and looking for RLE information in the RLE namespace, only on the server.
     # This is suboptimal, because getting the .cells files there will require two bulk uploads instead of one.
     # On the other hand, doing that in one step needs more code:
     # TODO:  get RLE from raw RLE namespace if we're going to be uploading that
     #        (this will need some fairly serious refactoring, probably moving .cells creation to a separate pass)
     #
     pat = g.parse(rleonly)
     if len(
             pat
     ) % 2 == 0:  # don't try to make a .cells for a multistate file like RLE:briansbrainp3
         g.new(item)
         g.putcells(pat)
         r = g.getrect()
         for y in range(r[3]):
             for x in range(r[2]):
                 ascii += "O" if g.getcell(x + r[0], y +
                                           r[1]) > 0 else "."
             ascii += "\n"
         with open(cellsfolder + item + ".cells", "w") as f:
             f.write(ascii)
 else:  # width and/or height are too big
     toobigforcells += [item]
示例#32
0
    return rle_res + "!"


# --------------------------------------------------------------------
###########################


def makeRLEline(pat):
    return giveRLE(list(itertools.chain(*pat)))


patdict = {}
objlist = []
for i in range(len(objs)):
    # normalize so that the first ON cell in the list is always (0,0)
    templist = g.parse(objs[i])
    objlist += [g.transform(templist, -templist[0], -templist[1])]
numobjs = len(objlist)
zonelist = []
for item in objlist:
    g.setrule("B12345678/S012345678")
    neighbors = g.evolve(item, 1)
    g.setrule("B12345678/S012345678"
              )  ######### this is "B2345678/S012345678" for Conway's Life
    zone = g.evolve(neighbors, 1)
    zonelist += [zone]  # includes cells for object also

g.setrule("LifeHistory")
nearlist = [[i, j] for i in range(-1, xsize + 1) for j in range(-1, ysize + 1)
            if i < 0 or i >= xsize or j < 0 or j >= ysize]
count, x, y, ptr, filledlist, searchlist = 0, 0, 0, 0, [], []
示例#33
0
import golly as g

font = g.parse(
    "701bo$307bo26bo21b2o18bo26bo11b2o90bo192b3o226bo2bo11b3o74b2o9bobo5bo8bo$2b3o7b4o9b3o7b4o8b5o7b5o7b3o8bo3bo5b3o9b3o6bo3bo6bo11bo3bo6bo3bo6b3o8b4o9b3o7b4o9b3o8b5o6bo3bo7bo3bo6bo3bo7bo3bo7bo3bo6b5o17bo26bo20bo20bo10bo9bo5bo12bo90bo77b3o9bo8b2o9b3o10bo8b5o8b3o8b5o7b3o9b3o9bobobo25bo4bo67bo14bo7bo44b2o12bo14bo13bo15bo2bo10bo3bo14bo6bo28b2o7b2o11bo2bo8bobo5bo7bobo$bo3bo6bo3bo7bo3bo6bo3bo7bo11bo10bo3bo7bo3bo6bo11bo7bo2bo7bo11b2ob2o6b2o2bo5bo3bo7bo3bo7bo3bo6bo3bo7bo3bo9bo8bo3bo7bo3bo6bo3bo7bo3bo7bo3bo10bo17bo26bo20bo20bo26bo2bo9bo89b3o75bo3bo7b2o7bo2bo7bo3bo8b2o8bo11bo15bo6bo3bo7bo3bo8bobo11b5o10bobo2bo29bo22bobo12bo14bo9bo22bo8bo10bo2bo12bo13bo13bo14b6o9bo2b2o13bo8bo10bo7bo8bo9bo11bo2bo23bo3bo$bo3bo6bo3bo7bo10bo3bo7bo11bo10bo11bo3bo6bo11bo7bobo8bo11bobobo6bobobo5bo3bo7bo3bo7bo3bo6bo3bo7bo13bo8bo3bo7bo3bo6bo3bo8bobo8bo3bo9bo7b3o8b4o9b3o8b4o8b3o8b3o8b4o7b4o7bo9bo5bobo10bo8b4o7bob2o8b3o8b4o9b4o6bob2o9b4o8bo8bo3bo7bo3bo6bobobo7bo3bo7bo3bo6b5o5bo2b2o8bo10bo11bo7bobo8bo11bo15bo6bo3bo7bo3bo9b3o26bo2bo30bo23bo13bo14bo9bo45bo12bo13bo13bo15bo2bo10bobobo13bo8bo9bo9bo7bo9bo11bobo$b5o6b4o8bo10bo3bo7b4o8b4o7bob3o7b5o6bo11bo7b2o9bo11bo3bo6bo2b2o5bo3bo7b4o8bo3bo6b4o9b3o10bo8bo3bo8bobo7bo3bo9bo10bobo9bo11bo7bo3bo7bo3bo6bo3bo7bo3bo8bo8bo3bo7bo3bo6bo9bo5b2o11bo8bobobo6b2o2bo6bo3bo7bo3bo7bo3bo6b2o2bo7bo12bo8bo3bo7bo3bo6bobobo8bobo8bo3bo9bo6bobobo8bo9bo10b2o7bo2bo8b4o8b4o11bo8b3o9b4o10bobo27bo29b5o5b4o10b5o10bo15bo9bo44bo14bo12bo13bo15bo2bo10bobobo12bo10bo7bo11bo6bo9bo10bobo2bo$bo3bo6bo3bo7bo10bo3bo7bo11bo10bo3bo7bo3bo6bo7bo3bo7bobo8bo11bo3bo6bo3bo5bo3bo7bo11bo3bo6bo3bo11bo9bo8bo3bo8bobo7bobobo8bobo10bo9bo9b4o7bo3bo7bo10bo3bo7b5o8bo8bo3bo7bo3bo6bo9bo5b3o10bo8bobobo6bo3bo6bo3bo7bo3bo7bo3bo6bo12b3o9bo8bo3bo8bobo7bobobo9bo9bo3bo8bo7b2o2bo8bo8bo13bo6b5o11bo7bo3bo9bo8bo3bo11bo8bobobo9b5o12bo3bo28bo23bo11bo16bo9bo22bo8bo11bo16bo11bo13bo14b6o9bo2b2o13bo8bo9bo9bo7bo9bo10bo2b2o$bo3bo6bo3bo7bo3bo6bo3bo7bo11bo10bo3bo7bo3bo6bo7bo3bo7bo2bo7bo11bo3bo6bo3bo5bo3bo7bo11bo3bo6bo3bo7bo3bo9bo8bo3bo9bo8b2ob2o7bo3bo9bo8bo9bo3bo7bo3bo7bo10bo3bo7bo12bo8bo3bo7bo3bo6bo9bo5bo2bo9bo8bobobo6bo3bo6bo3bo7bo3bo7bo3bo6bo15bo8bo8bo2b2o8bobo7bobobo8bobo8bo3bo7bo8bo3bo8bo7bo10bo3bo9bo8bo3bo7bo3bo9bo8bo3bo7bo3bo9b3o26bo3bobo27bo22bobo10bo16bo9bo22bo37bo11bo29bo2bo10bo17bo8bo10bo7bo8bo9bo10bo3bo$bo3bo6b4o9b3o7b4o8b5o7bo11b3o8bo3bo5b3o7b3o8bo3bo6b5o7bo3bo6bo3bo6b3o8bo12b3o7bo3bo8b3o10bo9b3o10bo8bo3bo7bo3bo9bo8b5o6b4o7b4o9b4o7b4o8b4o8bo9b4o7bo3bo6bo9bo5bo3bo7b3o7bobobo6bo3bo7b3o8b4o9b4o6bo11b4o10b2o7b2obo9bo9bobo8bo3bo8b4o6b5o6b3o8b3o6b4o8b3o10bo9b3o9b3o10bo9b3o9b3o11bo26bo5bo12b4o47bo18bo7bo9bo5bo6bo21bo17bo10bo13bo15bo2bo11b4o14bo6bo28b2o7b2o11b3obo$184b2o182bo28bo61bo15bo91bo267bo$368bo26b2o62bo15bo91bo266bo$365b3o91bo15bo88b3o!"
)
textLet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789$=%_+-*/(),.;:?\\|!#@{}<>[]&\"\'"

g.new("")
g.setrule("LifeHistory")
g.putcells(font)

rect = g.getrect()
cells = g.getcells(rect)

for i in range(2, len(cells), 3):
    if cells[i] == 1:
        cells[i] = 4

g.putcells(cells)

x0 = rect[0]
y0 = rect[1] - 1
l = rect[2] + 2
h = rect[3] + 2


def ReadLetters(x0, y0, l, h):
    res = []
    xs = x0
    d = 0
    zerocnt = 0
示例#34
0
   
   g.putcells(g.evolve(obj, p + GetEvolveDirection(t) * ((4 * (x1 - x0)) % p)), x1, y1)
   
   g.update()
   
   d[2] = x1
   d[3] = y1
   
def InitUpdateMove(obj, x, y):
   return [-1, obj, x, y]
   
   
objectArray = []

for d in data:
   objectArray.extend(GetObjectArray([g.parse(d[0]), d[1]]))
   
moving = False
g.show("Select known object with left click, exit with right click")
handling = False
searching = False

while True:

   event = g.getevent()
   
   if handling or searching:
      continue 
      
   handling = True
示例#35
0
def popcount():
    clist = g.getcells(g.getrect())
    return sum(clist[2::3].count(x) for x in live_cells)


input = g.getstring('maxnum/step/boxwidth', '100/1/40')
maxnum = int(input.split('/')[0])
step = int(input.split('/')[1])
boxwidth = int(input.split('/')[2])

tile = []

box = g.parse(
    "40o$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$\
o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38b\
o$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o\
38bo$o38bo$o38bo$o38bo$40o!")
box = pattern(box)
help1 = 'tilewd/soupnum/soupwd/density/gen_thres'
input = g.getstring(help1, '10/100/50/35/500')
tilewd = int(input.split('/')[0])
soupnum = int(input.split('/')[1])
soupwd = int(input.split('/')[2])
density = int(input.split('/')[3])
gen_thres = int(input.split('/')[4])

if g.getrule().split(':')[0] in dict_lc:
    yfunc = 'popc'
else:
    yfunc = 'pop'
示例#36
0
    return representation

# Compares strings first by length, then by lexicographical ordering.
# A hash character is worse than anything else.
def compare_representations(a, b):

    if (a == "#"):
        return b
    elif (b == "#"):
        return a
    elif (len(a) < len(b)):
        return a
    elif (len(b) < len(a)):
        return b
    elif (a < b):
        return a
    else:
        return b

pattern = canonise()
if pattern in consts:
    g.new("solutions")
    loc = consts.index(pattern)
    g.show(str(len(cols[loc])) + " collisions found")
    g.setname(pattern)
    for e in cols[loc]:
	    g.putcells(g.parse(e),offset,0)
	    offset += 50
else:
    g.note("No 3 glider collision found for that constellation. Better luck next time")
示例#37
0
import golly as g 
import copy

gld = g.parse("3o$o$bo!")
blck = g.parse("2o$2o!")

def FindActive():

   rect = g.getrect()
   
   cells = g.getcells([rect[0], rect[1], rect[2], 1])
   
   return [cells[0], cells[1]]
         
def FindConnected(listXY):
   result = copy.copy(listXY)
   
   for xy in listXY:
      x = xy[0]
      y = xy[1]
      
      for i in xrange(-1, 2): 
         for j in xrange(-1, 2): 
            if g.getcell(x + i, y + j) > 0 and len([i for t in listXY if (t[0] == x + i and t[1] == y + j)]) == 0:
				if len([i for t in result if (t[0] == x + i and t[1] == y + j)]) == 0:
					result.append([x + i, y + j])
         
   return result
   
def RemoveList(listXY):
示例#38
0
import golly as g 

glider_cells = g.parse("3o$o$bo!")
#block_cells = g.parse("2o$2o!")
block_cells = g.parse("2o$2o!", 0, 1)
lines = [] 

def Read(path):
	ins = open(path, "r" )
	array = []

	for line in ins:
		vals = line.split(":")
		lines.append(line)
		
		vals[0] = vals[0].replace("m", "")
		vals[0] = vals[0].split(",")
		x = int(vals[0][1])
		y = int(vals[0][2])
		vals[1] = vals[1].replace("E", "").replace("\n", "").replace(" ", "")
		vals[1] = vals[1].split(",")
		
		for i in xrange(0, len(vals[1])):
			vals[1][i] = int(vals[1][i])
			
		array.append([x, y, vals[1]])
		
	ins.close()

	return array
	
示例#39
0
#Get the Value of gun which should be the only thing present in the current Document 
#Make sure you've saved your work. This script deletes history. 
#This script is made to evaluate glider gun value easier. 
#Written by Michael Simkin 2014
import golly as g 
import glob

'''Number Placement'''

snakeLineHor = g.parse("2obob2obo$ob2obob2o!")
snakeLineVer = g.transform(snakeLineHor, -3, 3, 0, 1, 1, 0)

figure8 = [snakeLineVer, g.transform(snakeLineVer, 0, 13),  snakeLineHor, g.transform(snakeLineHor, 0, 13), g.transform(snakeLineHor, 0, 26), g.transform(snakeLineVer, 13, 0), g.transform(snakeLineVer, 13, 13)]

def PlaceDigit(digit, x = 0, y = 0):
	digitIdx = [[0,1,2,4,5,6], [5,6],[1,2,3,4,5],[2,3,4,5,6],[0,3,5,6],[0,2,3,4,6],[0,1,2,3,4,6],[2,5,6],[0,1,2,3,4,5,6],[0,2,3,4,5,6]]
	
	if digit >= 0 and digit <= 9:
		for idx  in digitIdx[digit]:
			g.putcells(figure8[idx], x, y)
def NumDigit(num):
	if num < 10: 
		return 1 
	else: 
		return 1 + NumDigit(int((num - (num % 10))/10))
		
def PlaceNumber(number, x = 0, y = 0):
	if number < 0: 
		g.putcells(figure8[3], x, y)
		PlaceNumber(-number, x, y)
		return
示例#40
0
http://catagolue.hatsya.com/hashsoup/C4_1/m_ZpA8wrqL7BWe5025735/b3s23
http://catagolue.hatsya.com/hashsoup/C4_1/m_n4RrjxJnAyVh2247280/b3s23
http://catagolue.hatsya.com/hashsoup/C4_1/m_QhQqSp6E9f46681912/b3s23
http://catagolue.hatsya.com/hashsoup/C4_1/m_wv5nSaeHhnju2755748/b3s23
http://catagolue.hatsya.com/hashsoup/C4_1/m_eabypta5Dw7j5383677/b3s23
http://catagolue.hatsya.com/hashsoup/C4_1/m_pjmRhnaWVfDr7996204/b3s23
http://catagolue.hatsya.com/hashsoup/C4_1/m_qQx4KFH2gMvf4787776/b3s23
http://catagolue.hatsya.com/hashsoup/C4_1/m_QiAMYn8FSeHa9286352/b3s23
http://catagolue.hatsya.com/hashsoup/C4_1/m_msEhYNZ9Zwxq9626379/b3s23
http://catagolue.hatsya.com/hashsoup/C4_1/m_JwysjvV8r7Ts5961536/b3s23
http://catagolue.hatsya.com/hashsoup/C4_1/m_rXDPBX33mgJT6619083/b3s23
http://catagolue.hatsya.com/hashsoup/C4_1/m_RwxdnsCi974q6249233/b3s23
http://catagolue.hatsya.com/hashsoup/C4_1/m_8WW8mnKRkAGV62287/b3s23
http://catagolue.hatsya.com/hashsoup/C4_1/m_H5sFgC3GJHua3439480/b3s23
http://catagolue.hatsya.com/hashsoup/C4_1/m_FdbGbkwCnaVg965122/b3s23
http://catagolue.hatsya.com/hashsoup/C4_1/m_PTHj7EtSqkFb3452202/b3s23
http://catagolue.hatsya.com/hashsoup/C4_1/m_9JmjUrKbmFTm2538171/b3s23
http://catagolue.hatsya.com/hashsoup/C4_1/m_px3inAktzpwG428065/b3s23
http://catagolue.hatsya.com/hashsoup/C4_1/m_nMjZjz8NHTaV1592863/b3s23
"""

datalist = data.split("\n")
ptr = 0
for d in datalist:
    html = urlopen(d).read().decode()
    # get rid of header line
    ind = html.index("\n")
    rle = html[ind + 1:]
    g.putcells(g.parse(rle), ptr, 0)
    ptr += 100
def add_it(objs, s, dx, dy):
    cells = g.parse(s)
    for i in range(4):
        objs.append((make_target(cells), dx, dy))
        cells = g.evolve(cells, 1)
示例#42
0
import golly as g 
from copy import copy

destinationPath = "C:\\Users\\SimSim314\\Glue\\WSSp2Fast\\"
gld = g.parse("3o$o$bo!")
blck = g.parse("2o$2o!")
existingDic = {}
existingKeys = []

def FindRightMost(cells):
	maxX = -10000
	
	for i in xrange(1, len(cells), 2):
		if cells[i - 1] > maxX:
			maxX = cells[i - 1]
			
	return maxX
	
def HasEdgeShooter(minx):
	rect = g.getrect()
	
	y = rect[1] + rect[3]
	
	if y < 100: 
		return False
		
	g.run(4)
	
	rect = g.getrect()
	
	if y + 2 == rect[1] + rect[3]:
示例#43
0
文件: parser.py 项目: simsim314/Glue
import golly as g 
import copy

inputFile = "C:\\Users\\SimSim314\\Documents\\GitHub\\FastGlue\\results_10250.txt"

snakeLineHor = g.parse("2obob2obo$ob2obob2o!")
snakeLineVer = g.transform(snakeLineHor, -3, 3, 0, 1, 1, 0)

figure8 = [snakeLineVer, g.transform(snakeLineVer, 0, 13),  snakeLineHor, g.transform(snakeLineHor, 0, 13), g.transform(snakeLineHor, 0, 26), g.transform(snakeLineVer, 13, 0), g.transform(snakeLineVer, 13, 13)]

def PlaceDigit(digit, x = 0, y = 0):
   digitIdx = [[0,1,2,4,5,6], [5,6],[1,2,3,4,5],[2,3,4,5,6],[0,3,5,6],[0,2,3,4,6],[0,1,2,3,4,6],[2,5,6],[0,1,2,3,4,5,6],[0,2,3,4,5,6]]
   
   if digit >= 0 and digit <= 9:
      for idx  in digitIdx[digit]:
         g.putcells(figure8[idx], x, y)
		 
def NumDigit(num):
   if num < 10: 
      return 1 
   else: 
      return 1 + NumDigit(int((num - (num % 10))/10))
      
def PlaceNumber(number, x = 0, y = 0):
   curNum = number
   d = 20 * NumDigit(number)
   
   while True:
      PlaceDigit(curNum%10, x + d, y)
      curNum = (curNum - curNum%10) / 10 
      
示例#44
0
# build-single-channel.py, version 3.0

import golly as g

gliders = ["3o$o$bo!", "b2o$2o$2bo!", "b2o$bobo$bo!", "2bo$b2o$bobo!"]
gliderlist = [g.parse(gl) for gl in gliders]
elbow = g.parse("2C$2C!")


def makerecipe(recipe):
    g.putcells(gliderlist[0])
    totaltime = 0
    for i in recipe[1:]:
        totaltime += i
        g.putcells(
            g.transform(gliderlist[totaltime % 4], totaltime / 4,
                        totaltime / 4))
        g.show(str(totaltime))


# sample combined recipe
recipe = [
    0,
    109,
    91,
    94,
    91,
    90,
    96,
    90,
    91,
示例#45
0
import golly as g
 
inputstr="E9 E10 E11 E12 E13 E14 E15 E15 E22 E15 E7 O-9 E24 E24 O33 O-9 O-9 O-11 O2 E-11 E-11 O-17 O-5 O-30 E9 O39 O28 E-2 E0 O10 E3 E8 E13 E17 E-21 E-32 E-26 E-7 E-3 E-5 O12 E2 E16 E20 O-15 E-27 E-23 E-31 O-23 O-24 O-11 O-31 O-7 E27 E35 E23 O17 E30 E16 E20 O7 O10 O7 O12 O1 O3 E9 O4 O30 O43 E34 O29 O29 O-5 E-31 E-26 E-24 E-26 O-18 O-16 O-14 E-6 E-6 O-14 O-15 O-19 O12 O15 E25 E23 O13 O2 E1 E25 O-9 O-12 E-22 E-20 O-10 O1 E2 E-22"
inputstr="E-8 E-18 E-12 E6 E15 E22 E15 E7 O-9 E24 E24 O33 O-9 O-9 O-11 O2 E-11 E-11 O-17 O-5 O-30 E9 O39 O28 E-2 E0 O10 E3 E8 E13 E17 E-21 E-32 E-26 E-7 E-3 E-5 O12 E2 E16 E20 O-15 E-27 E-23 E-31 O-23 O-24 O-11 O-31 O-7 E27 E35 E23 O17 E30 E16 E20 O7 O10 O7 O12 O1 O3 E9 O4 O30 O43 E34 O29 O29 O-5 E-31 E-26 E-24 E-26 O-18 O-16 O-14 E-6 E-6 O-14 O-15 O-19 O12 O15 E25 E23 O13 O2 E1 E25 O-9 O-12 E-22 E-20 O-10 O1 E2 E-22"
 
gliders=["3o$o$bo!","b2o$2o$2bo!","b2o$bobo$bo!","2bo$b2o$bobo!"]
gliderlist=[g.parse(gl) for gl in gliders]
elbow=g.parse("2o$2o!")
 
g.setrule("Life")
 
def makerecipe(recipe):
  clist = gliderlist[0]
  totaltime=0
  for i in recipe[1:]:
    totaltime+=i
    clist=g.join(clist,g.transform(gliderlist[totaltime%4],totaltime/4,totaltime/4))
  return clist

## find this one -- [-33, -44, '0,93,90,91,91,90,90,154,120,127,90,100,90,147,91,90,91,276,94,93,91,91,90,134,90,90,90,144,90', 0]

data="""Move+14Lane+00:0,109,91,93,91,92,90,97,91,116,91,145,90,91,98,90,90,188,91,91,91,90,115,90
Move-01Lane+00:0,109,91,93,91,92,90,97,91,116,91,145,90,91,98,90,90,188,91,90,90,90
Move+05Lane+01:0,109,91,95,125,128,90,90,90,172,90,90,90,119,91,113,247,90,144,90,140,90
Move-24Lane+01:0,109,91,94,91,91,93,90,95,90,113,90,99,90,156,90,90,90,138,170
Move+02Lane-01:0,109,91,94,91,91,136,90,90,91,171,100,91,91,90,92,96,90,101,90
Move-09Lane-01:0,109,90,95,245,90,95,90,123,91,90,115,142,90
Move+00Lane+02:0,109,91,93,91,92,90,162,90,129,91,91,91,90,137,99,90,90,111,91,153,90,90,90
Move-27Lane+02:0,109,91,94,91,91,124,91,90,91,91,90,91,90,141,90,172,91,161,90,169,228,90
Move+07Lane-02:0,109,91,93,91,92,91,90,90,162,91,91,90,129,91,113,90,90,90,90
Move-23Lane-02:0,93,91,118,91,151,90,99,153,91,90,149,136,91,106,91,90,90,91,136,90
示例#46
0
    if len(r) == 0: g.exit("No pattern, nothing to do.")
sel = g.getcells(r)
if len(sel) == 0: g.exit("Nothing in selection.")
if len(sel) % 2: g.exit("Can't do the rewinding trick on multistate rules.")
all = g.getcells(g.getrect())
allcoords = []
for i in range(0, len(all), 2):
    allcoords.append([all[i], all[i + 1]])

# g.show("Processing object library...")
odict = dict()
for i in range(len(lib)):
    # g.show("Processing object " + lib[i][0])
    # run and normalize each library object until a duplicate of the original pattern appears
    # The number of ticks to duplication, and the offset, give all the information needed to rewind...
    obj = g.parse(lib[i][1])
    basex, basey, ticks, newobj = obj[0], obj[1], 0, []
    baseobj = g.transform(obj, -basex, -basey)
    basepat = pattern(
        baseobj)  # use glife to avoid having to add a layer in Golly
    while cmp(baseobj, newobj) != 0:
        ticks += 1
        newpat = basepat[ticks]
        newlist = list(newpat)
        newobj = g.transform(newpat, -newlist[0], -newlist[1])
        if ticks > 999:
            g.exit(obj[0] + " in library has no reasonable repeat time.")
    stridex, stridey = newlist[0], newlist[1]

    # odict key is name+phase, and there's an entry for each phase of each object
    # Contains list of repeat, stridex, stridey, dx, dy, clist, envclist.
示例#47
0
count = NUMLINES
outptrx, outptry, matches = 0, 0, 0
pat = g.getcells(r)

g.addlayer()  # do tests in a new layer, then put results there
hash = getoctohash(pat)
g.new("Output")
if pat != []:
    g.putcells(pat, -pat[0] - GRIDSIZE, -pat[1])

for i in range(10):
    s = "Scanning " + fingerprintfile + "_" + str(i) + ".txt"
    with open(fingerprintfile + "_" + str(i) + ".txt", "r") as f:
        for line in f:
            count -= 1
            if hash in line:
                matches += 1
                matchingpat = line[:line.index(" ")]
                g.putcells(g.parse(matchingpat), outptrx * GRIDSIZE,
                           outptry * GRIDSIZE)
                outptrx += 1
                if outptrx % 50 == 0:
                    outptrx, outptry = 0, outptry + 1
                    g.fit()
                    g.update()
            if count % 1000 == 0:
                g.show(s + " Lines remaining: " + str(count / 1000) +
                       "K lines.")
plural = "" if matches == 1 else "s"
g.show("Found " + str(matches) + " line" + plural + " matching" + hash +
       " in " + str(NUMLINES) + " lines of " + fingerprintfile + ".")
示例#48
0
import golly as g
import copy
from os import path

glider_cells = g.parse("3o$o$bo!")
block_cells = g.parse("2o$2o!")


class RecipeConstructor(object):
    def __init__(self):
        self.blockX = 0
        self.blockY = 0
        self.sequence = []
        self.recipe = []
        self.BlockMoveTableEven = {}
        self.BlockMoveTableOdd = {}
        self.WssCreator = []
        self.minD = 0
        self.maxY = 0
        self.maxX = 0

    def Reset(self):
        self.blockX = 0
        self.blockY = 0
        self.sequence = []
        self.recipe = []

    def AddWss(self, idx):
        delta = self.blockY - self.blockX
        dx = self.WssCreator[idx][0]
        dy = self.WssCreator[idx][1]
示例#49
0
def get_glider_color(glider):
    return (glider[0] % 2) == (glider[1] % 2)


filename = '/Users/ifomichev/work/gencols/hbsynth/hf.col'
infile = open(filename, 'r')
outfile = open(filename + '.out', 'w')

for line in infile:
    pattern, _, _, pattern_type = re.split('\s', line, 5)[:4]
    if pattern_type != 'other':
        continue

    pattern = re.sub('!', '.\n', pattern)

    cells = g.parse(pattern)

    gliders = []
    temp_cells = cells[:]
    for gen in range(0, 4):
        gliders.extend(find_all_gliders(temp_cells))
        temp_cells = g.evolve(temp_cells, 1)

    if len(gliders) < 2:
        continue

    sample = get_glider_color(gliders[0])
    if not all([get_glider_color(glider) == sample for glider in gliders[1:]]):
        continue

    # check that pattern emits exactly one orthogonal glider
示例#50
0
def get_glider_color(glider):
  return (glider[0] % 2) == (glider[1] % 2)

filename = '/Users/ifomichev/work/gencols/hbsynth/hf.col'
infile = open(filename, 'r')
outfile = open(filename + '.out', 'w')

for line in infile:
  pattern, _, _, pattern_type = re.split('\s', line, 5)[:4]
  if pattern_type != 'other':
    continue

  pattern = re.sub('!', '.\n', pattern)

  cells = g.parse(pattern)

  gliders = []
  temp_cells = cells[:]
  for gen in range(0, 4):
    gliders.extend(find_all_gliders(temp_cells))
    temp_cells = g.evolve(temp_cells, 1)

  if len(gliders) < 2:
    continue

  sample = get_glider_color(gliders[0])
  if not all([get_glider_color(glider) == sample for glider in gliders[1:]]):
    continue

  # check that pattern emits exactly one orthogonal glider
示例#51
0
import golly as g 
import copy

gld = g.parse("3o$o$bo!")
blck = g.parse("2o$2o!")

def FindActive():

   rect = g.getrect()
   
   cells = g.getcells([rect[0], rect[1], rect[2], 1])
   
   return [cells[0], cells[1]]
         
def FindConnected(listXY):
   result = copy.copy(listXY)
   
   for xy in listXY:
      x = xy[0]
      y = xy[1]
      
      for i in xrange(-1, 2): 
         for j in xrange(-1, 2): 
            if g.getcell(x + i, y + j) > 0 and len([i for t in listXY if (t[0] == x + i and t[1] == y + j)]) == 0:
				if len([i for t in result if (t[0] == x + i and t[1] == y + j)]) == 0:
					result.append([x + i, y + j])
         
   return result
   
def RemoveList(listXY):