So I am working on adding probability to crate meshes that are either alive or dead. Using code from Game of Life I would like to establish rule sets that change the likelihood of a mesh coming back to life or dying.
Below is a piece of code where I would like to add an 80% chance to the ruleset but can’t manage to right the conditional.
def applyGOL(self):
#create temporary dictionary to save new values in
newValues = {}
#loop through x and y values
for i in range(self.intX):
for j in range(self.intY):
#call function to find the sum of the neighbors
sum = self.sumNeighbors(i, j)
#run conditionals to change value
#INCLUDING PROBABILITY TO THE CODE
#if a cell is alive(1)
if self.valMTX[(i,j)] == 1:
#if the cell has less than 2 neighbors it has an 80% chance it dies(0)
if sum < 2:
newValues[(i,j)] = 0
#if the cell has more than 3 neighbors it dies(0)
elif sum > 3:
newValues[(i,j)] = 0
#otherwise the cell stays alive(1)
else:
newValues[(i,j)] = 1
#if the cell is dead(0)
else:
#it will come to life(1) if it has exactly 3 live neighbors
if sum == 3:
newValues[(i,j)] = 1