Random Rule

For scripts to aid with computation or simulation in cellular automata.
Post Reply
User avatar
Hektor
Posts: 89
Joined: November 3rd, 2011, 2:37 pm

Random Rule

Post by Hektor » February 4th, 2012, 8:26 am

Hi everyone, I was writing a script for setting a random rule in golly.
The program runs fine, but nothing changes...
Where am I wrong?

Code: Select all

import golly as g
import random

numB = random.randint(0,9)	#The number of rules for a cell to be born. For example b123/... has three rules
numS = random.randint(0,9)	#Same with survival rules. b.../s012345678 has nine rules

borns = ["0","1","2","3","4","5","6","7","8"]
survs = ["0","1","2","3","4","5","6","7","8"]

b = []
s = []

for i in xrange(0,numB):
	newb = random.choice(borns)		#Choose a number from all the possible number of neighbours
	borns.remove(newb)				#Removes it from the list for preventing duplicates like b33/s23
	b.append(newb)					#Append the number to b
			
for j in xrange(0,numB):
	news = random.choice(survs)
	survs.remove(news)
	s.append(news)
			

b.sort()	#Sort numerically the lists
s.sort()	

b = "".join(b)	#Make strings from them
s = "".join(s)

rule = "b{0}/s{1}".format(str(b),str(s))
g.exit(rule)
g.setrule(rule)

beebop
Posts: 44
Joined: October 13th, 2011, 9:53 pm
Contact:

Re: Random Rule

Post by beebop » February 4th, 2012, 1:06 pm

Try taking out the g.exit() call.

User avatar
Hektor
Posts: 89
Joined: November 3rd, 2011, 2:37 pm

Re: Random Rule

Post by Hektor » February 4th, 2012, 1:13 pm

Thanks, I would have never thought that! :D

Post Reply