Here's an alpha-version Python script that could be edited to explore any of the clickmazes recipes. I've hard-coded it to display the 247-step Gosper glider gun recipe.
Code: Select all
# interactive-life.py, version 0.1 alpha
# ... I know, it should probably really be interactive-life.lua,
# but I'm faster at writing Python and theoretically I could always port it over later.
import golly as g
from time import sleep
# the middle line below is only needed to get the key cell out of the way of the gun, and store it safely in a block. Could be much shorter.
preload = r"L/R>LS>\\><<DS<<U/<<SS<SS<SSU\SSD<SS</S\R\LSSSLS>></\D\\SS\SS\SS\SSD<SS<SS<SS<SS<SS</S\R\LSD\><LSS\SLSUR\>L</S>U>DU<</U\\S<<SS<SS<SSU\>S<R<LSU</\LSS<SLSDR<//SSL\>S\D\U/D>SD/\/<\\SS\SS\SSR/SS/U<>L>RSU>SR/DDDLS<<U\SUDU/SS/SS/<S/SL/SUSU<<U<D>>>/RS<R>" \
+ r"U/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SSLRSSSSSSSSSSSSSSSSSSSSSS" \
+ r"SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS" # let the pattern run for a while to show that the glider gun works
startpat = "kGjFiGhHkHiIjI"
waitlength = 0.5
charlookup = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
chardict = {}
for i in range(62):
chardict[charlookup[i]]=i
delta = {"S":[0,0],"U":[0,-1],"D":[0,1],
"L":[-1,0],"R":[1,0],"\\":[-1,-1],
"/":[1,-1],"<":[-1,1],">":[1,1]}
g.setrule("LifeHistory")
g.new("Interactive-Life")
if len(startpat) == 0:
g.exit("Starting pattern has not been specified.")
if len(startpat) % 2 == 1:
g.exit("Starting pattern must consist of coordinate pairs (i.e., must be even length).")
for i in range(len(startpat)):
if startpat[i] not in chardict:
g.exit("Illegal character found in starting pattern: '" + startpat[i] + "'.")
for i in range(0,len(startpat),2):
x, y = chardict[startpat[i]],chardict[startpat[i+1]]
if i == 0:
x0, y0 = x, y
g.setcell(x,y,5)
else:
g.setcell(x,y,1)
g.fit()
g.setmag( g.getmag() - 2 )
g.update()
while 1:
char = ""
if preload != "":
char = preload[:1]
preload = preload[1:]
if preload == "":
g.show("No more preloaded recipe. Press \, U, /, L, S, R, <, D, >.")
else:
ch = "?"
while ch!="~":
ch = (g.getevent()+"~~~~~")[4]
if ch == "+" or ch == "=":
waitlength /= 1.3
elif ch == "_" or ch == "-":
waitlength *= 1.3
g.show("Speed = " + str(waitlength) + ", preloaded characters left = " + str(len(preload)) + ". Current character '" + char + "'.")
sleep(waitlength)
else:
while char == "":
key = g.getevent()
if key[:4]=="key ":
dx, dy = 0,0
char = key[4].upper()
if char not in "SUDLR\/<>Q":
char = ""
if char == "Q":
g.show("Simulation complete.")
g.exit()
dx, dy = delta[char]
x1, y1 = x0 + dx, y0 + dy
# g.note("Moving cell to " + str(x1) + "," + str(y1) + ".")
g.setcell(x0,y0,0)
g.setcell(x1,y1,5)
g.update()
sleep(waitlength)
g.run(1)
if g.getcell(x1,y1) != 5:
g.exit("Problem: sequence resulted in cell death in generation " + g.getgen() + ".")
x0, y0 = x1, y1
g.update()
As it currently stands, the script starts allowing keyboard interaction once the preloaded characters have been processed. The keys are the same as the characters in the clickmazes scripts:
To speed up or slow down the processing of preloaded characters, hit + or - respectively. Q quits the script.
I didn't put in a check for legality of the key cell's movement, so it can currently move to be on top of an existing ON cell, which is technically illegal by the standard rules.
This link gives a longer recipe for a Gosper glider gun, but with better commentary on how the construction problem was solved. If anyone wants to play around with this, that might be a good next recipe to implement.
I used the "life2" Java applet's way of specifying initial cells, e.g., "kGjFiGhHkHiIjI" for a 2bo$bobo$o2bo$b2o! loaf. It looks like some of the pages instead specify a starting position by a certain number of preliminary moves of a cell (leaving behind an ON trail, I think). If someone wants to implement that option for a starting pattern, please be my guest. I hereby promise not to do any more work on this script, so it's up to all y'all from here out.