I'm trying to modify a python script that models a version of Conway's game of life. In which a set of cells in X number of columns and Y number of rows are each given a value that determines if they will switch between two states of active or dormant depending on the state of their neighbors.
Right now the initial values for these cells are defined by this definition, which references a number of variables set by the user. (this isnt the full script, just what I think is relevant)
def randomizeArray(intLength,intWidth):
arr = []
for j in range(intWidth):
arri = []
for i in range(intLength):
rnd =random.random()
arri.append(rnd)
arr.append(arri)
print rnd
return arr
def Main():
intLength = rs.GetInteger("how many in x",30)
intWidth = rs.GetInteger("how many in y",30)
intGen = rs.GetInteger("how many generations",40)
strStack = rs.GetString ("should I stack the generations", "yes", ["yes", "no"])
crvs = rs.GetObjects("select the crvs",4)
thres = rs.GetReal("type the threshold to voxelize",1)
allValues = []
arrValues = randomizeArray(intLength,intWidth)
for i in range(40):
arrValues = applyGOL(arrValues)
allValues.append(arrValues)
#arrMeshes = render(arrValues,-1, strStack)
for i in range(intGen-1):
arrValues = applyGOLCrvs(arrValues, i, crvs)
allValues.append(arrValues)
"""
if strStack == "no" :
update(arrMeshes, arrValues)
else :
render(arrValues,i, strStack)
"""
myVoxels = voxels(intLength,intWidth,intGen, allValues)
myVoxels.voxelize(thres)
#Call DeleteObjects2dArray(arrMeshes)
Main()
What I would like to do is replace the random.random function with a .txt file of values that I can set myself.
This is what I have come up with so far
def selectedArray(intLength,intWidth):
arr = []
for j in range(intWidth):
arri = []
for i in range(intLength):
selected = open('C:\Users\IAmADog\Documents\Thesis\Scripts\ArrayValues2.txt','r')
lines = selected.read().split(',')
arri.append(lines)
arr.append(arri)
return arr
But, when this is run it gives me an error saying "Message: unsupported operand type(s) for +: 'int' and 'list'"
The .txt file is set up like this [.1,.1,.9,.9,.... etc]
Any suggestion on why this is happening? And the full code can be found here. https://stackoverflow.com/questions/22138217/assistance-with-python-gol-script