How to get the codes for patterns?
Posted: July 3rd, 2020, 8:42 pm
Can anyone tell me how to get the code for various patterns?
Forums for Conway's Game of Life
https://conwaylife.com/forums/
Do you mean apgcode?hotcrystal0 wrote: July 3rd, 2020, 8:42 pm Can anyone tell me how to get the code for various patterns?
Code: Select all
import golly as g
# Golly selection to apgcode (in clipboard)
# stolen shamelessly from apgsearch. Thanks Adam!
def bijoscar(maxsteps):
initpop = int(g.getpop())
initrect = g.getrect()
if (len(initrect) == 0):
return 0
inithash = g.hash(initrect)
for i in xrange(maxsteps):
g.run(1)
if (int(g.getpop()) == initpop):
prect = g.getrect()
phash = g.hash(prect)
if (phash == inithash):
period = i + 1
if (prect == initrect):
return period
else:
return -period
return -1
def canonise():
p = bijoscar(1000)
representation = "#"
for i in range(abs(p)):
rect = g.getrect()
representation = compare_representations(representation, canonise_orientation(rect[2], rect[3], rect[0], rect[1], 1, 0, 0, 1))
representation = compare_representations(representation, canonise_orientation(rect[2], rect[3], rect[0]+rect[2]-1, rect[1], -1, 0, 0, 1))
representation = compare_representations(representation, canonise_orientation(rect[2], rect[3], rect[0], rect[1]+rect[3]-1, 1, 0, 0, -1))
representation = compare_representations(representation, canonise_orientation(rect[2], rect[3], rect[0]+rect[2]-1, rect[1]+rect[3]-1, -1, 0, 0, -1))
representation = compare_representations(representation, canonise_orientation(rect[3], rect[2], rect[0], rect[1], 0, 1, 1, 0))
representation = compare_representations(representation, canonise_orientation(rect[3], rect[2], rect[0]+rect[2]-1, rect[1], 0, -1, 1, 0))
representation = compare_representations(representation, canonise_orientation(rect[3], rect[2], rect[0], rect[1]+rect[3]-1, 0, 1, -1, 0))
representation = compare_representations(representation, canonise_orientation(rect[3], rect[2], rect[0]+rect[2]-1, rect[1]+rect[3]-1, 0, -1, -1, 0))
g.run(1)
if (p<0):
prefix = "q"+str(abs(p))
elif (p==1):
prefix = "s"+str(g.getpop())
else:
prefix = "p"+str(p)
g.setclipstr("x"+prefix+"_"+representation)
# A subroutine used by canonise:
def canonise_orientation(length, breadth, ox, oy, a, b, c, d):
representation = ""
chars = "0123456789abcdefghijklmnopqrstuvwxyz"
for v in xrange(int((breadth-1)/5)+1):
zeroes = 0
if (v != 0):
representation += "z"
for u in xrange(length):
baudot = 0
for w in xrange(5):
x = ox + a*u + b*(5*v + w)
y = oy + c*u + d*(5*v + w)
baudot = (baudot >> 1) + 16*g.getcell(x, y)
if (baudot == 0):
zeroes += 1
else:
if (zeroes > 0):
if (zeroes == 1):
representation += "0"
elif (zeroes == 2):
representation += "w"
elif (zeroes == 3):
representation += "x"
else:
representation += "y"
representation += chars[zeroes - 4]
zeroes = 0
representation += chars[baudot]
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
g.duplicate()
g.clear(1)
canonise()Welcome! RLE is definitely not something like "$0B65$97$2e1".
Ordinarily, if a pattern hasn't started running yet, or if you hit R to reset to the T=0 version of the pattern, Ctrl+C will work fine without any need to click the Sync button.Saka wrote: July 3rd, 2020, 9:43 pmOn lifeviewer, click the "Sync" button first to turn enable copying to the external clipboard. After that, just Ctrl+C as usual and the RLE will be in your clipboard.
When there is no selection then Ctrl+C will copy the entire pattern to both the internal (LifeViewer) and external (System) clipboards.dvgrn wrote: July 3rd, 2020, 10:37 pmOrdinarily, if a pattern hasn't started running yet, or if you hit R to reset to the T=0 version of the pattern, Ctrl+C will work fine without any need to click the Sync button.Saka wrote: July 3rd, 2020, 9:43 pmOn lifeviewer, click the "Sync" button first to turn enable copying to the external clipboard. After that, just Ctrl+C as usual and the RLE will be in your clipboard.
It's only when you're doing things in LifeViewer that might create very large RLEs -- e.g., editing and running a pattern for a long time -- that the requirement to enable Sync goes into effect.
What is a specific example of a pattern that you want a script for? What kind of script (Python? Lua?) Where did you get the impression that patterns have associated scripts?
Well, if you want to make the LifeViewer show up embedded in the post itself, click the "viewer" tag and then paste the RLE inside it. However, this is often frowned upon due to how much space it takes up, so instead it's generally preferred to use the "code" tag instead (fifth button from the left) which, if it has a valid RLE inside, will produce a "show in viewer" button that creates a popup LifeViewer window:
Code: Select all
x = 3, y = 3, rule = B3/S23
bo$2bo$3o!