Changed the algo the QuickLife, which is a little faster. Still trying to implement multiple soups per page.
Code: Select all
# codeholic's FuseFinder script v1.02
# Creates a new layer called "FuseTestLayer"
# Writes to a FuseFinder subfolder in Golly's data directory.
# Updates screen every hundred trials (why not?)
# Uses g.new() as per simsim314's suggestion
# (I noticed that Golly's Undo got very slow after running the old script) (?)
import golly as g
import os
import time
import hashlib
outpath=os.path.join(g.getdir("data"),"FuseFinder")
if not os.path.isdir(outpath): os.mkdir(outpath)
SEED = "Anything you like"
FUSENAME = "Diagpuffer"
DEBRIS = g.parse('bo$obo$bo4$3bo$2bobo$2bobo$3bo!')
WIDTH = 5
HEIGHT = 10
DX, DY = (-7, -7) #For diagonal/oblique fuses
COPIES = 100
TESTRECT = [COPIES * DX, COPIES * DY, WIDTH, HEIGHT]
RNDSIZE = 15
RNDRECT = [0, 0, RNDSIZE, RNDSIZE]
SOUPSPERDISPLAY = 100
def hashsoup(instring):
s = hashlib.sha256(instring).digest()
thesoup = []
for j in xrange(32):
t = ord(s[j])
for k in xrange(8):
if (t & (1 << (7 - k))):
thesoup.append(k + 8*(j % 2))
thesoup.append(int(j / 2))
return thesoup
def patterns_identical(cells1, cells2):
if len(cells1) != len(cells2):
return False
return set(zip(cells1[::2], cells1[1::2])) == set(zip(cells2[::2], cells2[1::2]))
for i in range(g.numlayers()):
if g.getname(i)=="FuseTestLayer":
r=g.getrect()
if r is not []:
g.select(r)
g.clear(0)
break
if not g.getname(i)=="FuseTestLayer": g.addlayer()
g.setalgo('QuickLife')
for i in xrange(1, COPIES+1):
g.putcells(DEBRIS, i * DX, i * DY)
allcells=g.getcells(g.getrect())
cells = g.getcells(TESTRECT)
count, found = 0, 0
start_time = time.clock()
# For profiling
#
#init_time = 0
#gen_time = 0
#check_time = 0
while True:
#mark = time.clock()
g.new("FuseTestLayer")
g.putcells(allcells)
g.select(RNDRECT)
g.randfill(50)
#init_time += time.clock()-mark
#mark = time.clock()
g.setbase(16)
g.setstep(3)
g.step()
#gen_time +=time.clock()-mark
#mark = time.clock()
test = g.getcells(TESTRECT)
count += 1
if not patterns_identical(test, cells):
g.reset()
g.save(os.path.join(outpath, FUSENAME + str(count) + '.rle'), 'rle')
g.show("Saved fuse to " + outpath + FUSENAME + str(count) + ".rle")
found += 1
if count % SOUPSPERDISPLAY == 0:
end_time =time.clock()
g.show('Count:' + str(count) + ' Found:' + str(found) + ' (' +\
str(round(SOUPSPERDISPLAY/(end_time - start_time), 2)) + " soups per second)")
#g.show('init: '+str(init_time*1000/count)+'ms gen: '+str(gen_time*1000/count)+'ms check: '+str(check_time*1000/count)+'ms')
start_time = end_time
g.setmag(2)
g.update()
#check_time += time.clock()-mark