Help needed with rectangle lists

For scripts to aid with computation or simulation in cellular automata.
Post Reply
User avatar
Saka
Posts: 3409
Joined: June 19th, 2015, 8:50 pm
Location: In the kingdom of Sultan Hamengkubuwono X
Contact:

Help needed with rectangle lists

Post by Saka » December 1st, 2016, 3:43 am

I'm writing a simple script but I have encountered an error: Index is out of range or something like that. I know what it means, but I don't know why it's happening. The most curious thing is that the script works fine in Life and HighLife, but not in other rules, like Day and Night. The problematic part of the code:

Code: Select all

while True:
    rand = r.randrange(10, 80)
    g.randfill(rand)
    g.run(5000)
    oldbounds = g.getrect()
    g.run(100)
    newbounds = g.getrect()
    if oldbounds[2] != newbounds[2] or oldbounds[3] != newbounds[3]:
        break

Code: Select all

o3b2ob2obo3b2o2b2o$bo3b2obob3o3bo2bo$2bo2b3o5b3ob4o$3o3bo2bo2b3o3b3o$
4bo4bobo4bo$2o2b2o2b4obo2bo3bo$2ob4o3bo2bo2bo2bo$b2o3bobob2o$3bobobo5b
obobobo$3bobobob2o3bo2bobo!
(Check gen 3)
Add your computer to the Table of Lifeenthusiast Computers!

wildmyron
Posts: 1397
Joined: August 9th, 2013, 12:45 am

Re: Help needed with rectangle lists

Post by wildmyron » December 1st, 2016, 4:41 am

Saka wrote:I'm writing a simple script but I have encountered an error: Index is out of range or something like that. I know what it means, but I don't know why it's happening. The most curious thing is that the script works fine in Life and HighLife, but not in other rules, like Day and Night. The problematic part of the code:

Code: Select all

while True:
    rand = r.randrange(10, 80)
    g.randfill(rand)
    g.run(5000)
    oldbounds = g.getrect()
    g.run(100)
    newbounds = g.getrect()
    if oldbounds[2] != newbounds[2] or oldbounds[3] != newbounds[3]:
        break
The error most likely occurs when the pattern dies out and the population is 0. In this instance g.getrect() will return an empty array and indexing into it will fail. You should test if newbounds is empty before testing the bounding box dimensions.

It's difficult to say if this is the problem because you haven't provided the error message. Even though it doesn't look like it, you can copy the error message with 'Ctrl C' (on Windows). Presumably, the error message was something like this:

Code: Select all

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\ariep\AppData\Roaming\Golly\golly_clip.py", line 14, in <module>
    if oldbounds[2] != newbounds[2] or oldbounds[3] != newbounds[3]:
IndexError: list index out of range
The latest version of the 5S Project contains over 226,000 spaceships. There is also a GitHub mirror of the collection. Tabulated pages up to period 160 (out of date) are available on the LifeWiki.

Post Reply