Thread for your script-related questions

For scripts to aid with computation or simulation in cellular automata.
User avatar
wwei47
Posts: 1603
Joined: February 18th, 2021, 11:18 am

Re: Thread for your script-related questions

Post by wwei47 » April 30th, 2022, 10:21 am

LLAMASKYWALKER wrote:
April 30th, 2022, 1:38 am
I literally am not changing anything at all. I just hit start.
Try this.
Press Ctrl-P. This will bring up the "Properties" box under the "Edit field" tab. In the top left, there will be a panel labeled "Dimensions". You will see three numbers set to 35, 15, and 4 respectively. Change the first one to 5 and the second one to 6. Now, click the "Tiling/translation" tab. See the "After the last generation is..." panel? There are two numbers set to 0 and 0 by default. Change the second one to -2.

Now, you want to set the search order to make the search faster. It won't matter here when the box is so small, but it will make a HUGE difference with larger searches. Press Ctrl-T to open the "Options..." box. Go to the "Sorting" tab. The "Area" panel is our interest this time. Observe that one box is yellow-the one labeled "Horizontal". Click the one labeled "Vertical" to make it yellow instead.

Now, let's specify a cell for JLS to start from. In generation 0, click the cell in column 2 and cell 1 to set it to "on"; this tells JLS to look for ships where this cell is on.

Now, press Ctrl-G. If all went well, you've just found the LWSS!
Help me find high-period c/2 technology!
My guide: https://bit.ly/3uJtzu9
My c/2 tech collection: https://bit.ly/3qUJg0u
Overview of periods: https://bit.ly/3LwE0I5
Most wanted periods: 76,116

User avatar
LLAMASKYWALKER
Posts: 168
Joined: December 2nd, 2021, 1:02 pm

Re: Thread for your script-related questions

Post by LLAMASKYWALKER » April 30th, 2022, 11:09 am

wwei47 wrote:
April 30th, 2022, 10:21 am
LLAMASKYWALKER wrote:
April 30th, 2022, 1:38 am
I literally am not changing anything at all. I just hit start.
Try this.
Press Ctrl-P. This will bring up the "Properties" box under the "Edit field" tab. In the top left, there will be a panel labeled "Dimensions". You will see three numbers set to 35, 15, and 4 respectively. Change the first one to 5 and the second one to 6. Now, click the "Tiling/translation" tab. See the "After the last generation is..." panel? There are two numbers set to 0 and 0 by default. Change the second one to -2.

Now, you want to set the search order to make the search faster. It won't matter here when the box is so small, but it will make a HUGE difference with larger searches. Press Ctrl-T to open the "Options..." box. Go to the "Sorting" tab. The "Area" panel is our interest this time. Observe that one box is yellow-the one labeled "Horizontal". Click the one labeled "Vertical" to make it yellow instead.

Now, let's specify a cell for JLS to start from. In generation 0, click the cell in column 2 and cell 1 to set it to "on"; this tells JLS to look for ships where this cell is on.

Now, press Ctrl-G. If all went well, you've just found the LWSS!

thx! wait can it find puffers and how do i make a .lif file?

Code: Select all

x = 5, y = 5, rule = B3/S12o3H
bo$2obo$3bo$b2obo$3bo!

Code: Select all

x = 15, y = 11, rule = 23/34/10
2$6.F.B$5.GICDA$4.H3I2D2A$4.I3.GF2A$7.FAD2A$8.2A!

Code: Select all

x = 8, y = 14, rule = B3-q4z5y/S234k5j
4b2o$4bo2bo$5b3o7$2o2b3o$2obo3bo$3bo3bo$3bo3bo$4b3o!
CGoL is my hobby

User avatar
wwei47
Posts: 1603
Joined: February 18th, 2021, 11:18 am

Re: Thread for your script-related questions

Post by wwei47 » April 30th, 2022, 11:47 am

LLAMASKYWALKER wrote:
April 30th, 2022, 11:09 am
thx! wait can it find puffers and how do i make a .lif file?
Ctrl-T again. This time check the "Append solutions to file" box and click the "Browse..." button, and type in the name of the file you want. If it doesn't exist, JLS will create it for you once it finds a solution.

JLS isn't exactly for puffers. I have found a few puffers with it, but I've almost always done so by running a spaceship search for a stabilization of an engine that I found with some other method. The few exceptions were "I was watching JLS and saw a thin connection so I tried pausing (Esc key), taking off the back, and it started puffing on me.".
Help me find high-period c/2 technology!
My guide: https://bit.ly/3uJtzu9
My c/2 tech collection: https://bit.ly/3qUJg0u
Overview of periods: https://bit.ly/3LwE0I5
Most wanted periods: 76,116

User avatar
LLAMASKYWALKER
Posts: 168
Joined: December 2nd, 2021, 1:02 pm

Re: Thread for your script-related questions

Post by LLAMASKYWALKER » April 30th, 2022, 11:51 am

wwei47 wrote:
April 30th, 2022, 11:47 am
LLAMASKYWALKER wrote:
April 30th, 2022, 11:09 am
thx! wait can it find puffers and how do i make a .lif file?
Ctrl-T again. This time check the "Append solutions to file" box and click the "Browse..." button, and type in the name of the file you want. If it doesn't exist, JLS will create it for you once it finds a solution.

JLS isn't exactly for puffers. I have found a few puffers with it, but I've almost always done so by running a spaceship search for a stabilization of an engine that I found with some other method. The few exceptions were "I was watching JLS and saw a thin connection so I tried pausing (Esc key), taking off the back, and it started puffing on me.".
ok thx

Code: Select all

x = 5, y = 5, rule = B3/S12o3H
bo$2obo$3bo$b2obo$3bo!

Code: Select all

x = 15, y = 11, rule = 23/34/10
2$6.F.B$5.GICDA$4.H3I2D2A$4.I3.GF2A$7.FAD2A$8.2A!

Code: Select all

x = 8, y = 14, rule = B3-q4z5y/S234k5j
4b2o$4bo2bo$5b3o7$2o2b3o$2obo3bo$3bo3bo$3bo3bo$4b3o!
CGoL is my hobby

User avatar
LLAMASKYWALKER
Posts: 168
Joined: December 2nd, 2021, 1:02 pm

Re: Thread for your script-related questions

Post by LLAMASKYWALKER » April 30th, 2022, 11:52 am

might not belong here but how do i change my username on catagolue

Code: Select all

x = 5, y = 5, rule = B3/S12o3H
bo$2obo$3bo$b2obo$3bo!

Code: Select all

x = 15, y = 11, rule = 23/34/10
2$6.F.B$5.GICDA$4.H3I2D2A$4.I3.GF2A$7.FAD2A$8.2A!

Code: Select all

x = 8, y = 14, rule = B3-q4z5y/S234k5j
4b2o$4bo2bo$5b3o7$2o2b3o$2obo3bo$3bo3bo$3bo3bo$4b3o!
CGoL is my hobby

User avatar
yujh
Posts: 2861
Joined: February 27th, 2020, 11:23 pm
Location: I'm not sure where I am, so please tell me if you know
Contact:

Re: Thread for your script-related questions

Post by yujh » April 30th, 2022, 12:07 pm

LLAMASKYWALKER wrote:
April 30th, 2022, 11:52 am
might not belong here but how do i change my username on catagolue
your key or your username on the comments section?

User avatar
LLAMASKYWALKER
Posts: 168
Joined: December 2nd, 2021, 1:02 pm

Re: Thread for your script-related questions

Post by LLAMASKYWALKER » April 30th, 2022, 12:08 pm

yujh wrote:
April 30th, 2022, 12:07 pm
LLAMASKYWALKER wrote:
April 30th, 2022, 11:52 am
might not belong here but how do i change my username on catagolue
your key or your username on the comments section?
username, it will not let me log into my new key

Code: Select all

x = 5, y = 5, rule = B3/S12o3H
bo$2obo$3bo$b2obo$3bo!

Code: Select all

x = 15, y = 11, rule = 23/34/10
2$6.F.B$5.GICDA$4.H3I2D2A$4.I3.GF2A$7.FAD2A$8.2A!

Code: Select all

x = 8, y = 14, rule = B3-q4z5y/S234k5j
4b2o$4bo2bo$5b3o7$2o2b3o$2obo3bo$3bo3bo$3bo3bo$4b3o!
CGoL is my hobby

User avatar
LLAMASKYWALKER
Posts: 168
Joined: December 2nd, 2021, 1:02 pm

Re: Thread for your script-related questions

Post by LLAMASKYWALKER » May 2nd, 2022, 5:47 pm

Is there a way to simulate 3d ca?

Code: Select all

x = 5, y = 5, rule = B3/S12o3H
bo$2obo$3bo$b2obo$3bo!

Code: Select all

x = 15, y = 11, rule = 23/34/10
2$6.F.B$5.GICDA$4.H3I2D2A$4.I3.GF2A$7.FAD2A$8.2A!

Code: Select all

x = 8, y = 14, rule = B3-q4z5y/S234k5j
4b2o$4bo2bo$5b3o7$2o2b3o$2obo3bo$3bo3bo$3bo3bo$4b3o!
CGoL is my hobby

User avatar
ClippyCosmologist
Posts: 11
Joined: May 7th, 2022, 5:24 pm

Re: Thread for your script-related questions

Post by ClippyCosmologist » May 16th, 2022, 5:43 pm

On the LifeWiki page for the x66, it says
Its name refers to the fact that every cell (alive or dead) has at most 6 live neighbours (in contrast to spaceships based on lightweight spaceships, middleweight spaceships, or heavyweight spaceships). In fact, this spaceship was found via a search with this restriction. From this follows that the spaceship is stable also in Life-like rules allowing birth or survival for a cell with 7 or 8 neighbors.
What scripts can perform such restricted searches?
"Human beings, five hundred years after the Scientific Revolution, are only just starting to match their wits against the billion-year heritage of biology." -- E. Yudkowsky

User avatar
NimbleRogue
Posts: 120
Joined: January 11th, 2021, 11:48 pm

Re: Thread for your script-related questions

Post by NimbleRogue » May 17th, 2022, 1:10 am

I'm finally getting around to using the command line for apgmera, ikpx, and the like. I built the command line in visual studio and I'm wondering how to get the programs to start running. Any help? Thanks.
"I don't tell you how to tell me what to do, so don't tell me how to do what you tell me to do."- Bender Rodriguez

User avatar
silversmith
Posts: 203
Joined: June 15th, 2020, 6:20 pm
Contact:

Re: Thread for your script-related questions

Post by silversmith » May 17th, 2022, 6:56 pm

To start off the simplest way to get the program is to setup git on your command line environment. You can do so by typing the “git” command and see if it is recognized. Then you would clone the repo, which is done by navigating to the folder where you want to put the program, and then running the command to actually clone the repo. For apgmera the command would be:

Code: Select all

./git clone ‘https://gitlab.com/apgoucher/apgmera’
To clone other projects replace the url with the url of another git-based repository.

The front page of most program repos includes information on how to run it, for example:
https://gitlab.com/apgoucher/ikpx2
https://gitlab.com/apgoucher/apgmera

If you want to be credited with contributions to the catagolue website, first log in with a google account, then setup a payosha256 key to be used with your ikpx2 or apgmera searches. For more info goto https://conwaylife.com/wiki/Tutorials/C ... _Catagolue.

Examples
Ikpx2

Code: Select all

./recompile.sh --rule b38s23
./ikpx2 --velocity 'c/3'
Apgmera

Code: Select all

./apgluxe -n 20000000 --rule b38s23
A simulator with the tools I couldn’t find elsewhere: https://www.silversimulations.com/arise/

User avatar
NimbleRogue
Posts: 120
Joined: January 11th, 2021, 11:48 pm

Re: Thread for your script-related questions

Post by NimbleRogue » May 19th, 2022, 11:32 pm

I realized that the root of my problem was that I needed to build Clang, when I tried to I got this error, any help?

Code: Select all

CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_ASM_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
"I don't tell you how to tell me what to do, so don't tell me how to do what you tell me to do."- Bender Rodriguez

User avatar
pzq_alex
Posts: 402
Joined: May 1st, 2021, 9:00 pm
Location: in the life universe

Re: Thread for your script-related questions

Post by pzq_alex » May 20th, 2022, 6:11 am

ClippyCosmologist wrote:
May 16th, 2022, 5:43 pm
On the LifeWiki page for the x66, it says
Its name refers to the fact that every cell (alive or dead) has at most 6 live neighbours (in contrast to spaceships based on lightweight spaceships, middleweight spaceships, or heavyweight spaceships). In fact, this spaceship was found via a search with this restriction. From this follows that the spaceship is stable also in Life-like rules allowing birth or survival for a cell with 7 or 8 neighbors.
What scripts can perform such restricted searches?
gfind has parameters called /xN and /zN. The former disallows BN, and the latter disallows SN.

None of its descendants (zfind, qfind, etc.) have this capability, though.
Make b38s23/C1 great again!
https://catagolue.hatsya.com/census/b3a ... a4ity6c/C1
救救kench
Working on a spaceship search program…
Stop turning this forum into a place for politics. Please.

Code: Select all

x=4,y=3,rule=B3S2-i3-a4ciz5j6c8
bo$3o$ob2o!

User avatar
AlbertArmStain
Posts: 133
Joined: January 28th, 2022, 7:18 pm

Re: Thread for your script-related questions

Post by AlbertArmStain » May 20th, 2022, 5:04 pm

Where do you run scripts on the computer?

Code: Select all

x = 17, y = 22, rule = B3/S23
8bo4bo$9bob2o$7b3o2b2o2$7bo$2b2obo3bo$2bo$3b2o$3o2b7o$o2bo6b2o$b2o8b2o
$12bo2$12b3o$8bo2b4o$6b3o6bo$5bo4b6o$6b5o5bo$8bo2b5o$11bo$13bo$12b2o!

User avatar
silversmith
Posts: 203
Joined: June 15th, 2020, 6:20 pm
Contact:

Re: Thread for your script-related questions

Post by silversmith » May 21st, 2022, 8:34 am

AlbertArmStain wrote:
May 20th, 2022, 5:04 pm
Where do you run scripts on the computer?
Usually through a terminal/command line application. Sometimes through golly.

It depends on what script I am trying to run.
A simulator with the tools I couldn’t find elsewhere: https://www.silversimulations.com/arise/

User avatar
pzq_alex
Posts: 402
Joined: May 1st, 2021, 9:00 pm
Location: in the life universe

Re: Thread for your script-related questions

Post by pzq_alex » June 6th, 2022, 8:03 am

affamatodidio wrote:
June 6th, 2022, 7:57 am
pzq_alex wrote:
June 6th, 2022, 7:52 am
(my previous post)
You can try LLS.
I have attempted to set up LLS before, and failed. I followed every step to a tee a second time, and it still failed. If LLS is the only way to accomplish the question I have posited in my original post, then I will take my requests to the ¨Requests - Non-APGsearch¨ thread.
What’s the problem, precisely? Also, these posts should better fit the “Thread for your script related questions”.

LLS is pretty standard for these kind of problems, and I’m currently unaware of other methods.
Make b38s23/C1 great again!
https://catagolue.hatsya.com/census/b3a ... a4ity6c/C1
救救kench
Working on a spaceship search program…
Stop turning this forum into a place for politics. Please.

Code: Select all

x=4,y=3,rule=B3S2-i3-a4ciz5j6c8
bo$3o$ob2o!

User avatar
NimbleRogue
Posts: 120
Joined: January 11th, 2021, 11:48 pm

Re: Thread for your script-related questions

Post by NimbleRogue » June 16th, 2022, 9:13 pm

What's a good script for extending oscillator(specifically sparker) partials?
"I don't tell you how to tell me what to do, so don't tell me how to do what you tell me to do."- Bender Rodriguez

atavoidirc
Posts: 8
Joined: April 14th, 2022, 3:09 pm

Re: Thread for your script-related questions

Post by atavoidirc » June 22nd, 2022, 5:13 pm

How do you apgsearch custom rules?

User avatar
Ian07
Posts: 808
Joined: September 22nd, 2018, 8:48 am

Re: Thread for your script-related questions

Post by Ian07 » June 22nd, 2022, 6:18 pm

atavoidirc wrote:
June 22nd, 2022, 5:13 pm
How do you apgsearch custom rules?
First, copy the rule file into somewhere in the apgmera folder, ideally in /lifelib/rules/source. Then, it can be invoked like so:

Code: Select all

./apgluxe --rule 'lifelib/rules/source/KnightGoL.table'
.rule, .tree, .table, and .ruel (i.e. Nutshell) files are all supported.

Some caveats:
  • apgsearch is only able to generate soups with state 0 and 1 cells. If the rule is designed such that a pattern consisting entirely of those states can never produce states 2+, you may need to modify it by moving all the states over by one and creating a new state 1 that turns itself into other states based on neighbor count. EDIT: Actually, a better way to do this might be using a stdin symmetry to input custom soups which can, in fact, start off with multiple states. Luckily, there's a tutorial on the wiki for this. A practical example can be found here - notice how the sample occurrences do not look like typical RLEs generated by SHA-256.
  • apgsearch assumes when making apgcodes that the rule is isotropic, so the symmetry should be either "rotate4reflect" or "permute".
The resulting census on Catagolue will start with an "x" and may or may not contain additional numbers at the beginning to indicate capitals in the rule name, as seen here.

confocaloid
Posts: 166
Joined: February 8th, 2022, 3:15 pm

Re: Thread for your script-related questions

Post by confocaloid » June 29th, 2022, 5:46 am

Is there a tool that can be used to determine and display the minimum repeat time/best compression of a spaceship - something that outputs 14 for the glider and the LWSS, 16 for the MWSS and 196 for Sir Robin? E.g. neither LifeViewer nor Catagolue provide this information (although I understand this might be in general prohibitively costly to compute).

User avatar
Ian07
Posts: 808
Joined: September 22nd, 2018, 8:48 am

Re: Thread for your script-related questions

Post by Ian07 » June 29th, 2022, 1:50 pm

confocaloid wrote:
June 29th, 2022, 5:46 am
Is there a tool that can be used to determine and display the minimum repeat time/best compression of a spaceship - something that outputs 14 for the glider and the LWSS, 16 for the MWSS and 196 for Sir Robin? E.g. neither LifeViewer nor Catagolue provide this information (although I understand this might be in general prohibitively costly to compute).
Another script I made years ago (June 26, 2020) and never bothered to publish until now:

Code: Select all

import golly as g
from glife import rect, pattern
from time import time

# --------------------------------------------------------------------

# initialize lists
hashlist = []        # for pattern hash values
genlist = []         # corresponding generation counts
poplist = []         # corresponding population counts
boxlist = []         # corresponding bounding boxes

# --------------------------------------------------------------------

pat = g.getcells(g.getrect())
p = 0

# --------------------------------------------------------------------

def oscillating():
    # return True if the pattern is empty, stable or oscillating

    # first get current pattern's bounding box
    prect = g.getrect()
    pbox = rect(prect)
    if pbox.empty:
        g.show("The pattern is empty.")
        return True

    # get current pattern and create hash of "normalized" version -- ie. shift
    # its top left corner to 0,0 -- so we can detect spaceships and knightships
    ## currpatt = pattern( g.getcells(prect) )
    ## h = hash( tuple( currpatt(-pbox.left, -pbox.top) ) )

    # use Golly's hash command (3 times faster than above code)
    h = g.hash(prect)

    # check if outer-totalistic rule has B0 but not S8
    rule = g.getrule().split(":")[0]
    hasB0notS8 = rule.startswith("B0") and (rule.find("/") > 1) and not rule.endswith("8")

    # determine where to insert h into hashlist
    pos = 0
    listlen = len(hashlist)
    while pos < listlen:
        if h > hashlist[pos]:
            pos += 1
        elif h < hashlist[pos]:
            # shorten lists and append info below
            del hashlist[pos : listlen]
            del genlist[pos : listlen]
            del poplist[pos : listlen]
            del boxlist[pos : listlen]
            break
        else:
            # h == hashlist[pos] so pattern is probably oscillating, but just in
            # case this is a hash collision we also compare pop count and box size
            if (int(g.getpop()) == poplist[pos]) and \
               (pbox.wd == boxlist[pos].wd) and \
               (pbox.ht == boxlist[pos].ht):
                period = int(g.getgen()) - genlist[pos]

                if hasB0notS8 and (period % 2 > 0) and (pbox == boxlist[pos]):
                    # ignore this hash value because B0-and-not-S8 rules are
                    # emulated by using different rules for odd and even gens,
                    # so it's possible to have identical patterns at gen G and
                    # gen G+p if p is odd
                    return False

                if pbox == boxlist[pos]:
                    # pattern hasn't moved
                    if period == 1:
                        g.show("The pattern is stable.")
                    else:
                        g.show("Oscillator detected (period = " + str(period) + ")")
                else:
                    global p
                    p = period
                return True
            else:
                # look at next matching hash value or insert if no more
                pos += 1

    # store hash/gen/pop/box info at same position in various lists
    hashlist.insert(pos, h)
    genlist.insert(pos, int(g.getgen()))
    poplist.insert(pos, int(g.getpop()))
    boxlist.insert(pos, pbox)

    return False

# --------------------------------------------------------------------

def fit_if_not_visible():
    # fit pattern in viewport if not empty and not completely visible
    r = rect(g.getrect())
    if (not r.empty) and (not r.visible()): g.fit()

# --------------------------------------------------------------------

def check_repeat_time(n):
    g.show("Checking for repeat time " + str(n))

    g.new("test")
    g.putcells(pat)
    g.run(n)
    g.putcells(pat, 0, 0, 1, 0, 0, 1, "xor")
    test_hash = g.hash(g.getrect())

    g.run(p)

    if len(g.getrect()) == 0: return False
    current_hash = g.hash(g.getrect())

    return current_hash == test_hash


g.show("Checking for oscillation... (hit escape to abort)")

oldsecs = time()
while not oscillating():
    g.run(1)
    newsecs = time()
    if newsecs - oldsecs >= 1.0:     # show pattern every second
        oldsecs = newsecs
        fit_if_not_visible()
        g.update()

fit_if_not_visible()

i = 1
while not check_repeat_time(i):
    i += 1

g.show(str(i))
I also made a "lazy" version that essentially does a binary search instead, although as a result it's not guaranteed to output the correct answer:

Code: Select all

import golly as g
from glife import rect, pattern
from time import time

# --------------------------------------------------------------------

# initialize lists
hashlist = []        # for pattern hash values
genlist = []         # corresponding generation counts
poplist = []         # corresponding population counts
boxlist = []         # corresponding bounding boxes

# --------------------------------------------------------------------

pat = g.getcells(g.getrect())
p = 0

# --------------------------------------------------------------------

def oscillating():
    # return True if the pattern is empty, stable or oscillating

    # first get current pattern's bounding box
    prect = g.getrect()
    pbox = rect(prect)
    if pbox.empty:
        g.show("The pattern is empty.")
        return True

    # get current pattern and create hash of "normalized" version -- ie. shift
    # its top left corner to 0,0 -- so we can detect spaceships and knightships
    ## currpatt = pattern( g.getcells(prect) )
    ## h = hash( tuple( currpatt(-pbox.left, -pbox.top) ) )

    # use Golly's hash command (3 times faster than above code)
    h = g.hash(prect)

    # check if outer-totalistic rule has B0 but not S8
    rule = g.getrule().split(":")[0]
    hasB0notS8 = rule.startswith("B0") and (rule.find("/") > 1) and not rule.endswith("8")

    # determine where to insert h into hashlist
    pos = 0
    listlen = len(hashlist)
    while pos < listlen:
        if h > hashlist[pos]:
            pos += 1
        elif h < hashlist[pos]:
            # shorten lists and append info below
            del hashlist[pos : listlen]
            del genlist[pos : listlen]
            del poplist[pos : listlen]
            del boxlist[pos : listlen]
            break
        else:
            # h == hashlist[pos] so pattern is probably oscillating, but just in
            # case this is a hash collision we also compare pop count and box size
            if (int(g.getpop()) == poplist[pos]) and \
               (pbox.wd == boxlist[pos].wd) and \
               (pbox.ht == boxlist[pos].ht):
                period = int(g.getgen()) - genlist[pos]

                if hasB0notS8 and (period % 2 > 0) and (pbox == boxlist[pos]):
                    # ignore this hash value because B0-and-not-S8 rules are
                    # emulated by using different rules for odd and even gens,
                    # so it's possible to have identical patterns at gen G and
                    # gen G+p if p is odd
                    return False

                if pbox == boxlist[pos]:
                    # pattern hasn't moved
                    if period == 1:
                        g.show("The pattern is stable.")
                    else:
                        g.show("Oscillator detected (period = " + str(period) + ")")
                else:
                    global p
                    p = period
                return True
            else:
                # look at next matching hash value or insert if no more
                pos += 1

    # store hash/gen/pop/box info at same position in various lists
    hashlist.insert(pos, h)
    genlist.insert(pos, int(g.getgen()))
    poplist.insert(pos, int(g.getpop()))
    boxlist.insert(pos, pbox)

    return False

# --------------------------------------------------------------------

def fit_if_not_visible():
    # fit pattern in viewport if not empty and not completely visible
    r = rect(g.getrect())
    if (not r.empty) and (not r.visible()): g.fit()

# --------------------------------------------------------------------

def check_repeat_time(n):
    g.show("Checking for repeat time " + str(n))

    g.new("test")
    g.putcells(pat)
    g.run(n)
    g.putcells(pat, 0, 0, 1, 0, 0, 1, "xor")
    test_hash = g.hash(g.getrect())

    g.run(p)

    if len(g.getrect()) == 0: return False
    current_hash = g.hash(g.getrect())

    return current_hash == test_hash


g.show("Checking for oscillation... (hit escape to abort)")

oldsecs = time()
while not oscillating():
    g.run(1)
    newsecs = time()
    if newsecs - oldsecs >= 1.0:     # show pattern every second
        oldsecs = newsecs
        fit_if_not_visible()
        g.update()

fit_if_not_visible()

i = 1
while not check_repeat_time(i):
    i *= 2

factor = i/4
i -= factor

while factor != 1:
    factor /= 2
    if check_repeat_time(int(i)):
        i -= factor
    else:
        i += factor

g.show(str(i))
In fact, it appears to be buggy. Inputting Sir Robin correctly outputs 196 with the first script, but 195 with the second one, causing the two spaceships to collide.

Post Reply