Thread for your script-related questions

For scripts to aid with computation or simulation in cellular automata.
User avatar
Katrina
Posts: 161
Joined: September 26th, 2024, 3:23 am

Re: Thread for your script-related questions

Post by Katrina »

confocaloid wrote: February 6th, 2025, 12:23 am
Sylvani wrote: February 5th, 2025, 10:21 pm Is this code able to be fixed? [...]
Not an answer, but it looks like the same or closely related code was posted in another thread: viewtopic.php?p=203219#p203219 (although without a direct link or mention). Is that post now redundant to this post? Maybe there should be just a link instead of duplicating the code.
That post actually should be redundant because I think it is an earlier version of the code. I do apologize for reposting the code, too
User avatar
confocaloid
Posts: 6697
Joined: February 8th, 2022, 3:15 pm
Location: learn to protect yourself against stray gliders and sparks and self-destruct mechanisms

Re: Thread for your script-related questions

Post by confocaloid »

Sylvani wrote: February 5th, 2025, 10:21 pm Is this code able to be fixed? [...]
Here is one thing I noticed. Your 'backup' function contains the lines "nextset = 0" and "nextset = len(q)". But the variable nextset is global, so instead of changing the value of that global variable that will just make a local variable (leaving the global variable unaffected).
https://docs.python.org/3/reference/sim ... -statement
https://docs.python.org/3/reference/sim ... statements
There may be other occurrences of the same issue / other issues with the code.
127:1 B3/S234c User:Confocal/R (isotropic CA, incomplete)
Unlikely events happen.
My silence does not imply agreement, nor indifference. If I disagreed with something in the past, then please do not construe my silence as something that could change that.
User avatar
Katrina
Posts: 161
Joined: September 26th, 2024, 3:23 am

Re: Thread for your script-related questions

Post by Katrina »

confocaloid wrote: February 6th, 2025, 12:23 am But the variable nextset is global, so instead of changing the value of that global variable that will just make a local variable (leaving the global variable unaffected).
If I set nextset to not be global, then it says it cannot access it for some reason due to it being a local variable, even though it is defined outside the function

Edit: I was confusing it with another version I tried to write, so don't mind this.
User avatar
hth3
Posts: 362
Joined: February 15th, 2025, 10:04 am
Location: The Sun

Re: Thread for your script-related questions

Post by hth3 »

Stupid question but still going to ask: is there or can someone make a mobile compatible online OCA spaceship search program?
Can't trust someone who misspells typset as typeset.
Contribute to CheckerLife!
Oppose KOSA now, save the internet!
The Sandboxer Sandbox (Discord server)
RIP Unname New Web
User avatar
b-engine
Posts: 3762
Joined: October 26th, 2023, 4:11 am
Location: Somewhere on where Earth At
Contact:

Re: Thread for your script-related questions

Post by b-engine »

hth3 wrote: February 16th, 2025, 3:20 am Stupid question but still going to ask: is there or can someone make a mobile compatible online OCA spaceship search program?
RLifeSrc is an example, although a bit slow.
User avatar
eRroR_6o6
Posts: 384
Joined: August 15th, 2023, 1:24 am
Location: somewhere over the rainbow

Re: Thread for your script-related questions

Post by eRroR_6o6 »

How long would it normally take to search 1000000, 1000000000, or generally n soups while using apgsearch? (The specific version I'm using is v5, or apgluxe.)

Code: Select all

x = 19, y = 37, rule = B3/S23
13b3o$12b4o$11b2obobo$13bobo$15bo12$10b2o$bobo7bobo$o7b2o3b2o$o3bo2b3o
3bo$o6b4obo$o2bo7bo$3o12bobo$18bo$14bo3bo$14bo3bo$18bo$9bo5bo2bo$8b3o
5b3o2$10bo$2bobo4b2o$5bo2b3o$5bo2b3o$2bo2bo2b2obo$3b3o3b3o$10bo!
User avatar
confocaloid
Posts: 6697
Joined: February 8th, 2022, 3:15 pm
Location: learn to protect yourself against stray gliders and sparks and self-destruct mechanisms

Re: Thread for your script-related questions

Post by confocaloid »

eRroR_6o6 wrote: February 17th, 2025, 12:54 am How long would it normally take to search 1000000, 1000000000, or generally n soups while using apgsearch? (The specific version I'm using is v5, or apgluxe.)
Depends on several things, including on what kind of machine the program is running, and for which CA and symmetry type the program is compiled. It looks like there may be differences of one or two orders of magnitude merely due to the same version of apgsearch compiled/configured in the same way running on different machines. Further, plain B3/S23 should be significantly faster than general Life-like CA with "similar" level of chaoticness of soups, which should be significantly faster than general two-state range-1 isotropic, which should be significantly faster than Generations or ruletables/ruletrees. For some CA it depends on the symmetries of the generated soup since symmetric soups might often explode while breaking the symmetry can tame the chaos quickly. Sometimes it's the other way round and symmetric soups "behave better" than asymmetric soups.
127:1 B3/S234c User:Confocal/R (isotropic CA, incomplete)
Unlikely events happen.
My silence does not imply agreement, nor indifference. If I disagreed with something in the past, then please do not construe my silence as something that could change that.
User avatar
ElijahKen
Posts: 274
Joined: March 9th, 2024, 7:32 pm

Re: Thread for your script-related questions

Post by ElijahKen »

This is a simple question, but I don't know the answer. How do I run "make" for barrister? I am using windows, and have downloaded barrister, but cannot figure out how to "run make."
Engineering macro-spaceships is hard.
User avatar
Katrina
Posts: 161
Joined: September 26th, 2024, 3:23 am

Re: Thread for your script-related questions

Post by Katrina »

ElijahKen wrote: February 25th, 2025, 11:49 am This is a simple question, but I don't know the answer. How do I run "make" for barrister? I am using windows, and have downloaded barrister, but cannot figure out how to "run make."
No clue how else to help, but you can use something like Windows Subsystem for Linux to have access to make, because make is only on Linux (or Mac but I don't know anything about Mac)
User avatar
Katrina
Posts: 161
Joined: September 26th, 2024, 3:23 am

Re: Thread for your script-related questions

Post by Katrina »

Sylvani wrote: February 5th, 2025, 10:21 pm Is this code able to be fixed? It is meant to be a search program that has the same function as lifesrc. I am doing this so that people have an easy way to search for spaceships without having too much knowledge in programming.
There are 3 main problems I have that need to be solved.
1: Searching doesn't work perfectly. It does look like it is doing something in the code, but it never calls the backup function and the consistency function may be incorrect.
2: If you set the period above 1, it stops the script immediately after starting.
3: There is no implication function or anything because I don't know how to calculate the rules for it.

The reason why everything is calculated in numpy arrays is because there is no unknown state in Golly.

I've been working on this for days, I really need help with this.

Code: Select all

import math
import random
import golly as g
import numpy as np
from collections import deque
velx = 0
vely = 0

period = 1
width = 8
height = 8

neighbor = [(-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1)]

def tocells(n, x, y, z=0, w=0):
    c = []
    for q in np.argwhere(n>0.5):
        c.extend([q[0]+z,q[1]+w])
    return c

def toarray(c, x, y, z=0, w=0):
    n = np.zeros((x, y), dtype=np.int32)
    for i in range(0, len(c), 2):
        if 0 <= c[i]+z < x and 0 <= c[i+1]+w < y:
            n[c[i]+z, c[i+1]+w] = 1
    return n

def evolve(x, p, width=width, height=height):
    return toarray(g.evolve(tocells(x, width, height, 0, 0), p), width, height, 0, 0)

def display(r, x=0, y=0):
    if len(g.getrect()) != 0:
        g.select(g.getrect())
        g.clear(0)
        g.select([])
    g.putcells(g.transform(tocells(r, 0, 0), x, y))
    g.update()

cells = np.full((width, height, period), -1)
free = np.ones((width, height, period))
q = deque()
nextset = 0

def setcell(x, y, t, s, f):
    if cells[x, y, t] == s:
        return 1

    if cells[x, y, t] != -1:
        return 0

    cells[x, y, t] = s
    free[x, y, t] = f
    q.append([x, y, t, s, f])
    return 1

def consistify(x, y, t):
    t %= period
    prevcell = cells[x, y, t-1]
    nextprevcell = evolve(cells[:, :, t-1], 1)[x, y]
    if nextprevcell != cells[x, y, t]:
        if prevcell == 1:
            if cells[x, y, t] == 0:
                return 0
            cells[x, y, t] = 0
            free[x, y, t] = 0
            q.append([x, y, t, 1, 0])
        if prevcell == 0:
            if cells[x, y, t] == 1:
                return 0
            cells[x, y, t] = 1
            free[x, y, t] = 0
            q.append([x, y, t, 0, 0])
    if nextprevcell == 0 and cells[x, y, t] == 0 and setcell(x, y, t-1, 0, 0) != 1:
        return 0
    if nextprevcell == 1 and cells[x, y, t] == 1 and setcell(x, y, t-1, 1, 0) != 1:
        return 0
    s = -1
    if nextprevcell == 1 and cells[x, y, t] == -1:
        s = 0
    if nextprevcell == 0 and cells[x, y, t] == -1:
        s = 1
    if s == -1:
        return 1
    for i, j in neighbor:
        if 0 < x+i < width and 0 < y+j < height:
            if cells[x+i, y+j, t-1] == -1 and setcell(x+i, y+j, t-1, s, 0) != 1:
                return 0
    return 1

def consistify10(x, y, t):
    g.show(str(q))
    display(cells[:, :, 0])
    if consistify(x, y, t) != 1:
        return 0
    for i, j in neighbor:
        if 0 < x+i < width and 0 < y+j < height:
            if consistify(x+i, y+j, t+1) != 1:
                return 0
    return 1

def examinenext():
    if nextset == len(q):
        return 2
    cell = q.popleft()
    return consistify10(cell[0], cell[1], cell[2])

def proceed(x, y, t, s, f):
    if setcell(x, y, t, s, f) != 1:
        return 0
    while True:
        status = examinenext()
        if status == 0:
            return 0
        if status == 2:
            return 1

def backup():
    while len(q) != 0:
        cell = q.popleft()
        if cell[4] == 0:
            cells[cell[0], cell[1], cell[2]] = -1
            free[cell[0], cell[1], cell[2]] = 1
        else:
            nextset = len(q)
            return cell
    nextset = 0
    return "NULL"

def go(x, y, t, s, f):
    while True:
        status = proceed(x, y, t, s, f)
        if status == 1:
            return 1
        cell = backup()
        if cell == "NULL":
            return 0
        f = 0
        s = 1 - cells[x, y, t]
        cells[x, y, t] = -1

def getunknown():
    if len(np.argwhere(cells == -1)) != 0:
        return np.argwhere(cells == -1)[-1].tolist()
    return "NULL"

def search():
    cell = getunknown()
    if cell == "NULL":
        cell = backup()
        if cell == "NULL":
            return 0
        f = 0
        s = 1 - cell[3]
        cells[cell[0], cell[1], cell[2]] = -1
    else:
        f = 1
        s = 1
    while True:
        if go(cell[0], cell[1], cell[2], f, s) != 1:
            return 0

        cell = getunknown()
        if cell == "NULL":
            return 1
        f = 1
        s = 1

search()
Now that I think about it, a lot of people don't know where I am getting this stuff from (also this seems more like an advanced question so it might need to be moved or something idk) so here's a few links to where I am getting the basis for the code from, so that you know how to fix it:

https://github.com/DavidKinder/Xlife/tr ... lifesearch
-> https://github.com/DavidKinder/Xlife/bl ... rch/ORIGIN
-> https://github.com/DavidKinder/Xlife/bl ... h/search.c
-> https://github.com/DavidKinder/Xlife/bl ... /lifesrc.h
(The ones with arrows are very important, especially ORIGIN because it has the original plans/layout for the 1989 assembly version)
This is the only documentation I could find on the simpler original design and the full details on how it works.
User avatar
get_Snacked
Posts: 542
Joined: August 20th, 2022, 10:51 pm

Re: Thread for your script-related questions

Post by get_Snacked »

is there any place to learn how to make a program to pipe to apgluxe?
User avatar
confocaloid
Posts: 6697
Joined: February 8th, 2022, 3:15 pm
Location: learn to protect yourself against stray gliders and sparks and self-destruct mechanisms

Re: Thread for your script-related questions

Post by confocaloid »

127:1 B3/S234c User:Confocal/R (isotropic CA, incomplete)
Unlikely events happen.
My silence does not imply agreement, nor indifference. If I disagreed with something in the past, then please do not construe my silence as something that could change that.
User avatar
islptng
Posts: 495
Joined: May 24th, 2024, 6:17 am
Location: 种花家

Re: Thread for your script-related questions

Post by islptng »

Is there a program that receives min and max rules and returns a LLS rulestring?

Say, I want to convert this:

Code: Select all

B1e2ce3jr4et5y6c7c/S2ik3an4anqr5cijkq6c7e - B1e2cek3cejkqry4ceijkqty5eijknqry6acekn7c/S12aikn3aiknqy4aceknqrtwz5acijknqy6acekn78
My sandbox | All my engineered replicators | BsKngt | TNT
Asperger, ISTP, using a Dvorak keyboard.

I love my new school life.
wildmyron
Posts: 1571
Joined: August 9th, 2013, 12:45 am
Location: Western Australia

Re: Thread for your script-related questions

Post by wildmyron »

islptng wrote: March 29th, 2025, 3:01 am Is there a program that receives min and max rules and returns a LLS rulestring?
There is a script which does this posted to the LLS thread. It accepts the min rule and max rule as separate strings, but it would be simple to adapt it to accept a single string with a rule range.
There's a link to this script earlier in this thread which also references some other scripts related to LLS partial rule format.
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.
User avatar
hth3
Posts: 362
Joined: February 15th, 2025, 10:04 am
Location: The Sun

Re: Thread for your script-related questions

Post by hth3 »

Is there a LifeVíewer- or Web-based version of HyperConway?
Can't trust someone who misspells typset as typeset.
Contribute to CheckerLife!
Oppose KOSA now, save the internet!
The Sandboxer Sandbox (Discord server)
RIP Unname New Web
vilc
Posts: 311
Joined: March 20th, 2024, 4:36 pm

Re: Thread for your script-related questions

Post by vilc »

I compared the speed of JLS (1.7) and WLS (0.71) on the problem of finding every 1-generation predecessor of a nxn pattern in a (n+2)x(n+2) bounding box, but I am getting some odd results.
The test pattern :

Code: Select all

x = 3, y = 3
obo$3o$o!
Example solution :

Code: Select all

x = 5, y = 5, rule = LifeHistory
4.A$.DCD$ADCD$.2DC$2.3A!
The expected predecessor count is 13135, and both programs agree on it.

JLS takes 24ms to complete the search on my machine, but for some reason WLS takes 96s - 4000 times slower.

The main difference between the both seaches is the use of a border of UNSET cells in the first case, and UNCHECKED cells in the second (because UNSET cells apparently don't exist in WLS).
Am I using WLS improperly, or is it unsuited for this kind of search ?
Attached are my setup files.
Attachments
3x3_predecessor_search.zip
(1.2 KiB) Downloaded 21 times
User avatar
islptng
Posts: 495
Joined: May 24th, 2024, 6:17 am
Location: 种花家

Re: Thread for your script-related questions

Post by islptng »

How long will it take to generate a ruletree?
islptng wrote: April 1st, 2025, 7:34 pm This please
islptng wrote: April 1st, 2025, 2:43 am

Code: Select all

name = "ProgrammableLife"
n_states = 18
n_neighbors = 8
# order for 8 neighbors is NW, NE, SW, SE, N, W, E, S, C
def transition_function(a):
	nw,ne,sw,se,n,w,e,s,c = a
	if c not in [14,15]:
		# Test CGoL parts
		alivelist = [(i % 2 == 1) for i in a]
		self = alivelist[-1]
		alivelist = sum(alivelist[:-1])
		cgol = False
		if alivelist == 3: cgol = True
		if alivelist == 2 and self: cgol = True
		# Test Wire parts
		if c in [2,3,8,9]: check = [12,13]
		if c in [4,5,10,11]: check = [8,9]
		if c in [6,7,12,13]: check = [10,11]
		try: check
		except: return self // 2 * 2 + cgol
		wire = False
		if check[0] in [n,w,e,s]: wire = True
		if check[1] in [n,w,e,s]: wire = True
		if nw in check and n in [0,1] and w in [0,1]: wire = True
		if sw in check and s in [0,1] and w in [0,1]: wire = True
		if ne in check and n in [0,1] and e in [0,1]: wire = True
		if se in check and s in [0,1] and e in [0,1]: wire = True
		if n in check and w in check: wire = False
		if s in check and w in check: wire = False
		if n in check and e in check: wire = False
		if s in check and e in check: wire = False
		# combine together
		if c in [2,3,8,9]: retval = [2,3,8,9]
		if c in [4,5,10,11]: retval = [4,5,10,11]
		if c in [6,7,12,13]: retval = [6,7,12,13]
		return retval[wire * 2 + cgol]
	wire = 0
	for i in [8,9,10,11,12,13]:
		if i in [n,w,e,s]: wire = True
	return 14 + wire
EDIT: Must I provide a partial alongwith the .bin file when I want to continue ikpx2 search?
My sandbox | All my engineered replicators | BsKngt | TNT
Asperger, ISTP, using a Dvorak keyboard.

I love my new school life.
Chris857
Posts: 746
Joined: June 10th, 2020, 11:26 pm

Re: Thread for your script-related questions

Post by Chris857 »

I got a new Windows 11 laptop recently and have been setting up my Life stuff. In trying to run findpreds.py, the input() step to get the apgcode shows the "Apgcode:" prompt but doesn't seem to work or show what I type or paste in, and so it seems effectively stuck at that step. Running the individual commands of the script in a python interpreter seems to work up through that point and shows me my text input. I have tried both command prompt and powershell. Things worked fine on my previous Windows 10 laptop.
User avatar
confocaloid
Posts: 6697
Joined: February 8th, 2022, 3:15 pm
Location: learn to protect yourself against stray gliders and sparks and self-destruct mechanisms

Re: Thread for your script-related questions

Post by confocaloid »

Chris857 wrote: April 25th, 2025, 1:48 am I got a new Windows 11 laptop recently and have been setting up my Life stuff. In trying to run findpreds.py, the input() step to get the apgcode shows the "Apgcode:" prompt but doesn't seem to work or show what I type or paste in, and so it seems effectively stuck at that step. Running the individual commands of the script in a python interpreter seems to work up through that point and shows me my text input. I have tried both command prompt and powershell. Things worked fine on my previous Windows 10 laptop.
It may be a good idea to clarify the version of the script. Are you using version from viewtopic.php?p=147708#p147708 or different one?

Otherwise, it sounds like an OS-specific issue (judging from how input() fails to show what you type in, and how it worked on another laptop), and I'm not using the same system.

For some reason, the linked version of the script has two import lines, importing lifelib twice:

Code: Select all

import lifelib
# ...
import sys, os, lifelib, ssl, random
# ...
The moderator edit in the linked forum post seems misleading, the part "Golly 4.x-compatible Python 3 code" suggests that it's a Golly script, but the script appears to be intended to run outside Golly and there is no "import golly". EDIT by dvgrn: Thanks, adjusted this.
127:1 B3/S234c User:Confocal/R (isotropic CA, incomplete)
Unlikely events happen.
My silence does not imply agreement, nor indifference. If I disagreed with something in the past, then please do not construe my silence as something that could change that.
Chris857
Posts: 746
Joined: June 10th, 2020, 11:26 pm

Re: Thread for your script-related questions

Post by Chris857 »

That appears to be the one. I'm using python 3.13.3.

I have reduced the issue down to just:

Code: Select all

import lifelib
sess = lifelib.load_rules('b3s23')
rle = input("Apgcode: ")
print(rle)
If I don't have the load_rules() call, input() works fine, but with it there I get the issue with typing or pasting anything in.

I already installed lifelib, though I get an error at the end of lifelib.install_cygwin()

Code: Select all

Ending cygwin install
Verifying installation...
SUCCESS
Verifying numpy is installed...
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    lifelib.install_cygwin()
    ~~~~~~~~~~~~~~~~~~~~~~^^
  File "C:\Users\chris\AppData\Roaming\Python\Python313\site-packages\lifelib\autocompile.py", line 103, in install_cygwin
    verify_installation()
    ~~~~~~~~~~~~~~~~~~~^^
  File "C:\Users\chris\AppData\Roaming\Python\Python313\site-packages\lifelib\autocompile.py", line 115, in verify_installation
    np_version = subprocess.check_output(get_local_bash() + ['python3', '-c', 'import numpy as np; print(np.__version__)'])
  File "C:\Program Files\Python313\Lib\subprocess.py", line 472, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
               **kwargs).stdout
               ^^^^^^^^^
  File "C:\Program Files\Python313\Lib\subprocess.py", line 577, in run
    raise CalledProcessError(retcode, process.args,
                             output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['C:\\Users\\chris\\AppData\\Roaming\\Python\\Python313\\site-packages\\lifelib\\cygwin\\cygwin64\\bin\\bash.exe', 'C:\\Users\\chris\\AppData\\Roaming\\Python\\Python313\\site-packages\\lifelib\\cygbash.sh', 'python3', '-c', 'import numpy as np; print(np.__version__)']' returned non-zero exit status 1.
wildmyron
Posts: 1571
Joined: August 9th, 2013, 12:45 am
Location: Western Australia

Re: Thread for your script-related questions

Post by wildmyron »

Chris857 wrote: April 25th, 2025, 6:01 pm I already installed lifelib, though I get an error at the end of lifelib.install_cygwin()

Code: Select all

...
ModuleNotFoundError: No module named 'numpy'
...
This is the problem - the Python environment used to run lifelib commands does not have numpy installed.
Some background:
  • The lifelib Quikstart mentions that you need numpy, and also recommends jupyter
  • The python-lifelib package doesn't have numpy as a requirement (so it won't be automatically installed when you install python-lifelib)
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.
splitterrules
Posts: 106
Joined: April 11th, 2025, 6:11 pm

Re: Thread for your script-related questions

Post by splitterrules »

Is there an easy way so that for every spaceship in matchPatt2.txt, the number of rules which it works in is displayed next to the RLE? For example:
5, B3/S23, 1, 1, 4, o$b2o$2o!, 2^82
wildmyron
Posts: 1571
Joined: August 9th, 2013, 12:45 am
Location: Western Australia

Re: Thread for your script-related questions

Post by wildmyron »

splitterrules wrote: May 7th, 2025, 6:01 pm Is there an easy way so that for every spaceship in matchPatt2.txt, the number of rules which it works in is displayed next to the RLE? For example:
5, B3/S23, 1, 1, 4, o$b2o$2o!, 2^82
If you are using a recent (hah!) sss.py library from the 5S database then, yes, this is fairly easy. Here's a script which will read a matchPatt results file (or any other collection in sss format) and produce a new file with each line having the rulespace size appended. There's some file-handling stuff, minimal error checking and some sss manipulation, but the actual rulespace size measurement code is only a few lines near the end of the main processing loop. I think the output file will still be compatible with most of the 5S project scripts but I haven't tested it. Also, please note that any comments or other lines in the input file will not be reproduced in the output file.

Code: Select all

# sss_rulespace_count.py
# Script to post-process searchRule-matchPatt2.py results to add a count 
# of the rulespace size each result works in
# by Arie Paap, May 2025

import os.path
import golly as g
import sss

# Choose the input file and generate new output file name
filetypes = "sss Files (*.sss.txt;*.txt)|*.sss.txt;*.txt"
inputPath = g.opendialog("Choose spaceship file", filetypes)

(dirPath, inputFile) = os.path.split(inputPath)
(inputName, ext1) = os.path.splitext(inputFile)
(inputName, ext2) = os.path.splitext(inputName)

outputName = inputName+'_rsSize'
outputFile = outputName+ext2+ext1
outputPath = os.path.join(dirPath,outputFile)

if os.path.exists(outputPath):
  g.warn(f"Output file {outputFile} exists!\nClick 'OK' to continue (file will be overwritten).")

shipList = []
g.new('sss_rsSize')

with open(inputPath, 'r') as fIn:
  for line in fIn:
    # read in a ship from the input File
    ship = sss.parseshipstr(line)
    if not ship:
      continue
    minpop, rulestr, dx, dy, period, shiprle = ship
    
    # Clear the layer and place the ship
    r = g.getrect()
    if r:
        g.select(r)
        g.clear(0)
    shipPatt = g.parse(shiprle)
    g.putcells(shipPatt)
    g.setrule(rulestr)
 
    # Test the rulespace the ship works in
    b_need, s_need, b_OK, s_OK = sss.getRuleRangeElems(period)
    rsElemCount = len(b_OK)-len(b_need)+len(s_OK)-len(s_need)
    rsSize = f'2^{rsElemCount}'

    # Store the ship
    shipList.append( (minpop, rulestr, dx, dy, period, shiprle, rsSize) )

with open(outputPath, 'w') as fOut:
  for ship in shipList:
    fOut.write(', '.join(map(str, ship))+'\n')

g.show(f'Amended sss patterns written to file {outputFile}')
If you wish to modify the searchRule-matchPatt2.py script to directly output this amended format, you can do so with the following change (untested):

Code: Select all

            # sss.setminisorule(period)
            # newship = (minpop, g.getrule(), dx, dy, period, shipRLE)
            b_need, s_need, b_OK, s_OK = sss.getRuleRangeElems(period)
            g.setrule('B' + ''.join(sorted(b_need)) + '/S' + ''.join(sorted(s_need)))
            rsElemCount = len(b_OK)-len(b_need)+len(s_OK)-len(s_need)
            rsSize = f'2^{rsElemCount}'
            newship = (minpop, g.getrule(), dx, dy, period, shipRLE, rsSize)
Comment out those two lines near the end of the main loop and the replacement code.
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.
User avatar
Katrina
Posts: 161
Joined: September 26th, 2024, 3:23 am

Re: Thread for your script-related questions

Post by Katrina »

Is there any possibility that a new algorithm could be found that beats gfind, LLSSS, or ikpx2 in its speed or efficiency?
User avatar
LuveelVoom
Posts: 534
Joined: April 27th, 2022, 7:59 pm

Re: Thread for your script-related questions

Post by LuveelVoom »

Sylvani wrote: May 15th, 2025, 10:28 am Is there any possibility that a new algorithm could be found that beats gfind, LLSSS, or ikpx2 in its speed or efficiency?
There’s a known general improvement to all of the SAT-solver based programs: Grover’s algorithm, which provides a quadratic speedup. Unfortunately, it requires a fairly large quantum computer to use, which is not currently available. Other than that, I’m sure there are algorithms waiting out there somewhere. It’s just a matter of actually finding them.
Post Reply