For scripts to aid with computation or simulation in cellular automata.
-
Saka
- Posts: 3627
- Joined: June 19th, 2015, 8:50 pm
- Location: Indonesia
-
Contact:
-
Quote
-
Login to like this post
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
-
wildmyron
- Posts: 1544
- Joined: August 9th, 2013, 12:45 am
- Location: Western Australia
-
Quote
-
Login to like this post
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
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.