Prototype for 22da Soup Search

For scripts to aid with computation or simulation in cellular automata.
Post Reply
c0b0p0
Posts: 645
Joined: February 26th, 2014, 4:48 pm

Prototype for 22da Soup Search

Post by c0b0p0 » May 8th, 2014, 10:36 pm

A soup search script for 22da has been anticipated for some time, particularly because there are no known odd-period oscillators in the rule (and there are no known orthogonal spaceships in the rule, either). So here's a new soup search script that should make finding new oscillators and spaceships easier.

Code: Select all

# Prototype soup search script for 22da.  A pickled catalogue of data for novel objects is stored in a text file within Golly's patterns folder.

import time
import pickle

while 1 == 1: #soup search script by default goes forever 
 intrcttl=[(-2,-2),(-2,-1),(-2,0),(-1,-2),(-1,-1),(-1,0),(-1,1),(0,-2),(0,-1),(0,1),(0,2),(1,-1),(1,0),(1,1),(1,2),(2,0),(2,1),(2,2)]
 pttrnlf=[]
 try:
   f=open(g.getdir("patterns")+"hexobj.txt","r+")
 except:
   f=open(g.getdir("patterns")+"hexobj.txt","w")
 f.close()
 try: 
   with open(g.getdir("patterns")+"hexobj.txt","r+") as f:
     pl = pickle.load(f)
     while pl:    
       pttrnlf=pttrnlf+[(pl[0],pl[1])]  
       pl = pickle.load(f)
 except:
   pl=0
 rect=g.getrect() 
 if len(rect) != 0: g.clear(0)
 g.select([-20,-20,40,40])
 g.randfill(40)
 g.run(10000)
 rect=g.getrect() 
 cll=g.getcells(rect)
 lngth = len(cll)
 i=0
 pttrnl=[]
 while i < lngth:
   if g.getcell(cll[i],cll[i+1])==1:
     xinit=cll[i]
     yinit=cll[i+1]
     pttrntl=[(xinit,yinit)]
     initpttrntl=[]
     while pttrntl != initpttrntl:
       initpttrntl=list(set(pttrntl))
       for ct in pttrntl:
         xinit1=ct[0]
         yinit1=ct[1]
         for nct in intrcttl:
           if g.getcell(xinit1+nct[0],yinit1+nct[1]) == 1:
              g.setcell(xinit1+nct[0],yinit1+nct[1],0)
              pttrntl=pttrntl+[(xinit1+nct[0],yinit1+nct[1])]
       pttrntl=list(set(pttrntl))      
     pttrntl1=range(len(pttrntl))
     for j in range(len(pttrntl)):
       pttrntl1[j]=(pttrntl[j][0]-xinit,pttrntl[j][1]-yinit)
     pttrntl1.sort()
     pttrnl+=[[len(pttrntl1),pttrntl1,(xinit,yinit)]]
   i+=2
 if len(pttrnl)>0:
   pttrnl.sort()
   ptst=1
   for p in pttrnlf: 
     if pttrnl[0][0]==p[0] and pttrnl[0][1]==p[1]:
       ptst=0          
   if ptst==1: pttrnl1 = [pttrnl[0]]
   else: pttrnl1 = []
   for i in range(1,len(pttrnl)):
     if pttrnl[i][1]!=pttrnl[i-1][1]:
        ptst=1
        for p in pttrnlf: 
          if pttrnl[i][0]==p[0] and pttrnl[i][1]==p[1]:
             ptst=0          
        if ptst==1: pttrnl1 = pttrnl1 + [pttrnl[i]]
 if len(pttrnl1)>0:  
   f=open(g.getdir("patterns")+"hexobj.txt","a")
   t=time.time()
   for pttrn in pttrnl1:
     pickle.dump(pttrn+[t],f)
   f.close()

An unpickler script will be provided soon for those who don't want to read pickled lists.

wildmyron
Posts: 1547
Joined: August 9th, 2013, 12:45 am
Location: Western Australia

Re: Prototype for 22da Soup Search

Post by wildmyron » May 10th, 2014, 12:26 pm

Thanks for posting this. It certainly finds objects a lot more frequently than what I have been using until now. I had to make a few changes to get it to run though:
  • add "import golly as g"
  • indent everything below the while statement
  • add "g.select(rect)" prior to "if len(rect) != 0: g.clear(0)" so the clear doesn't fail
I also prefer to use "g.new('')" in each iteration of the loop. I'm not sure how expensive it becomes over time but there doesn't seem to be a need to retain undo history.

After running the script for a very short period I had a look at the output. It's apparent, and to be expected, that every different phase of each oscillator will be recorded as well as each phase of each direction of the gliders and the puffers. There were also a range of sparks which died out when I ran them. I guess they were probably disconnected parts of puffer output which were recorded.

I suspect some type of object detection would be beneficial. Have you looked at Nathaniel's census script? I think those ideas can certainly be applied here.

Here's my quick and dirty unpickler - just to give an overview of what gets recorded. Note - you'll need to change back the file location which I changed to accommodate my setup.

Code: Select all

# 22da-unpickle.py
# Prototype soup search script for 22da.  A pickled catalogue of data for novel objects is stored in a text file within Golly's patterns folder.
# Unpickle utility to display objects on a square grid

import os
import pickle
import math

import golly as g
from glife import pattern
from itertools import chain

fullName = os.path.join(g.getdir("patterns"), "My-Patterns", "22da", "hexobj.txt")
pttrnlf = []

try:
    with open(fullName,"r+") as f:
        pl = pickle.load(f)
        while pl:   
            pttrnlf = pttrnlf + [(pl[0], pl[1])] 
            pl = pickle.load(f)
except:
    pl = 0

length = len(pttrnlf)
side = int(math.ceil(math.sqrt(length)))

idx = 0
cells = []
pttrnl = []
all = pattern()

while idx < length:
    pttrnl = pttrnlf[idx]
    cells = list( chain.from_iterable(pttrnl[1]) )
    j, i = divmod(idx, side)
    all += pattern(cells)(15*i, 15*j)
    idx+=1

all.display()
g.show(str(length) + " items in object file")
The 5S project (Smallest Spaceships Supporting Specific Speeds) is now maintained by AforAmpere. The latest collection is hosted on GitHub and contains well over 1,000,000 spaceships.

Semi-active here - recovering from a severe case of LWTDS.

Post Reply